Skip to content

Commit 14f3740

Browse files
author
Teppo Järvelin
committed
Cellular: fixed cellular greentea tests after major refactoring.
1 parent 1b3db96 commit 14f3740

File tree

14 files changed

+139
-358
lines changed

14 files changed

+139
-358
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(unittest-test-sources
4141
stubs/Semaphore_stub.cpp
4242
stubs/UARTSerial_stub.cpp
4343
stubs/SerialBase_stub.cpp
44+
stubs/CellularStateMachine_stub.cpp
4445
)
4546

4647
# defines

features/cellular/TESTS/api/cellular_device/main.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@
3939

4040
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
4141
static CellularDevice *device;
42-
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
4342

4443
static void create_device()
4544
{
46-
device = new CELLULAR_DEVICE(queue);
45+
device = new CELLULAR_DEVICE(&cellular_serial);
4746
TEST_ASSERT(device != NULL);
4847
}
4948

@@ -52,32 +51,26 @@ static void open_close_interfaces()
5251
CellularNetwork *nw = device->open_network(&cellular_serial);
5352
TEST_ASSERT(nw != NULL);
5453
device->close_network();
55-
nw = device->open_network(NULL);
56-
TEST_ASSERT(nw == NULL);
5754

5855
CellularSIM *sim = device->open_sim(&cellular_serial);
5956
TEST_ASSERT(sim != NULL);
6057
device->close_sim();
61-
sim = device->open_sim(NULL);
62-
TEST_ASSERT(sim == NULL);
6358

6459
CellularInformation *info = device->open_information(&cellular_serial);
6560
TEST_ASSERT(info != NULL);
6661
device->close_information();
67-
info = device->open_information(NULL);
68-
TEST_ASSERT(info == NULL);
6962

7063
CellularPower *power = device->open_power(&cellular_serial);
7164
TEST_ASSERT(power != NULL);
7265
device->close_power();
73-
power = device->open_power(NULL);
74-
TEST_ASSERT(power == NULL);
7566

7667
CellularSMS *sms = device->open_sms(&cellular_serial);
7768
TEST_ASSERT(sms != NULL);
7869
device->close_sms();
79-
sms = device->open_sms(NULL);
80-
TEST_ASSERT(sms == NULL);
70+
71+
CellularContext *ctx = device->create_context();
72+
TEST_ASSERT(ctx != NULL);
73+
device->delete_context(ctx);
8174
}
8275

8376
static void other_methods()
@@ -86,8 +79,6 @@ static void other_methods()
8679
device->set_timeout(5000);
8780
device->modem_debug_on(true);
8881
device->modem_debug_on(false);
89-
NetworkStack *stack = device->get_stack();
90-
TEST_ASSERT(stack == NULL);
9182

9283
CellularNetwork *nw = device->open_network(&cellular_serial);
9384
TEST_ASSERT(nw != NULL);
@@ -96,8 +87,6 @@ static void other_methods()
9687
device->set_timeout(5000);
9788
device->modem_debug_on(true);
9889
device->modem_debug_on(false);
99-
stack = device->get_stack();
100-
TEST_ASSERT(stack != NULL);
10190
}
10291

10392
static void delete_device()

features/cellular/TESTS/api/cellular_information/main.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,28 @@
3939

4040

4141
#include "AT_CellularInformation.h"
42-
#include "CellularConnectionFSM.h"
42+
#include "CellularContext.h"
4343
#include "CellularDevice.h"
4444
#include "../../cellular_tests_common.h"
4545

46-
#define SIM_TIMEOUT (180*1000)
47-
48-
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
49-
static EventQueue queue(2 * EVENTS_EVENT_SIZE);
50-
static CellularConnectionFSM cellular;
51-
static CellularConnectionFSM::CellularState cellular_target_state;
52-
static rtos::Semaphore fsm_semaphore(0);
53-
54-
static bool fsm_callback(int state, int next_state)
55-
{
56-
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
57-
TEST_ASSERT(fsm_semaphore.release() == osOK);
58-
return false;
59-
}
60-
return true;
61-
}
46+
static CellularContext *ctx;
6247

