Skip to content

Commit 87851f3

Browse files
authored
Merge pull request #9472 from AriParkkila/cellular-refactor-greentea
Cellular: Fix cellular specific Greentea tests
2 parents 007caa0 + 7578d5b commit 87851f3

File tree

26 files changed

+195
-153
lines changed

26 files changed

+195
-153
lines changed

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
2020
#endif
2121

22-
#include "CellularUtil.h" // for CELLULAR_ helper macros
23-
#include "CellularTargets.h"
24-
25-
#ifndef CELLULAR_DEVICE
26-
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
27-
#endif
28-
2922
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
3023
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
3124
#endif
@@ -38,11 +31,9 @@
3831

3932
#include "CellularLog.h"
4033
#include "CellularDevice.h"
41-
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
4234
#include "Semaphore.h"
4335
#include "../../cellular_tests_common.h"
4436

45-
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
4637
static CellularDevice *device;
4738
static rtos::Semaphore semaphore;
4839

@@ -60,21 +51,21 @@ static CurrentOp op;
6051

6152
static void create_device()
6253
{
63-
device = new CELLULAR_DEVICE(&cellular_serial);
54+
device = CellularDevice::get_default_instance();
6455
TEST_ASSERT(device != NULL);
6556
}
6657

6758
static void open_close_interfaces()
6859
{
69-
CellularNetwork *nw = device->open_network(&cellular_serial);
60+
CellularNetwork *nw = device->open_network();
7061
TEST_ASSERT(nw != NULL);
7162
device->close_network();
7263

73-
CellularInformation *info = device->open_information(&cellular_serial);
64+
CellularInformation *info = device->open_information();
7465
TEST_ASSERT(info != NULL);
7566
device->close_information();
7667

77-
CellularSMS *sms = device->open_sms(&cellular_serial);
68+
CellularSMS *sms = device->open_sms();
7869
TEST_ASSERT(sms != NULL);
7970
device->close_sms();
8071

@@ -91,7 +82,7 @@ static void other_methods()
9182
device->modem_debug_on(true);
9283
device->modem_debug_on(false);
9384

94-
CellularNetwork *nw = device->open_network(&cellular_serial);
85+
CellularNetwork *nw = device->open_network();
9586
TEST_ASSERT(nw != NULL);
9687

9788
// then test with open interface which is called
@@ -100,21 +91,17 @@ static void other_methods()
10091
device->modem_debug_on(false);
10192

10293
TEST_ASSERT(device->get_queue() != NULL);
103-
TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK);
94+
TEST_ASSERT(device->hard_power_on() == NSAPI_ERROR_OK);
95+
TEST_ASSERT(device->soft_power_on() == NSAPI_ERROR_OK);
96+
wait(5);
97+
TEST_ASSERT_EQUAL_INT(device->init(), NSAPI_ERROR_OK);
10498
}
10599

106-
static void shutdown_reset()
100+
static void shutdown()
107101
{
108-
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
109102
TEST_ASSERT(device->shutdown() == NSAPI_ERROR_OK);
110-
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
111-
}
112-
113-
static void delete_device()
114-
{
115-
// delete will close all opened interfaces
116-
delete device;
117-
device = NULL;
103+
TEST_ASSERT(device->soft_power_off() == NSAPI_ERROR_OK);
104+
TEST_ASSERT(device->hard_power_off() == NSAPI_ERROR_OK);
118105
}
119106

120107
static void callback_func(nsapi_event_t ev, intptr_t ptr)
@@ -155,7 +142,9 @@ static void init_to_device_ready_state()
155142
device->attach(&callback_func);
156143

157144
op = OP_DEVICE_READY;
158-
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init_module());
145+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->hard_power_on());
146+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->soft_power_on());
147+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init());
159148
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_device_ready());
160149

161150
int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY);
@@ -204,13 +193,11 @@ static Case cases[] = {
204193
Case("CellularDevice create device", create_device, greentea_failure_handler),
205194
Case("CellularDevice Open and close interfaces", open_close_interfaces, greentea_failure_handler),
206195
Case("CellularDevice other methods", other_methods, greentea_failure_handler),
207-
Case("CellularDevice delete device", delete_device, greentea_failure_handler),
208196
Case("CellularDevice init to device ready", init_to_device_ready_state, greentea_failure_handler),
209197
Case("CellularDevice sim ready", continue_to_sim_ready_state, greentea_failure_handler),
210198
Case("CellularDevice register", continue_to_register_state, greentea_failure_handler),
211-
Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler)
212-
Case("CellularDevice shutdown/reset", shutdown_reset, greentea_failure_handler),
213-
Case("CellularDevice delete device", delete_device, greentea_failure_handler)
199+
Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler),
200+
Case("CellularDevice shutdown", shutdown, greentea_failure_handler),
214201
};
215202

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

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#include "CellularUtil.h" // for CELLULAR_ helper macros
2424
#include "CellularTargets.h"
2525

