Skip to content

Commit 4d07bcb

Browse files
authored
Merge pull request #8579 from jarvte/cellular_context
Major refactoring: changing Network inheritance from CellularNetwork to new class CellularContext
2 parents 82f195c + 88213d3 commit 4d07bcb

File tree

97 files changed

+4179
-3658
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4179
-3658
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ set(unittest-includes-base
117117
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs"
118118
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/API"
119119
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
120+
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/device"
120121
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
121122
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
122123
"${PROJECT_SOURCE_DIR}/../features/lorawan"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "gtest/gtest.h"
18+
#include <string.h>
19+
#include "AT_CellularContext.h"
20+
#include "EventQueue.h"
21+
#include "ATHandler.h"
22+
#include "AT_CellularDevice.h"
23+
#include "FileHandle_stub.h"
24+
#include "CellularLog.h"
25+
#include "ATHandler_stub.h"
26+
#include "AT_CellularStack.h"
27+
28+
using namespace mbed;
29+
using namespace events;
30+
31+
// AStyle ignored as the definition is not clear due to preprocessor usage
32+
// *INDENT-OFF*
33+
class TestAT_CellularContext : public testing::Test {
34+
protected:
35+
36+
void SetUp()
37+
{
38+
ATHandler_stub::int_count = kRead_int_table_size;
39+
ATHandler_stub::read_string_index = kRead_string_table_size;
40+
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
41+
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
42+
ATHandler_stub::int_value = -1;
43+
}
44+
45+
void TearDown()
46+
{
47+
}
48+
};
49+
// *INDENT-ON*
50+
class my_stack : public AT_CellularStack {
51+
public:
52+
my_stack(ATHandler &atHandler) : AT_CellularStack(atHandler, 1, IPV4_STACK) {}
53+
virtual int get_max_socket_count()
54+
{
55+
return 1;
56+
}
57+
virtual int get_max_packet_size()
58+
{
59+
return 200;
60+
}
61+
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
62+
{
63+
return true;
64+
}
65+
virtual nsapi_error_t socket_close_impl(int sock_id)
66+
{
67+
return NSAPI_ERROR_OK;
68+
}
69+
virtual nsapi_error_t create_socket_impl(CellularSocket *socket)
70+
{
71+
return NSAPI_ERROR_OK;
72+
}
73+
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
74+
const void *data, nsapi_size_t size)
75+
{
76+
return 100;
77+
}
78+
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
79+
void *buffer, nsapi_size_t size)
80+
{
81+
return 100;
82+
}
83+
};
84+
85+
class my_AT_CTX : public AT_CellularContext {
86+
public:
87+
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
88+
AT_CellularContext(at, device, apn) {}
89+
virtual ~my_AT_CTX() {}
90+
};
91+
92+
class my_AT_CTXIPV6 : public AT_CellularContext {
93+
public:
94+
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
95+
AT_CellularContext(at, device, apn) {}
96+
virtual ~my_AT_CTXIPV6() {}
97+
};
98+
99+
static int network_cb_count;
100+
static void network_cb(nsapi_event_t ev, intptr_t intptr)
101+
{
102+
network_cb_count++;
103+
}
104+
105+
TEST_F(TestAT_CellularContext, Create)
106+
{
107+
EventQueue que;
108+
FileHandle_stub fh1;
109+
ATHandler at(&fh1, que, 0, ",");
110+
111+
AT_CellularContext *ctx = new AT_CellularContext(at, NULL);
112+
EXPECT_TRUE(ctx != NULL);
113+
delete ctx;
114+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
####################
3+
# UNIT TESTS
4+
####################
5+
6+
# Add test specific include paths
7+
set(unittest-includes ${unittest-includes}
8+
features/cellular/framework/common/util
9+
../features/cellular/framework/common
10+
../features/cellular/framework/AT
11+
../features/cellular/framework/device
12+
)
13+
14+
# Source files
15+
set(unittest-sources
16+
../features/cellular/framework/AT/AT_CellularContext.cpp
17+
)
18+
19+
# Test files
20+
set(unittest-test-sources
21+
features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp
22+
stubs/ATHandler_stub.cpp
23+
stubs/AT_CellularBase_stub.cpp
24+
stubs/EventQueue_stub.cpp
25+
stubs/FileHandle_stub.cpp
26+
stubs/NetworkInterface_stub.cpp
27+
stubs/NetworkStack_stub.cpp
28+
stubs/us_ticker_stub.cpp
29+
stubs/mbed_assert_stub.c
30+
stubs/CellularDevice_stub.cpp
31+
stubs/CellularStateMachine_stub.cpp
32+
stubs/Semaphore_stub.cpp
33+
stubs/CellularUtil_stub.cpp
34+
stubs/equeue_stub.c
35+
)

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,21 @@ class TestAT_CellularDevice : public testing::Test {
3737

3838
TEST_F(TestAT_CellularDevice, Create)
3939
{
40-
EventQueue que;
41-
AT_CellularDevice dev(que);
40+
FileHandle_stub fh1;
41+
AT_CellularDevice dev(&fh1);
4242

43-
CellularDevice *dev2 = new AT_CellularDevice(que);
43+
CellularDevice *dev2 = new AT_CellularDevice(&fh1);
4444

4545
EXPECT_TRUE(dev2 != NULL);
4646
delete dev2;
4747
}
4848

4949
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
5050
{
51-
EventQueue que;
52-
AT_CellularDevice dev(que);
5351
FileHandle_stub fh1;
5452
FileHandle_stub fh2;
5553
FileHandle_stub fh3;
54+
AT_CellularDevice dev(&fh1);
5655

5756
EXPECT_TRUE(dev.open_network(&fh1));
5857
EXPECT_TRUE(dev.open_sms(&fh2));
@@ -66,59 +65,73 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
6665

6766
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
6867
{
69-
EventQueue que;
70-
AT_CellularDevice dev(que);
7168
FileHandle_stub fh1;
69+
AT_CellularDevice dev(&fh1);
7270

73-
EXPECT_TRUE(!dev.open_network(NULL));
74-
EXPECT_TRUE(dev.open_network(&fh1));
71+
CellularNetwork *nw = dev.open_network(NULL);
72+
CellularNetwork *nw1 = dev.open_network(&fh1);
73+
74+
EXPECT_TRUE(nw);
75+
EXPECT_TRUE(nw1);
76+
EXPECT_TRUE(nw1 == nw);
7577
}
7678

7779
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
7880
{
79-
EventQueue que;
80-
AT_CellularDevice dev(que);
8181
FileHandle_stub fh1;
82+
AT_CellularDevice dev(&fh1);
8283

83-
EXPECT_TRUE(!dev.open_sms(NULL));
84-
EXPECT_TRUE(dev.open_sms(&fh1));
84+
CellularSMS *sms = dev.open_sms(NULL);
85+
CellularSMS *sms1 = dev.open_sms(&fh1);
86+
87+
EXPECT_TRUE(sms);
88+
EXPECT_TRUE(sms1);
89+
EXPECT_TRUE(sms1 == sms);
8590
}
8691

8792
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
8893
{
89-
EventQueue que;
90-
AT_CellularDevice dev(que);
9194
FileHandle_stub fh1;
95+
AT_CellularDevice dev(&fh1);
9296

93-
EXPECT_TRUE(!dev.open_power(NULL));
94-
EXPECT_TRUE(dev.open_power(&fh1));
97+
CellularPower *pwr = dev.open_power(NULL);
98+
CellularPower *pwr1 = dev.open_power(&fh1);
99+
100+
EXPECT_TRUE(pwr);
101+
EXPECT_TRUE(pwr1);
102+
EXPECT_TRUE(pwr1 == pwr);
95103
}
96104

97105
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
98106
{
99-
EventQueue que;
100-
AT_CellularDevice dev(que);
101107
FileHandle_stub fh1;
108+
AT_CellularDevice dev(&fh1);
102109

103-
EXPECT_TRUE(! dev.open_sim(NULL));
104-
EXPECT_TRUE(dev.open_sim(&fh1));
110+
CellularSIM *sim = dev.open_sim(NULL);
111+
CellularSIM *sim1 = dev.open_sim(&fh1);
112+
113+
EXPECT_TRUE(sim);
114+
EXPECT_TRUE(sim1);
115+
EXPECT_TRUE(sim1 == sim);
105116
}
106117

107118
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
108119
{
109-
EventQueue que;
110-
AT_CellularDevice dev(que);
111120
FileHandle_stub fh1;
121+
AT_CellularDevice dev(&fh1);
112122

113-
EXPECT_TRUE(!dev.open_information(NULL));
114-
EXPECT_TRUE(dev.open_information(&fh1));
123+
CellularInformation *info = dev.open_information(NULL);
124+
CellularInformation *info1 = dev.open_information(&fh1);
125+
126+
EXPECT_TRUE(info);
127+
EXPECT_TRUE(info1);
128+
EXPECT_TRUE(info1 == info);
115129
}
116130

117131
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
118132
{
119-
EventQueue que;
120-
AT_CellularDevice dev(que);
121133
FileHandle_stub fh1;
134+
AT_CellularDevice dev(&fh1);
122135
ATHandler_stub::ref_count = 0;
123136

124137
EXPECT_TRUE(dev.open_network(&fh1));
@@ -131,9 +144,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
131144

132145
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
133146
{
134-
EventQueue que;
135-
AT_CellularDevice dev(que);
136147
FileHandle_stub fh1;
148+
AT_CellularDevice dev(&fh1);
137149
ATHandler_stub::ref_count = 0;
138150

139151
EXPECT_TRUE(dev.open_sms(&fh1));
@@ -146,9 +158,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
146158

147159
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
148160
{
149-
EventQueue que;
150-
AT_CellularDevice dev(que);
151161
FileHandle_stub fh1;
162+
AT_CellularDevice dev(&fh1);
152163
ATHandler_stub::ref_count = 0;
153164

154165
EXPECT_TRUE(dev.open_power(&fh1));
@@ -161,9 +172,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
161172

162173
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
163174
{
164-
EventQueue que;
165-
AT_CellularDevice dev(que);
166175
FileHandle_stub fh1;
176+
AT_CellularDevice dev(&fh1);
167177
ATHandler_stub::ref_count = 0;
168178
int ana = 0;
169179

@@ -182,9 +192,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
182192

183193
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
184194
{
185-
EventQueue que;
186-
AT_CellularDevice dev(que);
187195
FileHandle_stub fh1;
196+
AT_CellularDevice dev(&fh1);
188197
ATHandler_stub::int_value = 0;
189198

190199
EXPECT_TRUE(dev.open_information(&fh1));
@@ -193,6 +202,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
193202
AT_CellularBase_stub::handler_value = NULL;
194203
dev.close_information();
195204

205+
EventQueue que;
196206
ATHandler_stub::fh_value = &fh1;
197207
ATHandler at(&fh1, que, 0, ",");
198208
AT_CellularBase_stub::handler_value = &at;
@@ -208,9 +218,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
208218

209219
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
210220
{
211-
EventQueue que;
212-
AT_CellularDevice dev(que);
213221
FileHandle_stub fh1;
222+
AT_CellularDevice dev(&fh1);
214223
ATHandler_stub::timeout = 0;
215224
ATHandler_stub::default_timeout = false;
216225

@@ -231,9 +240,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
231240

232241
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
233242
{
234-
EventQueue que;
235-
AT_CellularDevice dev(que);
236243
FileHandle_stub fh1;
244+
AT_CellularDevice dev(&fh1);
237245
ATHandler_stub::debug_on = false;
238246

239247
// no interfaces open so debug toggling should not affect
@@ -249,31 +257,16 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
249257
dev.close_sim();
250258
}
251259

252-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_stack)
253-
{
254-
EventQueue que;
255-
AT_CellularDevice dev(que);
256-
FileHandle_stub fh1;
257-
258-
NetworkStack *stack = dev.get_stack();
259-
EXPECT_TRUE(stack == NULL);
260-
261-
EXPECT_TRUE(dev.open_network(&fh1));
262-
263-
stack = dev.get_stack();
264-
EXPECT_TRUE(stack == NULL); // Not in PPP so also null but this is got from the network class
265-
}
266-
267260
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
268261
{
269-
EventQueue que;
270-
AT_CellularDevice dev(que);
262+
FileHandle_stub fh1;
263+
AT_CellularDevice dev(&fh1);
271264
EXPECT_TRUE(0 == dev.get_send_delay());
272265
}
273266

274267
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
275268
{
276-
EventQueue que;
277-
AT_CellularDevice dev(que);
278-
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL));
269+
FileHandle_stub fh1;
270+
AT_CellularDevice dev(&fh1);
271+
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module());
279272
}

0 commit comments

Comments
 (0)