mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: added greentea tests for CellularInformation.
parent
f84862191c
commit
8624765c06
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(MBED_CONF_NSAPI_PRESENT)
|
||||||
|
#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
|
||||||
|
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
#include "unity.h"
|
||||||
|
#include "utest.h"
|
||||||
|
|
||||||
|
#include "mbed.h"
|
||||||
|
|
||||||
|
#include "CellularConnectionFSM.h"
|
||||||
|
#include "CellularDevice.h"
|
||||||
|
#include "../../cellular_tests_common.h"
|
||||||
|
|
||||||
|
#define SIM_TIMEOUT (180*1000)
|
||||||
|
|
||||||
|
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||||
|
static EventQueue queue(2 * EVENTS_EVENT_SIZE);
|
||||||
|
static CellularConnectionFSM cellular;
|
||||||
|
static CellularConnectionFSM::CellularState cellular_target_state;
|
||||||
|
static rtos::Semaphore fsm_semaphore(0);
|
||||||
|
|
||||||
|
static bool fsm_callback(int state, int next_state)
|
||||||
|
{
|
||||||
|
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
|
||||||
|
TEST_ASSERT(fsm_semaphore.release() == osOK);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_to_sim_state()
|
||||||
|
{
|
||||||
|
cellular.set_serial(&cellular_serial);
|
||||||
|
TEST_ASSERT(cellular.init() == NSAPI_ERROR_OK);
|
||||||
|
#if defined (MDMRTS) && defined (MDMCTS)
|
||||||
|
cellular_serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
|
||||||
|
#endif
|
||||||
|
cellular.set_callback(&fsm_callback);
|
||||||
|
TEST_ASSERT(cellular.start_dispatch() == NSAPI_ERROR_OK);
|
||||||
|
cellular_target_state = CellularConnectionFSM::STATE_SIM_PIN;
|
||||||
|
TEST_ASSERT(cellular.continue_to_state(cellular_target_state) == NSAPI_ERROR_OK);
|
||||||
|
TEST_ASSERT(fsm_semaphore.wait(SIM_TIMEOUT) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_information_interface()
|
||||||
|
{
|
||||||
|
CellularInformation *info = cellular.get_device()->open_information(&cellular_serial);
|
||||||
|
|
||||||
|
char buf[100];
|
||||||
|
TEST_ASSERT(info->get_manufacturer(buf, 100) == NSAPI_ERROR_OK);
|
||||||
|
TEST_ASSERT(info->get_model(buf, 100) == NSAPI_ERROR_OK);
|
||||||
|
TEST_ASSERT(info->get_revision(buf, 100) == NSAPI_ERROR_OK);
|
||||||
|
TEST_ASSERT(info->get_serial_number(buf, 100, CellularInformation::SN) == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
|
nsapi_error_t err = info->get_serial_number(buf, 100, CellularInformation::IMEI);
|
||||||
|
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
|
err = info->get_serial_number(buf, 100, CellularInformation::IMEISV);
|
||||||
|
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
|
err = info->get_serial_number(buf, 100, CellularInformation::SVN);
|
||||||
|
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
|
cellular.get_device()->close_information();
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace utest::v1;
|
||||||
|
|
||||||
|
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
|
||||||
|
{
|
||||||
|
greentea_case_failure_abort_handler(source, reason);
|
||||||
|
return STATUS_ABORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Case cases[] = {
|
||||||
|
Case("CellularInformation init", init_to_sim_state, greentea_failure_handler),
|
||||||
|
Case("CellularInformation test interface", test_information_interface, greentea_failure_handler)
|
||||||
|
};
|
||||||
|
|
||||||
|
static utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||||
|
{
|
||||||
|
GREENTEA_SETUP(10*60, "default_auto");
|
||||||
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Specification specification(test_setup, cases);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||||
|
trace_open();
|
||||||
|
#endif
|
||||||
|
int ret = Harness::run(specification);
|
||||||
|
#if MBED_CONF_MBED_TRACE_ENABLE
|
||||||
|
trace_close();
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -54,17 +54,17 @@ static void urc_callback()
|
||||||
static void wait_for_power(CellularPower* pwr)
|
static void wait_for_power(CellularPower* pwr)
|
||||||
{
|
{
|
||||||
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
|
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
||||||
|
|
||||||
int sanity_count = 0;
|
int sanity_count = 0;
|
||||||
while (pwr->is_device_ready() != NSAPI_ERROR_OK) {
|
while (pwr->is_device_ready() != NSAPI_ERROR_OK) {
|
||||||
sanity_count++;
|
sanity_count++;
|
||||||
wait(1);
|
wait(1);
|
||||||
MBED_ASSERT(sanity_count < 20);
|
TEST_ASSERT(sanity_count < 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pwr->set_at_mode();
|
err = pwr->set_at_mode();
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
pwr->remove_device_ready_urc_cb(&urc_callback);
|
pwr->remove_device_ready_urc_cb(&urc_callback);
|
||||||
}
|
}
|
||||||
|
@ -75,17 +75,17 @@ static void test_power_interface()
|
||||||
CellularPower* pwr = cellular_device->open_power(&cellular_serial);
|
CellularPower* pwr = cellular_device->open_power(&cellular_serial);
|
||||||
|
|
||||||
nsapi_error_t err = pwr->on();
|
nsapi_error_t err = pwr->on();
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
||||||
wait_for_power(pwr);
|
wait_for_power(pwr);
|
||||||
|
|
||||||
MBED_ASSERT(pwr->set_power_level(1,0) == NSAPI_ERROR_OK);
|
TEST_ASSERT(pwr->set_power_level(1,0) == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
err = pwr->reset();
|
err = pwr->reset();
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
wait_for_power(pwr);
|
wait_for_power(pwr);
|
||||||
|
|
||||||
err = pwr->off();
|
err = pwr->off();
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
|
@ -67,7 +67,7 @@ static char *get_rand_string(char *str, size_t size)
|
||||||
static bool fsm_callback(int state, int next_state)
|
static bool fsm_callback(int state, int next_state)
|
||||||
{
|
{
|
||||||
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
|
if (next_state == CellularConnectionFSM::STATE_SIM_PIN) {
|
||||||
MBED_ASSERT(network_semaphore.release() == osOK);
|
TEST_ASSERT(network_semaphore.release() == osOK);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -106,27 +106,27 @@ static void test_sim_interface()
|
||||||
|
|
||||||
// change pin and change it back
|
// change pin and change it back
|
||||||
err = sim->change_pin(MBED_CONF_APP_CELLULAR_SIM_PIN, pin);
|
err = sim->change_pin(MBED_CONF_APP_CELLULAR_SIM_PIN, pin);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
err = sim->change_pin(pin, MBED_CONF_APP_CELLULAR_SIM_PIN);
|
err = sim->change_pin(pin, MBED_CONF_APP_CELLULAR_SIM_PIN);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
// 3. test set_pin_query
|
// 3. test set_pin_query
|
||||||
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false);
|
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, true);
|
err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, true);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
// 4. test get_sim_state
|
// 4. test get_sim_state
|
||||||
CellularSIM::SimState state;
|
CellularSIM::SimState state;
|
||||||
err = sim->get_sim_state(state);
|
err = sim->get_sim_state(state);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
MBED_ASSERT(state == CellularSIM::SimStateReady);
|
TEST_ASSERT(state == CellularSIM::SimStateReady);
|
||||||
|
|
||||||
// 5. test get_imsi
|
// 5. test get_imsi
|
||||||
char imsi[16] = {0};
|
char imsi[16] = {0};
|
||||||
err = sim->get_imsi(imsi);
|
err = sim->get_imsi(imsi);
|
||||||
MBED_ASSERT(err == NSAPI_ERROR_OK);
|
TEST_ASSERT(err == NSAPI_ERROR_OK);
|
||||||
MBED_ASSERT(strlen(imsi) > 0);
|
TEST_ASSERT(strlen(imsi) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace utest::v1;
|
using namespace utest::v1;
|
||||||
|
|
|
@ -145,7 +145,7 @@ static void network_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
{
|
{
|
||||||
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) {
|
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE) {
|
||||||
if (ptr == NSAPI_STATUS_GLOBAL_UP) {
|
if (ptr == NSAPI_STATUS_GLOBAL_UP) {
|
||||||
MBED_ASSERT(network_semaphore.release() == osOK);
|
TEST_ASSERT(network_semaphore.release() == osOK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue