Skip to content

Cellular: Fix cellular specific Greentea tests #9472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions features/cellular/TESTS/api/cellular_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
#endif

#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"

#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
#endif

#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif
Expand All @@ -38,11 +31,9 @@

#include "CellularLog.h"
#include "CellularDevice.h"
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
#include "Semaphore.h"
#include "../../cellular_tests_common.h"

static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
static CellularDevice *device;
static rtos::Semaphore semaphore;

Expand All @@ -60,21 +51,21 @@ static CurrentOp op;

static void create_device()
{
device = new CELLULAR_DEVICE(&cellular_serial);
device = CellularDevice::get_default_instance();
TEST_ASSERT(device != NULL);
}

static void open_close_interfaces()
{
CellularNetwork *nw = device->open_network(&cellular_serial);
CellularNetwork *nw = device->open_network();
TEST_ASSERT(nw != NULL);
device->close_network();

CellularInformation *info = device->open_information(&cellular_serial);
CellularInformation *info = device->open_information();
TEST_ASSERT(info != NULL);
device->close_information();

CellularSMS *sms = device->open_sms(&cellular_serial);
CellularSMS *sms = device->open_sms();
TEST_ASSERT(sms != NULL);
device->close_sms();

Expand All @@ -91,7 +82,7 @@ static void other_methods()
device->modem_debug_on(true);
device->modem_debug_on(false);

CellularNetwork *nw = device->open_network(&cellular_serial);
CellularNetwork *nw = device->open_network();
TEST_ASSERT(nw != NULL);

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

TEST_ASSERT(device->get_queue() != NULL);
TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK);
TEST_ASSERT(device->hard_power_on() == NSAPI_ERROR_OK);
TEST_ASSERT(device->soft_power_on() == NSAPI_ERROR_OK);
wait(5);
TEST_ASSERT_EQUAL_INT(device->init(), NSAPI_ERROR_OK);
}

static void shutdown_reset()
static void shutdown()
{
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
TEST_ASSERT(device->shutdown() == NSAPI_ERROR_OK);
TEST_ASSERT(device->set_device_ready() == NSAPI_ERROR_OK);
}

static void delete_device()
{
// delete will close all opened interfaces
delete device;
device = NULL;
TEST_ASSERT(device->soft_power_off() == NSAPI_ERROR_OK);
TEST_ASSERT(device->hard_power_off() == NSAPI_ERROR_OK);
}

static void callback_func(nsapi_event_t ev, intptr_t ptr)
Expand Down Expand Up @@ -155,7 +142,9 @@ static void init_to_device_ready_state()
device->attach(&callback_func);

op = OP_DEVICE_READY;
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init_module());
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->hard_power_on());
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->soft_power_on());
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init());
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_device_ready());

int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY);
Expand Down Expand Up @@ -204,13 +193,11 @@ static Case cases[] = {
Case("CellularDevice create device", create_device, greentea_failure_handler),
Case("CellularDevice Open and close interfaces", open_close_interfaces, greentea_failure_handler),
Case("CellularDevice other methods", other_methods, greentea_failure_handler),
Case("CellularDevice delete device", delete_device, greentea_failure_handler),
Case("CellularDevice init to device ready", init_to_device_ready_state, greentea_failure_handler),
Case("CellularDevice sim ready", continue_to_sim_ready_state, greentea_failure_handler),
Case("CellularDevice register", continue_to_register_state, greentea_failure_handler),
Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler)
Case("CellularDevice shutdown/reset", shutdown_reset, greentea_failure_handler),
Case("CellularDevice delete device", delete_device, greentea_failure_handler)
Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler),
Case("CellularDevice shutdown", shutdown, greentea_failure_handler),
};

static utest::v1::status_t test_setup(const size_t number_of_cases)
Expand Down
4 changes: 0 additions & 4 deletions features/cellular/TESTS/api/cellular_information/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"

#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
#endif

#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif
Expand Down
51 changes: 0 additions & 51 deletions features/cellular/TESTS/api/cellular_network/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,10 @@
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
#endif

#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"

#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
#endif

#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif

#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
#endif

#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
Expand All @@ -45,7 +34,6 @@
#include "CellularContext.h"
#include "CellularDevice.h"
#include "../../cellular_tests_common.h"
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)

#define NETWORK_TIMEOUT (180*1000)

Expand Down Expand Up @@ -165,7 +153,6 @@ static void test_attach()

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

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

#ifndef TARGET_UBLOX_C027 // AT command is supported, but excluded as it runs out of memory easily (there can be very many operator names)
if (strcmp(devi, "QUECTEL_BG96") != 0 && strcmp(devi, "SARA4_PPP") != 0) {
// QUECTEL_BG96 timeouts with this one, tested with 3 minute timeout
CellularNetwork::operator_names_list op_names;
err = nw->get_operator_names(op_names);
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
if (err == NSAPI_ERROR_DEVICE_ERROR) {
// if device error then we must check was that really device error or that modem/network does not support the commands
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 4) || // 4 == NOT SUPPORTED BY THE MODEM
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
} else {
CellularNetwork::operator_names_t *opn = op_names.get_head();
TEST_ASSERT(strlen(opn->numeric) > 0);
TEST_ASSERT(strlen(opn->alpha) > 0);
}
}
#endif