26-
#ifndef CELLULAR_DEVICE
27-
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28-
#endif
29-
3026
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
3127
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
3228
#endif

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,10 @@
2020
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
2121
#endif
2222

23-
#include "CellularUtil.h" // for CELLULAR_ helper macros
24-
#include "CellularTargets.h"
25-
26-
#ifndef CELLULAR_DEVICE
27-
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28-
#endif
29-
3023
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
3124
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
3225
#endif
3326

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-
3827
#include "greentea-client/test_env.h"
3928
#include "unity.h"
4029
#include "utest.h"
@@ -45,7 +34,6 @@
4534
#include "CellularContext.h"
4635
#include "CellularDevice.h"
4736
#include "../../cellular_tests_common.h"
48-
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
4937

5038
#define NETWORK_TIMEOUT (180*1000)
5139

@@ -165,7 +153,6 @@ static void test_attach()
165153

166154
static void test_other()
167155
{
168-
const char *devi = CELLULAR_STRINGIFY(CELLULAR_DEVICE);
169156
TEST_ASSERT(nw->get_3gpp_error() == 0);
170157

171158
nsapi_error_t err = nw->set_access_technology(CellularNetwork::RAT_GSM);
@@ -204,52 +191,14 @@ static void test_other()
204191
nsapi_connection_status_t st = nw->get_connection_status();
205192
TEST_ASSERT(st == NSAPI_STATUS_DISCONNECTED);
206193

207-
#ifndef TARGET_UBLOX_C027 // AT command is supported, but excluded as it runs out of memory easily (there can be very many operator names)
208-
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "SARA4_PPP") != 0) {
209-
// QUECTEL_BG96 timeouts with this one, tested with 3 minute timeout
210-
CellularNetwork::operator_names_list op_names;
211-
err = nw->get_operator_names(op_names);
212-
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
213-
if (err == NSAPI_ERROR_DEVICE_ERROR) {
214-
// if device error then we must check was that really device error or that modem/network does not support the commands
215-
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
216-
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 4) || // 4 == NOT SUPPORTED BY THE MODEM
217-
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
218-
} else {
219-
CellularNetwork::operator_names_t *opn = op_names.get_head();
220-
TEST_ASSERT(strlen(opn->numeric) > 0);
221-
TEST_ASSERT(strlen(opn->alpha) > 0);
222-
}
223-
}
224-
#endif
225-
226194
// TELIT_HE910 and QUECTEL_BG96 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
227195
CellularNetwork::CIoT_Supported_Opt supported_opt = CellularNetwork::CIOT_OPT_MAX;
228196
CellularNetwork::CIoT_Preferred_UE_Opt preferred_opt = CellularNetwork::PREFERRED_UE_OPT_MAX;
229197
err = nw->get_ciot_ue_optimization_config(supported_opt, preferred_opt);
230198
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
231-
if (err == NSAPI_ERROR_DEVICE_ERROR) {
232-
// if device error then we must check was that really device error or that modem/network does not support the commands
233-
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) {
234-
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
235-
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
236-
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
237-
}
238-
} else {
239-
TEST_ASSERT(supported_opt != CellularNetwork::CIOT_OPT_MAX);
240-
TEST_ASSERT(preferred_opt != CellularNetwork::PREFERRED_UE_OPT_MAX);
241-
}
242199

243200
err = nw->set_ciot_optimization_config(supported_opt, preferred_opt, NULL);
244201
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
245-
if (err == NSAPI_ERROR_DEVICE_ERROR) {
246-
// if device error then we must check was that really device error or that modem/network does not support the commands
247-
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) {
248-
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
249-
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
250-
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
251-
}
252-
}
253202
}
254203

255204
static void test_detach()

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
2121
#endif
2222

23-
#include "CellularUtil.h" // for CELLULAR_ helper macros
24-
#include "CellularTargets.h"
25-
26-
#ifndef CELLULAR_DEVICE
27-
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
28-
#endif
29-
3023
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
3124
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
3225
#endif
@@ -45,12 +38,10 @@
4538
#include "CellularContext.h"
4639
#include "CellularDevice.h"
4740
#include "../../cellular_tests_common.h"
48-
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
4941

5042
#define NETWORK_TIMEOUT (600*1000)
5143
#define SIM_BUSY 314
52-
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
53-
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
44+
5445
static CellularContext *ctx;
5546
static CellularDevice *device;
5647
static CellularSMS *sms;
@@ -59,10 +50,10 @@ static int service_address_type;
5950