6348
static void init_to_sim_state()
6449
{
65-
cellular.set_serial(&cellular_serial);
66-
TEST_ASSERT(cellular.init() == NSAPI_ERROR_OK);
67-
#if defined (MDMRTS) && defined (MDMCTS)
68-
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
50+
ctx = CellularContext::get_default_instance();
51+
TEST_ASSERT(ctx != NULL);
52+
ctx->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
53+
#ifdef MBED_CONF_APP_APN
54+
ctx->set_credentials(MBED_CONF_APP_APN);
6955
#endif
70-
cellular.set_callback(&fsm_callback);
71-
TEST_ASSERT(cellular.start_dispatch() == NSAPI_ERROR_OK);
72-
cellular_target_state = CellularConnectionFSM::STATE_SIM_PIN;
73-
TEST_ASSERT(cellular.continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
74-
TEST_ASSERT(fsm_semaphore.wait(SIM_TIMEOUT) == 1);
56+
TEST_ASSERT(ctx->set_sim_ready() == NSAPI_ERROR_OK);
7557
}
7658

7759
static void test_information_interface()
7860
{
79-
CellularInformation *info = cellular.get_device()->open_information(&cellular_serial);
61+
CellularDevice *dev = CellularDevice::get_default_instance();
62+
63+
CellularInformation *info = dev->open_information();
8064
const int kbuf_size = 100;
8165
char *buf = new char[kbuf_size];
8266

@@ -96,7 +80,7 @@ static void test_information_interface()
9680
err = info->get_serial_number(buf, kbuf_size, CellularInformation::SVN);
9781
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
9882

99-
cellular.get_device()->close_information();
83+
dev->close_information();
10084

10185
delete [] buf;
10286
}

features/cellular/TESTS/api/cellular_network/main.cpp

Lines changed: 21 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -31,72 +31,41 @@
3131
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
3232
#endif
3333

34+
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
35+
#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
36+
#endif
37+
3438
#include "greentea-client/test_env.h"
3539
#include "unity.h"
3640
#include "utest.h"
3741

3842
#include "mbed.h"
3943

4044
#include "AT_CellularNetwork.h"
41-
#include "CellularConnectionFSM.h"
45+
#include "CellularContext.h"
4246
#include "CellularDevice.h"
4347
#include "../../cellular_tests_common.h"
4448
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
4549

4650
#define NETWORK_TIMEOUT (180*1000)
4751

48-
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
49-
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
50-
static rtos::Semaphore network_semaphore(0);
51-
static CellularConnectionFSM cellular;
52-
static CellularConnectionFSM::CellularState cellular_target_state;
53-
static CELLULAR_DEVICE *device;
52+
static CellularContext *ctx;
53+
static CellularDevice *device;
5454
static CellularNetwork *nw;
5555

56-
57-
static bool fsm_callback(int state, int next_state)
58-
{
59-
if (next_state == cellular_target_state) {
60-
TEST_ASSERT(network_semaphore.release() == osOK);
61-
return false;
62-
}
63-
return true;
64-
}
65-
66-
// test methods that are already run in state machine (CellularConnectionFSM) but as it might change
67-
// we wan't to run these 'manually' also
68-
static void test_network_interface_fsm()
69-
{
70-
#if defined (MDMRTS) && defined (MDMCTS)
71-
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
72-
#endif
73-
device = new CELLULAR_DEVICE(queue);
74-
TEST_ASSERT(device != NULL);
75-
76-
CellularNetwork *nw = device->open_network(&cellular_serial);
77-
TEST_ASSERT(nw != NULL);
78-
TEST_ASSERT(nw->init() == NSAPI_ERROR_OK);
79-
80-
delete device;
81-
device = NULL;
82-
}
83-
8456
static void init_network_interface()
8557
{
86-
cellular.set_serial(&cellular_serial);
87-
TEST_ASSERT(cellular.init() == NSAPI_ERROR_OK);
88-
cellular.set_callback(&fsm_callback);
89-
TEST_ASSERT(cellular.start_dispatch() == NSAPI_ERROR_OK);
90-
cellular.set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
58+
ctx = CellularContext::get_default_instance();
59+
TEST_ASSERT(ctx != NULL);
60+
ctx->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
9161
#ifdef MBED_CONF_APP_APN
92-
CellularNetwork *network = cellular.get_network();
93-
TEST_ASSERT(network->set_credentials(MBED_CONF_APP_APN) == NSAPI_ERROR_OK);
62+
ctx->set_credentials(MBED_CONF_APP_APN);
9463
#endif
95-
cellular_target_state = CellularConnectionFSM::STATE_REGISTERING_NETWORK;
96-
TEST_ASSERT(cellular.continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
97-
TEST_ASSERT(network_semaphore.wait(NETWORK_TIMEOUT) == 1);
98-
}
64+
TEST_ASSERT(ctx->register_to_network() == NSAPI_ERROR_OK);
9965

66+
device = CellularDevice::get_default_instance();
67+
TEST_ASSERT(device != NULL);
68+
}
10069

10170
static bool get_network_registration(CellularNetwork::RegistrationType type,
10271
CellularNetwork::RegistrationStatus &status, bool &is_registered)
@@ -149,8 +118,8 @@ static void nw_callback(nsapi_event_t ev, intptr_t intptr)
149118

150119
static void test_network_registration()
151120
{
152-
cellular.get_device()->set_timeout(10 * 1000);
153-
nw = cellular.get_network();
121+
device->set_timeout(10 * 1000);
122+
nw = device->open_network();
154123
TEST_ASSERT(nw != NULL);
155124

156125
nw->attach(&nw_callback);
@@ -194,97 +163,22 @@ static void test_attach()
194163
TEST_ASSERT(status == CellularNetwork::Attached);
195164
}
196165

197-
static void test_activate_context()
198-
{
199-
TEST_ASSERT(nw->activate_context() == NSAPI_ERROR_OK);
200-
}
201-
202-
static void test_connect()
203-
{
204-
TEST_ASSERT(nw->connect() == NSAPI_ERROR_OK);
205-
char count = 0;
206-
while ((nw->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) && (count++ < 60)) {
207-
wait(1);
208-
}
209-
nsapi_connection_status_t st = nw->get_connection_status();
210-
TEST_ASSERT(st == NSAPI_STATUS_GLOBAL_UP);
211-
}
212-
213-
static void test_credentials()
214-
{
215-
nsapi_error_t err = nw->set_credentials(NULL, "username", "pass");
216-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
217-
err = nw->set_credentials("internet", "user", NULL);
218-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
219-
err = nw->set_credentials("internet", CellularNetwork::NOAUTH, "user", "pass");
220-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
221-
TEST_ASSERT(nw->set_credentials("internet", NULL, "pass") == NSAPI_ERROR_OK);
222-
}
223-
224166
static void test_other()
225167
{
226168
const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
227169
TEST_ASSERT(nw->get_3gpp_error() == 0);
228170

229-
CellularNetwork::RateControlExceptionReports reports;
230-
CellularNetwork::RateControlUplinkTimeUnit timeUnit;
231-
int uplinkRate;
232-
// can't test values as they are optional
233-
nsapi_error_t err = nw->get_rate_control(reports, timeUnit, uplinkRate);
234-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
235-
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "TELIT_HE910") != 0 && strcmp(devi, "SARA4_PPP") != 0) { // QUECTEL_BG96 does not give any specific reason for device error
236-
if (err == NSAPI_ERROR_DEVICE_ERROR) {
237-
TEST_ASSERT(((AT_CellularNetwork *)nw)->get_device_error().errCode == 100 && // 100 == unknown command for modem
238-
((AT_CellularNetwork *)nw)->get_device_error().errType == 3); // 3 == CME error from the modem
239-
}
240-
}
241-
242-
uplinkRate = -1;
243-
err = nw->get_apn_backoff_timer(uplinkRate);
244-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR || err == NSAPI_ERROR_PARAMETER);
245-
if (err == NSAPI_ERROR_DEVICE_ERROR) {
246-
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "TELIT_HE910") != 0 && strcmp(devi, "SARA4_PPP") != 0) { // QUECTEL_BG96 does not give any specific reason for device error
247-
TEST_ASSERT(((AT_CellularNetwork *)nw)->get_device_error().errCode == 100 && // 100 == unknown command for modem
248-
((AT_CellularNetwork *)nw)->get_device_error().errType == 3); // 3 == CME error from the modem
249-
}
250-
} else if (err == NSAPI_ERROR_PARAMETER) {
251-
TEST_ASSERT(uplinkRate == -1);
252-
} else {
253-
TEST_ASSERT(uplinkRate >= 0);
254-
}
255-
256-
err = nw->set_access_technology(CellularNetwork::RAT_GSM);
171+
nsapi_error_t err = nw->set_access_technology(CellularNetwork::RAT_GSM);
257172
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
258173