// 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
CellularNetwork::CIoT_Supported_Opt supported_opt = CellularNetwork::CIOT_OPT_MAX;
CellularNetwork::CIoT_Preferred_UE_Opt preferred_opt = CellularNetwork::PREFERRED_UE_OPT_MAX;
err = nw->get_ciot_ue_optimization_config(supported_opt, preferred_opt);
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
if (err == NSAPI_ERROR_DEVICE_ERROR) {
// if device error then we must check was that really device error or that modem/network does not support the commands
if (!(strcmp(devi, "TELIT_HE910") == 0 || strcmp(devi, "QUECTEL_BG96") == 0 || strcmp(devi, "SARA4_PPP") == 0)) {
TEST_ASSERT((((AT_CellularNetwork *)nw)->get_device_error().errType == 3) && // 3 == CME error from the modem
((((AT_CellularNetwork *)nw)->get_device_error().errCode == 100) || // 100 == unknown command for modem
(((AT_CellularNetwork *)nw)->get_device_error().errCode == 50))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
}
} else {
TEST_ASSERT(supported_opt != CellularNetwork::CIOT_OPT_MAX);
TEST_ASSERT(preferred_opt != CellularNetwork::PREFERRED_UE_OPT_MAX);
}

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

static void test_detach()
Expand Down
29 changes: 10 additions & 19 deletions features/cellular/TESTS/api/cellular_sms/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
#endif

#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"

#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
#endif

#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif
Expand All @@ -45,12 +38,10 @@
#include "CellularContext.h"
#include "CellularDevice.h"
#include "../../cellular_tests_common.h"
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)

#define NETWORK_TIMEOUT (600*1000)
#define SIM_BUSY 314
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
static EventQueue queue(8 * EVENTS_EVENT_SIZE);

static CellularContext *ctx;
static CellularDevice *device;
static CellularSMS *sms;
Expand All @@ -59,10 +50,10 @@ static int service_address_type;

static void create_context()
{
device = new CELLULAR_DEVICE(&cellular_serial);
device = CellularDevice::get_default_instance();
TEST_ASSERT(device != NULL);
device->set_timeout(9000);
ctx = device->create_context();
ctx = CellularContext::get_default_instance();
TEST_ASSERT(ctx != NULL);
ctx->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
#ifdef MBED_CONF_APP_APN
Expand All @@ -75,12 +66,12 @@ static void store_service_center_address()
// First we need to go SIM_PIN state to make sure that we can get service address and device ready to accept AT commands
create_context();
TEST_ASSERT(ctx->set_sim_ready() == NSAPI_ERROR_OK);
wait(1);
delete device; // will also delete context

wait(3); // some modems needs more time access sim
wait(5); // some modems needs more time access sim

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

Expand All @@ -90,10 +81,10 @@ static void store_service_center_address()
at_init->read_string(service_center_address, sizeof(service_center_address));
service_address_type = at_init->read_int();
at_init->resp_stop();

TEST_ASSERT(at_init->get_last_error() == NSAPI_ERROR_OK);

delete at_init;
at_init->unlock();
device->release_at_handler(at_init);
}

static void init()
Expand All @@ -103,7 +94,7 @@ static void init()
create_context();

TEST_ASSERT(ctx->register_to_network() == NSAPI_ERROR_OK);
sms = device->open_sms(&cellular_serial);
sms = device->open_sms();
TEST_ASSERT(sms != NULL);
wait(3); // some modems needs more time access sim
}
Expand Down
4 changes: 0 additions & 4 deletions features/cellular/TESTS/socket/udp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif

#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
#error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
#endif

#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
Expand Down
5 changes: 1 addition & 4 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ bool AT_CellularContext::set_new_context(int cid)
_pdp_type = pdp_type;
_cid = cid;
_new_context_set = true;
tr_info("New PDP context %d, type %s", _cid, pdp_type);
tr_info("New PDP context %d, type %d", _cid, pdp_type);
}

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

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

if (_cp_req && !_cp_in_use && (data->error == NSAPI_ERROR_OK) &&
Expand Down Expand Up @@ -948,7 +946,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
}
}
} else {
tr_debug("CellularContext: event %d, ptr %d", ev, ptr);
#if NSAPI_PPP_AVAILABLE
if (_is_blocking) {
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/device/CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref

CellularDevice::~CellularDevice()
{
tr_debug("CellularDevice destruct");
}

void CellularDevice::stop()
Expand Down Expand Up @@ -115,6 +116,7 @@ nsapi_error_t CellularDevice::create_state_machine()
_state_machine->set_cellular_callback(callback(this, &CellularDevice::cellular_callback));
err = _state_machine->start_dispatch();
if (err) {
tr_error("Start state machine failed.");
delete _state_machine;
_state_machine = NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions features/cellular/framework/device/CellularStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event

CellularStateMachine::~CellularStateMachine()
{
tr_debug("CellularStateMachine destruct");
stop();
}

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

_queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue");
if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
report_failure("Failed to start thread.");
stop();
return NSAPI_ERROR_NO_MEMORY;
}
Expand Down
Loading