Merge pull request #7102 from jarvte/adding_cellular_tests

Adding cellular tests
pull/7224/head
Cruz Monrreal 2018-06-14 10:16:58 -05:00 committed by GitHub
commit c82af3dbe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 363 additions and 14 deletions

View File

@ -0,0 +1,139 @@
/*
* 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
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "mbed.h"
#include "CellularLog.h"
#include "CellularDevice.h"
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
static CellularDevice *device;
static EventQueue queue(8 * EVENTS_EVENT_SIZE);
static void create_device()
{
device = new CELLULAR_DEVICE(queue);
TEST_ASSERT(device != NULL);
}
static void open_close_interfaces()
{
CellularNetwork *nw = device->open_network(&cellular_serial);
TEST_ASSERT(nw != NULL);
device->close_network();
nw = device->open_network(NULL);
TEST_ASSERT(nw == NULL);
CellularSIM* sim = device->open_sim(&cellular_serial);
TEST_ASSERT(sim != NULL);
device->close_sim();
sim = device->open_sim(NULL);
TEST_ASSERT(sim == NULL);
CellularInformation* info = device->open_information(&cellular_serial);
TEST_ASSERT(info != NULL);
device->close_information();
info = device->open_information(NULL);
TEST_ASSERT(info == NULL);
CellularPower* power = device->open_power(&cellular_serial);
TEST_ASSERT(power != NULL);
device->close_power();
power = device->open_power(NULL);
TEST_ASSERT(power == NULL);
CellularSMS* sms = device->open_sms(&cellular_serial);
TEST_ASSERT(sms != NULL);
device->close_sms();
sms = device->open_sms(NULL);
TEST_ASSERT(sms == NULL);
}
static void other_methods()
{
// test first without any open interfaces
device->set_timeout(5000);
device->modem_debug_on(true);
device->modem_debug_on(false);
NetworkStack* stack = device->get_stack();
TEST_ASSERT(stack == NULL);
CellularNetwork *nw = device->open_network(&cellular_serial);
TEST_ASSERT(nw != NULL);
// then test witj open interface which is called
device->set_timeout(5000);
device->modem_debug_on(true);
device->modem_debug_on(false);
stack = device->get_stack();
TEST_ASSERT(stack != NULL);
}
static void delete_device()
{
// delete will close all opened interfaces
delete device;
device = NULL;
}
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("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)
};
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()
{
mbed_trace_init();
return Harness::run(specification);
}

View File

@ -97,3 +97,17 @@ TEST(AT_CellularDevice, test_AT_CellularDevice_close_information)
unit->test_AT_CellularDevice_close_information();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_set_timeout)
{
unit->test_AT_CellularDevice_set_timeout();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
{
unit->test_AT_CellularDevice_modem_debug_on();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_get_stack)
{
unit->test_AT_CellularDevice_get_stack();
}

View File

@ -112,22 +112,56 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_open_information()
void Test_AT_CellularDevice::test_AT_CellularDevice_close_network()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
CHECK(dev.open_network(&fh1));
CHECK(ATHandler_stub::ref_count == 1);
dev.close_network();
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
CHECK(dev.open_sms(&fh1));
CHECK(ATHandler_stub::ref_count == 1);
dev.close_sms();
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_power()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
CHECK(dev.open_power(&fh1));
CHECK(ATHandler_stub::ref_count == 1);
dev.close_power();
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
CHECK(dev.open_sim(&fh1));
dev.close_sms(); // this should not affect to refcount as it's not opened
CHECK(ATHandler_stub::ref_count == 1);
dev.close_sim();
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
@ -155,3 +189,61 @@ void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
ATHandler_stub::fh_value = NULL;
}
void Test_AT_CellularDevice::test_AT_CellularDevice_set_timeout()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::timeout = 0;
ATHandler_stub::default_timeout = false;
// no interfaces open so settings timeout should not change anything
dev.set_timeout(5000);
CHECK(ATHandler_stub::timeout == 0);
CHECK(ATHandler_stub::default_timeout == false);
CHECK(dev.open_sim(&fh1));
CHECK(ATHandler_stub::ref_count == 1);
dev.set_timeout(5000);
CHECK(ATHandler_stub::timeout == 5000);
CHECK(ATHandler_stub::default_timeout == true);
dev.close_sim();
}
void Test_AT_CellularDevice::test_AT_CellularDevice_modem_debug_on()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::debug_on = false;
// no interfaces open so debug toggling should not affect
dev.modem_debug_on(true);
CHECK(ATHandler_stub::debug_on == false);
CHECK(dev.open_sim(&fh1));
CHECK(ATHandler_stub::ref_count == 1);
dev.modem_debug_on(true);
CHECK(ATHandler_stub::debug_on == true);
dev.close_sim();
}
void Test_AT_CellularDevice::test_AT_CellularDevice_get_stack()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
NetworkStack *stack = dev.get_stack();
CHECK(stack == NULL);
CHECK(dev.open_network(&fh1));
stack = dev.get_stack();
CHECK(stack == NULL); // Not in PPP so also null but this is got from the network class
}

View File

@ -47,6 +47,12 @@ public:
void test_AT_CellularDevice_close_sim();
void test_AT_CellularDevice_close_information();
void test_AT_CellularDevice_set_timeout();
void test_AT_CellularDevice_modem_debug_on();
void test_AT_CellularDevice_get_stack();
};
#endif // TEST_AT_CELLULARDEVICE_H

View File

@ -25,5 +25,5 @@ TEST_SRC_FILES = \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT -DMBED_CONF_CELLULAR_DEBUG_AT=1

View File

@ -207,9 +207,9 @@ TEST(ATHandler, test_ATHandler_consume_to_stop_tag)
unit->test_ATHandler_consume_to_stop_tag();
}
TEST(ATHandler, test_ATHandler_enable_debug)
TEST(ATHandler, test_ATHandler_set_debug)
{
unit->test_ATHandler_enable_debug();
unit->test_ATHandler_set_debug();
}
TEST(ATHandler, test_ATHandler_get_3gpp_error)

View File

@ -778,15 +778,15 @@ void Test_ATHandler::test_ATHandler_consume_to_stop_tag()
CHECK(at.consume_to_stop_tag());
}
void Test_ATHandler::test_ATHandler_enable_debug()
void Test_ATHandler::test_ATHandler_set_debug()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.enable_debug(true);
at.set_debug(true);
at.enable_debug(false);
at.set_debug(false);
}
void Test_ATHandler::test_ATHandler_get_3gpp_error()

View File

@ -92,7 +92,7 @@ public:
void test_ATHandler_consume_to_stop_tag();
void test_ATHandler_enable_debug();
void test_ATHandler_set_debug();
void test_ATHandler_get_3gpp_error();
};

View File

@ -31,6 +31,10 @@ const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds
nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
int ATHandler_stub::int_value = -1;
int ATHandler_stub::ref_count = 0;
int ATHandler_stub::timeout = 0;
bool ATHandler_stub::default_timeout = 0;
bool ATHandler_stub::debug_on = 0;
ssize_t ATHandler_stub::ssize_value = 0;
char* ATHandler_stub::read_string_value = NULL;
size_t ATHandler_stub::size_value = 0;
@ -47,27 +51,32 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
_fileHandle(fh),
_queue(queue)
{
ATHandler_stub::ref_count = 1;
}
void ATHandler::enable_debug(bool enable)
void ATHandler::set_debug(bool debug_on)
{
ATHandler_stub::debug_on = debug_on;
}
ATHandler::~ATHandler()
{
ATHandler_stub::ref_count = -909;
}
void ATHandler::inc_ref_count()
{
ATHandler_stub::ref_count++;
}
void ATHandler::dec_ref_count()
{
ATHandler_stub::ref_count--;
}
int ATHandler::get_ref_count()
{
return ATHandler_stub::int_value;
return ATHandler_stub::ref_count;
}
FileHandle *ATHandler::get_file_handle()
@ -113,6 +122,8 @@ nsapi_error_t ATHandler::unlock_return_error()
void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout)
{
ATHandler_stub::timeout = timeout_milliseconds;
ATHandler_stub::default_timeout = default_timeout;
}
void ATHandler::restore_at_timeout()

View File

@ -28,6 +28,10 @@ namespace ATHandler_stub {
extern nsapi_error_t nsapi_error_value;
extern uint8_t nsapi_error_ok_counter;
extern int int_value;
extern int ref_count;
extern int timeout;
extern bool default_timeout;
extern bool debug_on;
extern ssize_t ssize_value;
extern char* read_string_value;
extern size_t size_value;

View File

@ -74,3 +74,7 @@ void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callbac
}
nsapi_error_t AT_CellularPower::is_device_ready()
{
return NSAPI_ERROR_OK;
}

View File

@ -77,3 +77,13 @@ nsapi_error_t NetworkInterface::set_blocking(bool blocking)
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_value_or_error_t NetworkInterface::gethostbyname_async(char const*, mbed::Callback<void (int, SocketAddress*)>, nsapi_version)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id)
{
return NSAPI_ERROR_UNSUPPORTED;
}

View File

@ -21,7 +21,6 @@
#include "stddef.h"
#include <new>
// Default NetworkStack operations
nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
@ -33,6 +32,11 @@ nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address)
return NSAPI_ERROR_OK;
}
nsapi_error_t NetworkStack::get_dns_server(int index, SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
@ -64,3 +68,28 @@ NetworkStack *nsapi_create_stack(NetworkStack *stack)
return NULL;
}
nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *host, hostbyname_cb_t callback,
nsapi_version_t version)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id)
{
return NSAPI_ERROR_UNSUPPORTED;
}
call_in_callback_cb_t NetworkStack::get_call_in_callback()
{
return NULL;
}
nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback<void()> func)
{
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkStack::get_ip_address()
{
return NULL;
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2017, 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.
*/
#ifndef MBED_OS_FEATURES_CELLULAR_MBED_TRACE_H_
#define MBED_OS_FEATURES_CELLULAR_MBED_TRACE_H_
//usage macros:
#define tr_debug(...)
#define tr_info(...)
#define tr_warning(...)
#define tr_warn(...)
#define tr_error(...)
#define tr_err(...)
#endif /* MBED_OS_FEATURES_CELLULAR_MBED_TRACE_H_ */

View File

@ -18,8 +18,6 @@
#ifndef CELLULAR_LOG_H_
#define CELLULAR_LOG_H_
#include "rtos.h"
#if defined(HAVE_DEBUG) && !defined(FEA_TRACE_SUPPORT)
#define FEA_TRACE_SUPPORT
#endif

View File

@ -33,7 +33,13 @@ UBLOX_PPP::~UBLOX_PPP()
CellularNetwork *UBLOX_PPP::open_network(FileHandle *fh)
{
if (!_network) {
_network = new UBLOX_PPP_CellularNetwork(*get_at_handler(fh));
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_network = new UBLOX_PPP_CellularNetwork(*atHandler);
if (!_network) {
release_at_handler(atHandler);
}
}
}
return _network;
}
@ -41,7 +47,13 @@ CellularNetwork *UBLOX_PPP::open_network(FileHandle *fh)
CellularPower *UBLOX_PPP::open_power(FileHandle *fh)
{
if (!_power) {
_power = new UBLOX_PPP_CellularPower(*get_at_handler(fh));
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_power = new UBLOX_PPP_CellularPower(*get_at_handler(fh));
if (!_power) {
release_at_handler(atHandler);
}
}
}
return _power;
}