259174
// scanning of operators requires some delay before operation is allowed(seen with WISE_1570)
260175
wait(5);
261176
// scanning of operators might take a long time
262-
cellular.get_device()->set_timeout(240 * 1000);
177+
device->set_timeout(240 * 1000);
263178
CellularNetwork::operList_t operators;
179+
int uplinkRate = -1;
264180
TEST_ASSERT(nw->scan_plmn(operators, uplinkRate) == NSAPI_ERROR_OK);
265-
cellular.get_device()->set_timeout(10 * 1000);
266-
267-
268-
// all current targets support IPV4
269-
nsapi_ip_stack_t stack_type = IPV4_STACK;
270-
TEST_ASSERT(nw->set_stack_type(stack_type) == NSAPI_ERROR_OK);
271-
TEST_ASSERT(nw->get_stack_type() == stack_type);
272-
273-
CellularNetwork::pdpContextList_t params_list;
274-
err = nw->get_pdpcontext_params(params_list);
275-
276-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
277-
if (err == NSAPI_ERROR_DEVICE_ERROR) {
278-
if (strcmp(devi, "TELIT_HE910") != 0) { // TELIT_HE910 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
279-
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
280-
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
281-
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
282-
}
283-
} else {
284-
// should have some values, only not optional are apn and bearer id
285-
CellularNetwork::pdpcontext_params_t *params = params_list.get_head();
286-
TEST_ASSERT(params->bearer_id >= 0)
287-
}
181+
device->set_timeout(10 * 1000);
288182