6051
static void create_context()
6152
{
62-
device = new CELLULAR_DEVICE(&cellular_serial);
53+
device = CellularDevice::get_default_instance();
6354
TEST_ASSERT(device != NULL);
6455
device->set_timeout(9000);
65-
ctx = device->create_context();
56+
ctx = CellularContext::get_default_instance();
6657
TEST_ASSERT(ctx != NULL);
6758
ctx->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
6859
#ifdef MBED_CONF_APP_APN
@@ -75,12 +66,12 @@ static void store_service_center_address()
7566
// First we need to go SIM_PIN state to make sure that we can get service address and device ready to accept AT commands
7667
create_context();
7768
TEST_ASSERT(ctx->set_sim_ready() == NSAPI_ERROR_OK);
78-
wait(1);
79-
delete device; // will also delete context
8069

81-
wait(3); // some modems needs more time access sim
70+
wait(5); // some modems needs more time access sim
8271

83-
ATHandler *at_init = new ATHandler(&cellular_serial, queue, 30000, "\r");
72+
ATHandler *at_init = device->get_at_handler();
73+
at_init->lock();
74+
at_init->set_at_timeout(30 * 1000);
8475
at_init->cmd_start("AT+CSCA?");
8576
at_init->cmd_stop();
8677

@@ -90,10 +81,10 @@ static void store_service_center_address()
9081
at_init->read_string(service_center_address, sizeof(service_center_address));
9182
service_address_type = at_init->read_int();
9283
at_init->resp_stop();
93-
9484
TEST_ASSERT(at_init->get_last_error() == NSAPI_ERROR_OK);
9585

96-
delete at_init;
86+
at_init->unlock();
87+
device->release_at_handler(at_init);
9788
}
9889

9990
static void init()
@@ -103,7 +94,7 @@ static void init()
10394
create_context();
10495

10596
TEST_ASSERT(ctx->register_to_network() == NSAPI_ERROR_OK);
106-
sms = device->open_sms(&cellular_serial);
97+
sms = device->open_sms();
10798
TEST_ASSERT(sms != NULL);
10899
wait(3); // some modems needs more time access sim
109100
}

features/cellular/TESTS/socket/udp/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
2727
#endif
2828

29-
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
30-
#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
31-
#endif
32-
3329
#include "greentea-client/test_env.h"
3430
#include "unity.h"
3531
#include "utest.h"

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ bool AT_CellularContext::set_new_context(int cid)
429429
_pdp_type = pdp_type;
430430
_cid = cid;
431431
_new_context_set = true;
432-
tr_info("New PDP context %d, type %s", _cid, pdp_type);
432+
tr_info("New PDP context %d, type %d", _cid, pdp_type);
433433
}
434434

435435
return success;
@@ -871,7 +871,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
871871
cell_callback_data_t *data = (cell_callback_data_t *)ptr;
872872
cellular_connection_status_t st = (cellular_connection_status_t)ev;
873873
_cb_data.error = data->error;
874-
tr_debug("CellularContext: event %d, err %d, data %d", ev, data->error, data->status_data);
875874
#if USE_APN_LOOKUP
876875
if (st == CellularSIMStatusChanged && data->status_data == CellularDevice::SimStateReady &&
877876
_cb_data.error == NSAPI_ERROR_OK) {
@@ -903,7 +902,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
903902

904903
if (!_nw && st == CellularDeviceReady && data->error == NSAPI_ERROR_OK) {
905904
_nw = _device->open_network(_fh);
906-
tr_error("OPEN NETWORK");
907905
}
908906

909907
if (_cp_req && !_cp_in_use && (data->error == NSAPI_ERROR_OK) &&
@@ -948,7 +946,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
948946
}
949947
}
950948
} else {
951-
tr_debug("CellularContext: event %d, ptr %d", ev, ptr);
952949
#if NSAPI_PPP_AVAILABLE
953950
if (_is_blocking) {
954951
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref
4444

4545
CellularDevice::~CellularDevice()
4646
{
47+
tr_debug("CellularDevice destruct");
4748
}
4849

4950
void CellularDevice::stop()
@@ -115,6 +116,7 @@ nsapi_error_t CellularDevice::create_state_machine()
115116
_state_machine->set_cellular_callback(callback(this, &CellularDevice::cellular_callback));
116117
err = _state_machine->start_dispatch();
117118
if (err) {
119+
tr_error("Start state machine failed.");
118120
delete _state_machine;
119121
_state_machine = NULL;
120122
}

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event
7373

7474
CellularStateMachine::~CellularStateMachine()
7575
{
76+
tr_debug("CellularStateMachine destruct");
7677
stop();
7778
}
7879

@@ -523,6 +524,7 @@ nsapi_error_t CellularStateMachine::run_to_state(CellularStateMachine::CellularS
523524
// call pre_event via queue so that it's in same thread and it's safe to decisions
524525
int id = _queue.call_in(0, this, &CellularStateMachine::pre_event, tmp_state);
525526
if (!id) {
527+
report_failure("Failed to call queue.");
526528
stop();
527529
_mutex.unlock();
528530
return NSAPI_ERROR_NO_MEMORY;
@@ -655,6 +657,7 @@ nsapi_error_t CellularStateMachine::start_dispatch()
655657

656658
_queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue");
657659
if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
660+
report_failure("Failed to start thread.");
658661
stop();
659662
return NSAPI_ERROR_NO_MEMORY;
660663
}

0 commit comments

Comments
 (0)