Skip to content

Commit 8624765

Browse files
author
Teppo Järvelin
committed
Cellular: added greentea tests for CellularInformation.
1 parent f848621 commit 8624765

File tree

4 files changed

+145
-17
lines changed

4 files changed

+145
-17
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
18+
19+
#if !defined(MBED_CONF_NSAPI_PRESENT)
20+
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
21+
#endif
22+
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+
30+
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
31+
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
32+
#endif
33+
34+
#include "greentea-client/test_env.h"
35+
#include "unity.h"
36+
#include "utest.h"
37+
38+
#include "mbed.h"
39+
40+
#include "CellularConnectionFSM.h"
41+
#include "CellularDevice.h"
42+
#include "../../cellular_tests_common.h"
43+
44+
#define SIM_TIMEOUT (180*1000)
45+
46+
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
47+
static EventQueue queue(2 * EVENTS_EVENT_SIZE);
48+
static CellularConnectionFSM cellular;
49+
static CellularConnectionFSM::CellularState cellular_target_state;
50+
static rtos::Semaphore fsm_semaphore(0);
51+
52+
static bool fsm_callback(int state, int next_state)
53+
{
54+
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
55+
TEST_ASSERT(fsm_semaphore.release() == osOK);
56+
return false;
57+
}
58+
return true;
59+
}
60+
61+
static void init_to_sim_state()
62+
{
63+
cellular.set_serial(&cellular_serial);
64+
TEST_ASSERT(cellular.init() == NSAPI_ERROR_OK);
65+
#if defined (MDMRTS) && defined (MDMCTS)
66+
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
67+
#endif
68+
cellular.set_callback(&fsm_callback);
69+
TEST_ASSERT(cellular.start_dispatch() == NSAPI_ERROR_OK);
70+
cellular_target_state = CellularConnectionFSM::STATE_SIM_PIN;
71+
TEST_ASSERT(cellular.continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
72+
TEST_ASSERT(fsm_semaphore.wait(SIM_TIMEOUT) == 1);
73+
}
74+
75+
static void test_information_interface()
76+
{
77+
CellularInformation *info = cellular.get_device()->open_information(&cellular_serial);
78+
79+
char buf[100];
80+
TEST_ASSERT(info->get_manufacturer(buf, 100) == NSAPI_ERROR_OK);
81+
TEST_ASSERT(info->get_model(buf, 100) == NSAPI_ERROR_OK);
82+
TEST_ASSERT(info->get_revision(buf, 100) == NSAPI_ERROR_OK);
83+
TEST_ASSERT(info->get_serial_number(buf, 100, CellularInformation::SN) == NSAPI_ERROR_OK);
84+
85+
nsapi_error_t err = info->get_serial_number(buf, 100, CellularInformation::IMEI);
86+
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
87+
88+
err = info->get_serial_number(buf, 100, CellularInformation::IMEISV);
89+
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
90+
91+
err = info->get_serial_number(buf, 100, CellularInformation::SVN);
92+
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
93+
94+
cellular.get_device()->close_information();
95+
}
96+
97+
using namespace utest::v1;
98+
99+
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
100+
{
101+
greentea_case_failure_abort_handler(source, reason);
102+
return STATUS_ABORT;
103+
}
104+
105+
static Case cases[] = {
106+
Case("CellularInformation init", init_to_sim_state, greentea_failure_handler),
107+
Case("CellularInformation test interface", test_information_interface, greentea_failure_handler)
108+
};
109+
110+
static utest::v1::status_t test_setup(const size_t number_of_cases)
111+
{
112+
GREENTEA_SETUP(10*60, "default_auto");
113+
return verbose_test_setup_handler(number_of_cases);
114+
}
115+
116+
static Specification specification(test_setup, cases);
117+
118+
int main()
119+
{
120+
#if MBED_CONF_MBED_TRACE_ENABLE
121+
trace_open();
122+
#endif
123+
int ret = Harness::run(specification);
124+
#if MBED_CONF_MBED_TRACE_ENABLE
125+
trace_close();
126+
#endif
127+
return ret;
128+
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ static void urc_callback()
5454
static void wait_for_power(CellularPower* pwr)
5555
{
5656
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
57-
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
57+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
5858

5959
int sanity_count = 0;
6060
while (pwr->is_device_ready() != NSAPI_ERROR_OK) {
6161
sanity_count++;
6262
wait(1);
63-
MBED_ASSERT(sanity_count < 20);
63+
TEST_ASSERT(sanity_count < 20);
6464
}
6565

6666
err = pwr->set_at_mode();
67-
MBED_ASSERT(err == NSAPI_ERROR_OK);
67+
TEST_ASSERT(err == NSAPI_ERROR_OK);
6868

6969
pwr->remove_device_ready_urc_cb(&urc_callback);
7070
}
@@ -75,17 +75,17 @@ static void test_power_interface()
7575
CellularPower* pwr = cellular_device->open_power(&cellular_serial);
7676

7777
nsapi_error_t err = pwr->on();
78-
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
78+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
7979
wait_for_power(pwr);
8080

81-
MBED_ASSERT(pwr->set_power_level(1,0) == NSAPI_ERROR_OK);
81+
TEST_ASSERT(pwr->set_power_level(1,0) == NSAPI_ERROR_OK);
8282

8383
err = pwr->reset();
84-
MBED_ASSERT(err == NSAPI_ERROR_OK);
84+
TEST_ASSERT(err == NSAPI_ERROR_OK);
8585
wait_for_power(pwr);
8686

8787
err = pwr->off();
88-
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
88+
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
8989
}
9090

9191
using namespace utest::v1;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static char *get_rand_string(char *str, size_t size)
6767
static bool fsm_callback(int state, int next_state)
6868
{
6969
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
70-
MBED_ASSERT(network_semaphore.release() == osOK);
70+
TEST_ASSERT(network_semaphore.release() == osOK);
7171
return false;
7272
}
7373
return true;
@@ -106,27 +106,27 @@ static void test_sim_interface()
106106

107107
// change pin and change it back
108108
err = sim->change_pin(MBED_CONF_APP_CELLULAR_SIM_PIN, pin);
109-
MBED_ASSERT(err == NSAPI_ERROR_OK);
109+
TEST_ASSERT(err == NSAPI_ERROR_OK);
110110
err = sim->change_pin(pin, MBED_CONF_APP_CELLULAR_SIM_PIN);
111-
MBED_ASSERT(err == NSAPI_ERROR_OK);
111+
TEST_ASSERT(err == NSAPI_ERROR_OK);
112112

113113
// 3. test set_pin_query
114114
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false);
115-
MBED_ASSERT(err == NSAPI_ERROR_OK);
115+
TEST_ASSERT(err == NSAPI_ERROR_OK);
116116
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, true);
117-
MBED_ASSERT(err == NSAPI_ERROR_OK);
117+
TEST_ASSERT(err == NSAPI_ERROR_OK);
118118

119119
// 4. test get_sim_state
120120
CellularSIM::SimState state;
121121
err = sim->get_sim_state(state);
122-
MBED_ASSERT(err == NSAPI_ERROR_OK);
123-
MBED_ASSERT(state == CellularSIM::SimStateReady);
122+
TEST_ASSERT(err == NSAPI_ERROR_OK);
123+
TEST_ASSERT(state == CellularSIM::SimStateReady);
124124

125125
// 5. test get_imsi
126126
char imsi[16] = {0};
127127
err = sim->get_imsi(imsi);
128-
MBED_ASSERT(err == NSAPI_ERROR_OK);
129-
MBED_ASSERT(strlen(imsi) > 0);
128+
TEST_ASSERT(err == NSAPI_ERROR_OK);
129+
TEST_ASSERT(strlen(imsi) > 0);
130130
}
131131

132132
using namespace utest::v1;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void network_callback(nsapi_event_t ev, intptr_t ptr)
145145
{
146146
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) {
147147
if (ptr == NSAPI_STATUS_GLOBAL_UP) {
148-
MBED_ASSERT(network_semaphore.release() == osOK);
148+
TEST_ASSERT(network_semaphore.release() == osOK);
149149
}
150150
}
151151
}

0 commit comments

Comments
 (0)