289183
int rxlev = -1, ber = -1, rscp = -1, ecno = -1, rsrq = -1, rsrp = -1;
290184
err = nw->get_extended_signal_quality(rxlev, ber, rscp, ecno, rsrq, rsrp);
@@ -328,8 +222,6 @@ static void test_other()
328222
nsapi_connection_status_t st = nw->get_connection_status();
329223
TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED);
330224

331-
TEST_ASSERT(nw->set_blocking(true) == NSAPI_ERROR_OK);
332-
333225
#ifndef TARGET_UBLOX_C027 // AT command is supported, but excluded as it runs out of memory easily (there can be very many operator names)
334226
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "SARA4_PPP") != 0) {
335227
// QUECTEL_BG96 timeouts with this one, tested with 3 minute timeout
@@ -378,15 +270,6 @@ static void test_other()
378270
}
379271
}
380272

381-
static void test_disconnect()
382-
{
383-
nsapi_connection_status_t st = nw->get_connection_status();
384-
TEST_ASSERT(st == NSAPI_STATUS_GLOBAL_UP);
385-
TEST_ASSERT(nw->disconnect() == NSAPI_ERROR_OK);
386-
// wait to process URC's, received after disconnect
387-
rtos::ThisThread::sleep_for(500);
388-
}
389-
390273
static void test_detach()
391274
{
392275
// in PPP mode there is NO CARRIER waiting so flush it out
@@ -412,17 +295,11 @@ static utest::v1::status_t greentea_failure_handler(const Case *const source, co
412295
}
413296

414297
static Case cases[] = {
415-
Case("CellularNetwork state machine methods", test_network_interface_fsm, greentea_failure_handler),
416298
Case("CellularNetwork init", init_network_interface, greentea_failure_handler),
417299
Case("CellularNetwork test registering", test_network_registration, greentea_failure_handler),
418300
Case("CellularNetwork test attach", test_attach, greentea_failure_handler),
419-
Case("CellularNetwork test activate pdp context", test_activate_context, greentea_failure_handler),
420301
Case("CellularNetwork test other functions", test_other, greentea_failure_handler),
421-
Case("CellularNetwork test connect", test_connect, greentea_failure_handler),
422-
Case("CellularNetwork test credentials", test_credentials, greentea_failure_handler),
423-
Case("CellularNetwork test disconnect", test_disconnect, greentea_failure_handler),
424302
Case("CellularNetwork test detach", test_detach, greentea_failure_handler)
425-
426303
};
427304

428305
static utest::v1::status_t test_setup(const size_t number_of_cases)

0 commit comments

Comments
 (0)