Skip to content

Commit 7bdfc07

Browse files
author
Cruz Monrreal
authored
Merge pull request #7750 from jarvte/fix_smsgreentea_tests
Cellular: Fixed sms greentea tests init
2 parents 63e4ea7 + a8faeac commit 7bdfc07

File tree

1 file changed

+42
-33
lines changed
  • features/cellular/TESTS/api/cellular_sms

1 file changed

+42
-33
lines changed

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

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
5151
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
5252
static rtos::Semaphore network_semaphore(0);
53-
static CellularConnectionFSM cellularConnectionFSM;
53+
static CellularConnectionFSM *cellularConnectionFSM;
5454
static CellularConnectionFSM::CellularState cellular_target_state;
5555
static CellularSMS* sms;
5656
static char service_center_address[SMS_MAX_PHONE_NUMBER_SIZE];
@@ -65,9 +65,35 @@ static bool cellular_status(int state, int next_state)
6565
return true;
6666
}
6767

68-
static void init()
68+
static void createFSM()
6969
{
70-
//the service center address is checked before any modification tests on it
70+
#if defined (MDMRTS) && defined (MDMCTS)
71+
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
72+
#endif
73+
cellularConnectionFSM = new CellularConnectionFSM();
74+
cellularConnectionFSM->set_serial(&cellular_serial);
75+
cellularConnectionFSM->set_callback(&cellular_status);
76+
77+
TEST_ASSERT(cellularConnectionFSM->init() == NSAPI_ERROR_OK);
78+
TEST_ASSERT(cellularConnectionFSM->start_dispatch() == NSAPI_ERROR_OK);
79+
cellularConnectionFSM->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
80+
81+
CellularDevice *device = cellularConnectionFSM->get_device();
82+
TEST_ASSERT(device != NULL);
83+
device->set_timeout(30000);
84+
85+
}
86+
static void store_service_center_address()
87+
{
88+
// Frist we need to go SIM_PIN state to make sure that we can get service address and device ready to accept AT commands
89+
createFSM();
90+
cellular_target_state = CellularConnectionFSM::STATE_SIM_PIN;
91+
TEST_ASSERT(cellularConnectionFSM->continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
92+
TEST_ASSERT(network_semaphore.wait(NETWORK_TIMEOUT) == 1); // cellular network searching may take several minutes
93+
94+
delete cellularConnectionFSM;
95+
cellularConnectionFSM = NULL;
96+
7197
ATHandler *at_init = new ATHandler(&cellular_serial, queue, 30000, "\r");
7298
at_init->cmd_start("AT+CSCA?");
7399
at_init->cmd_stop();
@@ -82,41 +108,27 @@ static void init()
82108
TEST_ASSERT(at_init->get_last_error() == NSAPI_ERROR_OK);
83109

84110
delete at_init;
85-
86-
#if defined (MDMRTS) && defined (MDMCTS)
87-
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
88-
#endif
89-
cellularConnectionFSM.set_serial(&cellular_serial);
90-
cellularConnectionFSM.set_callback(&cellular_status);
91-
92-
TEST_ASSERT(cellularConnectionFSM.init() == NSAPI_ERROR_OK);
93-
TEST_ASSERT(cellularConnectionFSM.start_dispatch() == NSAPI_ERROR_OK);
94-
95-
96-
CellularDevice *device = cellularConnectionFSM.get_device();
97-
98-
TEST_ASSERT(device != NULL);
99-
device->set_timeout(30000);
100-
101-
sms = device->open_sms(&cellular_serial);
102-
TEST_ASSERT(sms != NULL);
103-
104-
wait(3);
105-
106111
}
107112

108-
static void activate_context()
113+
static void init()
109114
{
110-
CellularNetwork *network = cellularConnectionFSM.get_network();
115+
// First store current service address
116+
store_service_center_address();
117+
118+
createFSM();
119+
CellularNetwork *network = cellularConnectionFSM->get_network();
111120

112121
TEST_ASSERT(network != NULL);
113122
TEST_ASSERT(network->set_credentials(MBED_CONF_APP_APN, NULL, NULL) == NSAPI_ERROR_OK);
114123

115-
cellularConnectionFSM.set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
116-
117124
cellular_target_state = CellularConnectionFSM::STATE_REGISTERING_NETWORK;
118-
TEST_ASSERT(cellularConnectionFSM.continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
125+
TEST_ASSERT(cellularConnectionFSM->continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
119126
TEST_ASSERT(network_semaphore.wait(NETWORK_TIMEOUT) == 1); // cellular network searching may take several minutes
127+
128+
sms = cellularConnectionFSM->get_device()->open_sms(&cellular_serial);
129+
TEST_ASSERT(sms != NULL);
130+
131+
wait(3);
120132
}
121133

122134
static void test_sms_initialize_text_mode()
@@ -132,8 +144,6 @@ static void test_sms_initialize_pdu_mode()
132144
static void test_set_cscs()
133145
{
134146
TEST_ASSERT(sms->set_cscs("IRA") == NSAPI_ERROR_OK);
135-
TEST_ASSERT(sms->set_cscs("8859-1") == NSAPI_ERROR_OK);
136-
TEST_ASSERT(sms->set_cscs("PCCP437") == NSAPI_ERROR_OK);
137147
TEST_ASSERT(sms->set_cscs("UCS2") == NSAPI_ERROR_OK);
138148
TEST_ASSERT(sms->set_cscs("GSM") == NSAPI_ERROR_OK);
139149
}
@@ -203,7 +213,7 @@ static void test_delete_all_messages()
203213
//send a message so that there is something to delete
204214
test_sms_send();
205215
wait(7);
206-
TEST_ASSERT(sms->delete_all_messages() == NSAPI_ERROR_OK);
216+
TEST_ASSERT(sms->delete_all_messages() == NSAPI_ERROR_OK);
207217
callbacks_received = 0;
208218
}
209219

@@ -226,7 +236,6 @@ static utest::v1::status_t greentea_failure_handler(const Case *const source, co
226236

227237
static Case cases[] = {
228238
Case("CellularSMS init", init, greentea_failure_handler),
229-
Case("CellularSMS activate context", activate_context, greentea_failure_handler),
230239
Case("CellularSMS test ME for storage", test_set_cpms_me, greentea_failure_handler),
231240
Case("CellularSMS test initialize to PDU mode", test_sms_initialize_pdu_mode, greentea_failure_handler),
232241
Case("CellularSMS test character sets", test_set_cscs, greentea_failure_handler),

0 commit comments

Comments
 (0)