Skip to content

Adding cellular tests #7102

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
merged 3 commits into from
Jun 14, 2018
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
139 changes: 139 additions & 0 deletions features/cellular/TESTS/api/cellular_device/main.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Test_AT_CellularDevice
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
Expand Down
2 changes: 1 addition & 1 deletion features/cellular/UNITTESTS/at/athandler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ TEST_SRC_FILES = \

include ../../MakefileWorker.mk

CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT -DMBED_CONF_CELLULAR_DEBUG_AT=1

4 changes: 2 additions & 2 deletions features/cellular/UNITTESTS/at/athandler/athandlertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions features/cellular/UNITTESTS/at/athandler/test_athandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion features/cellular/UNITTESTS/at/athandler/test_athandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Test_ATHandler

void test_ATHandler_consume_to_stop_tag();

void test_ATHandler_enable_debug();
void test_ATHandler_set_debug();

void test_ATHandler_get_3gpp_error();
};
Expand Down
15 changes: 13 additions & 2 deletions features/cellular/UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading