Merge pull request #6082 from AriParkkila/master

Mbed OS cellular connectivity
pull/6267/merge
Anna Bridge 2018-03-02 18:36:48 +00:00 committed by GitHub
commit a6e27b1b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
178 changed files with 19123 additions and 8 deletions

View File

@ -111,7 +111,7 @@ matrix:
- python tools/make.py -t GCC_ARM -m K64F --source=. --build=BUILD/K64F/GCC_ARM -j0
# Check that example compiles without rtos
- sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' $EVENTS/README.md > main.cpp
- rm -r rtos features/netsocket features/frameworks BUILD
- rm -r rtos features/cellular features/netsocket features/frameworks BUILD
- python tools/make.py -t GCC_ARM -m DISCO_F401VC --source=. --build=BUILD/DISCO_F401VC/GCC_ARM -j0
# Run local equeue tests
- make -C $EVENTS/equeue test

12
features/cellular/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
lcov/
results/
coverages/
gcov/
*.exe
*.o
*.d
*.a
*.gcda
*.gcno
cpputest_*.xml
*_unit_tests*

View File

@ -0,0 +1 @@
UNITTESTS/*

View File

@ -0,0 +1,56 @@
#
# Makefile.test for CIot library unit tests
#
# List of subdirectories to build
TEST_FOLDER_NAME := UNITTESTS
TEST_FOLDER := ./UNITTESTS/
# List of unit test directories for libraries
UNITTESTS := $(sort $(dir $(wildcard $(TEST_FOLDER)*)))
TESTDIRS := $(UNITTESTS:%=build-%)
CLEANTESTDIRS := $(UNITTESTS:%=clean-%)
COVERAGEFILE := ./lcov/coverage.info
.PHONY: test
test: $(TESTDIRS)
@rm -rf ./lcov
@rm -rf ./coverage
@mkdir -p lcov
@mkdir -p lcov/results
@mkdir coverage
@find $(TEST_FOLDER) -name '*.xml' | xargs cp -t ./lcov/results/
@rm -f lcov/index.xml
@./xsl_script.sh
@cp junit_xsl.xslt lcov/.
@xsltproc -o lcov/testresults.html lcov/junit_xsl.xslt lcov/index.xml
@rm -f lcov/junit_xsl.xslt
@rm -f lcov/index.xml
@find ./ -name '*.gcno' | xargs cp --backup=numbered -t ./coverage/
@find ./ -name '*.gcda' | xargs cp --backup=numbered -t ./coverage/
@gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/$(TEST_FOLDER_NAME)/.*' -e '.*/yotta_modules/.*' -e '.*/stubs/.*' -e '.*/mbed-coap/.*' -x -o ./lcov/gcovr.xml
@lcov -d $(TEST_FOLDER_NAME)/. -c -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/usr*" -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/$(TEST_FOLDER_NAME)*" -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/mbed-client-libservice*" -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/mbed-client*" -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/mbed-os/events*" -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/mbed-os/features/netsocket*" -o $(COVERAGEFILE)
@lcov -q -r $(COVERAGEFILE) "/mbed-os/platform*" -o $(COVERAGEFILE)
@genhtml -q $(COVERAGEFILE) --output-directory lcov/html
@echo mbed-ciot module unit tests built
$(TESTDIRS):
@make -C $(@:build-%=%)
$(CLEANDIRS):
@make -C $(@:clean-%=%) clean
$(CLEANTESTDIRS):
@make -C $(@:clean-%=%) clean
# Extend default clean rule
clean: clean-extra
clean-extra: $(CLEANDIRS) \
$(CLEANTESTDIRS)

View File

@ -0,0 +1,73 @@
# Mbed cellular connectivity
This is the Github repo for Mbed cellular connectivity:
easy_cellular/
EasyCellularConnection Simplified cellular usage based on `CellularBase.h`
CellularConnectionUtil A utility class for cellular connection
framework/
API Application Programming Interface for cellular connectivity
AT AT implementation based on 3GPP TS 27.007 specification
common Common and utility sources
targets Vendor specific cellular module adaptations
## Known limitations
**Please note that this is a first release of Cellular framework and is subject to further development in future.**
Only UDP is supported when using AT commands to control sockets in an IP stack built into the cellular modem. If TCP is required, use the PPP/LWIP stack.
## Supported modules
You can find currently supported cellular modules in the `framework/targets/` folder, where we also add support for new cellular modules.
## Cellular configuration
You can change cellular defaults in the `mbed_app.json` configuration file:
"config": {
"cellular_plmn": {
"help": "PLMN selection, 0=auto",
"value": 0
},
"apn": {
"help": "Access point name, e.g. internet",
"value": "\"internet\""
},
"cellular_sim_pin": {
"help": "PIN code",
"value": "\"1234\""
}
}
## Debug traces
You can define the debug tracing level in the `mbed_app.json` configuration file:
"target_overrides": {
"*": {
"target.features_add": ["COMMON_PAL"],
"mbed-trace.enable": true,
"platform.stdio-convert-newlines": true,
"platform.stdio-baud-rate": 115200,
"platform.default-serial-baud-rate": 115200
}
},
"config": {
"trace-level": {
"help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG",
"macro_name": "MBED_TRACE_MAX_LEVEL",
"value": "TRACE_LEVEL_INFO"
}
}
## Unit tests
The `UNITTESTS` folder contains unit tests for cellular specific classes. Unit tests are based on the stubbing method.
You can run those tests locally by running `./run_tests` script under the `UNITTESTS/` folder.
You need the following applications: `cpputest`, `gcov` and `lcov` (genhtml) for running the tests.
After you have run the `run_tests` script, you can find test results under `UNITTESTS/results` folder and line and function coverages under the `UNITTESTS/coverages` folder.

View File

@ -0,0 +1,82 @@
/*
* 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 CELLULAR_TESTS_H
#define CELLULAR_TESTS_H
#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"
#ifdef CELLULAR_DEVICE
#include "mbed_events.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "CellularLog.h"
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
extern EventQueue queue;
extern CELLULAR_DEVICE cellularDevice;
extern UARTSerial serial;
extern CellularNetwork *network;
extern CellularSMS *sms;
extern CellularPower *pwr;
extern CellularSIM *sim;
/**
* TEST CASES DEFINED HERE AND in main.cpp
*/
// power
void test_create_power(void);
// SIM
void test_get_sim_state(void);
void test_set_pin(void);
void test_change_pin(void);
// sms
void test_sms_init(void);
// network
void test_attach(void);
void test_connect(void);
void test_get_ip_address(void);
void test_disconnect(void);
// stack
void test_socket_open(void);
void test_socket_bind(void);
/*
void test_socket_set_blocking();
void test_socket_send_receive_blocking();
*/
void test_socket_set_non_blocking();
void test_socket_send_receive_non_blocking();
void test_socket_close(void);
// Test closing all interface via device
void test_close_interfaces(void);
#endif // CELLULAR_DEVICE
#endif // CELLULAR_TESTS_H

View File

@ -0,0 +1,107 @@
/*
* 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.
*/
#include "CellularTests.h"
#if !defined(MBED_CONF_NSAPI_PRESENT)
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
#endif
#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined for this test
#endif
EventQueue queue(32 * EVENTS_EVENT_SIZE);
Thread t;
CELLULAR_DEVICE cellularDevice(queue);
UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
CellularNetwork *network = NULL;
CellularPower *pwr = NULL;
CellularSIM *sim = NULL;
CellularSMS *sms = NULL;
using namespace utest::v1;
// using namespace mbed;
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE;
}
Case cases[] = {
// power test
Case("Create power", test_create_power, greentea_failure_handler),
#ifdef MBED_CONF_APP_CELLULAR_SIM_PIN
// sim test
Case("test get SIM state", test_get_sim_state, greentea_failure_handler),
Case("SIM set pin", test_set_pin, greentea_failure_handler),
Case("SIM change pin", test_change_pin, greentea_failure_handler),
#endif
// network tests
Case("attach", test_attach, greentea_failure_handler),
// SMS tests
Case("SMS init", test_sms_init, greentea_failure_handler),
// network tests
Case("connect", test_connect, greentea_failure_handler),
Case("get_ip_address", test_get_ip_address, greentea_failure_handler),
// stack tests
Case("open", test_socket_open, greentea_failure_handler),
Case("bind", test_socket_bind, greentea_failure_handler),
// Case("set socket blocking", test_socket_set_blocking, greentea_failure_handler),
// Case("socket send receive in blocking mode", test_socket_send_receive_blocking, greentea_failure_handler),
Case("set socket non blocking", test_socket_set_non_blocking, greentea_failure_handler),
Case("socket send receive in non blocking mode", test_socket_send_receive_non_blocking, greentea_failure_handler),
Case("close", test_socket_close, greentea_failure_handler),
// network tests
Case("disconnect", test_disconnect, greentea_failure_handler),
// test closing of all interface, must be the last test case
Case("Close all Interfaces", test_close_interfaces, greentea_failure_handler)
};
utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(300, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}
Specification specification(test_setup, cases);
void test_close_interfaces()
{
// SMS is already closed in it's test
cellularDevice.close_network();
cellularDevice.close_sim();
cellularDevice.close_power();
}
int main()
{
#if defined (MDMRTS) && defined (MDMCTS)
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
#endif
pwr = cellularDevice.open_power(&serial);
sim = cellularDevice.open_sim(&serial);
sms = cellularDevice.open_sms(&serial);
network = cellularDevice.open_network(&serial);
t.start(callback(&queue, &EventQueue::dispatch_forever));
return Harness::run(specification);
}

View File

@ -0,0 +1,103 @@
/*
* 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.
*/
#include "CellularTests.h"
#ifdef CELLULAR_DEVICE
using namespace mbed;
static bool wait_register()
{
tr_info("Try registering to network...");
if (network->set_registration() != NSAPI_ERROR_OK) {
tr_error("Network registration request failed.");
return false;
}
CellularNetwork::RegistrationStatus status;
for (int i=0; i<180; i++) {
tr_info("Register to network %d...", i);
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
if (network->get_registration_status((CellularNetwork::RegistrationType)type, status) == NSAPI_ERROR_OK) {
tr_info("status %d...", status);
switch (status) {
case CellularNetwork::RegisteredRoaming:
// fall-through
case CellularNetwork::RegisteredHomeNetwork:
tr_info("Registered to network.");
return true;
case CellularNetwork::RegisteredSMSOnlyRoaming:
// fall-through
case CellularNetwork::RegisteredSMSOnlyHome:
tr_warn("SMS only network registration!");
return true;
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
// fall-through
case CellularNetwork::RegisteredCSFBNotPreferredHome:
tr_warn("Not preferred network registration!");
return true;
case CellularNetwork::AttachedEmergencyOnly:
tr_warn("Emergency only network registration!");
return true;
case CellularNetwork::RegistrationDenied:
tr_warn("Network registration denied!");
wait(i);
break;
case CellularNetwork::NotRegistered:
case CellularNetwork::Unknown:
case CellularNetwork::SearchingNetwork:
default:
break;
}
}
}
wait(1);
}
return false;
}
void test_attach()
{
tr_info("Register to network.");
TEST_ASSERT(wait_register());
tr_info("Attach to network.");
nsapi_error_t err = network->set_attach();
TEST_ASSERT(!err);
CellularNetwork::AttachStatus status;
err = network->get_attach(status);
TEST_ASSERT(!err);
}
void test_connect()
{
nsapi_error_t err = network->connect();
TEST_ASSERT(!err);
}
void test_get_ip_address()
{
const char *ip = network->get_ip_address();
TEST_ASSERT(ip && ip[0]);
tr_info("IP: %s\r\n", ip);
}
void test_disconnect()
{
nsapi_error_t err = network->disconnect();
TEST_ASSERT(!err);
}
#endif // CELLULAR_DEVICE

View File

@ -0,0 +1,52 @@
/*
* 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.
*/
#include "CellularTests.h"
#ifdef CELLULAR_DEVICE
using namespace mbed;
static bool start_cellular_at(CellularPower *pwr)
{
nsapi_error_t err = pwr->off();
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
return false;
}
err = pwr->on();
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
return false;
}
tr_info("Wait for cellular device 180 seconds...");
for (int i = 0; i < 180; i++) {
if (pwr->set_at_mode() == NSAPI_ERROR_OK) {
return true;
}
wait(1);
}
return false;
}
void test_create_power()
{
TEST_ASSERT(start_cellular_at(pwr));
tr_info("Cellular device is ready!");
}
// TODO: tests still missing for off, sleep, opt_power_save_mode, opt_receive_period
#endif // CELLULAR_DEVICE

View File

@ -0,0 +1,90 @@
/*
* 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.
*/
#include "CellularTests.h"
#ifdef CELLULAR_DEVICE
#ifdef MBED_CONF_APP_CELLULAR_SIM_PIN
using namespace mbed;
void test_get_sim_state()
{
wait(1);
CellularSIM::SimState state = CellularSIM::SimStateUnknown;
tr_info("Wait SIM for 180 seconds...");
for (int i = 0; i < 180; i++) {
CellularSIM::SimState tmp_state;
if ((sim->get_sim_state(tmp_state) == NSAPI_ERROR_OK) && tmp_state != CellularSIM::SimStateUnknown) {
state = tmp_state;
break;
}
}
TEST_ASSERT_MESSAGE(state == CellularSIM::SimStateReady || state == CellularSIM::SimStatePinNeeded ||
state == CellularSIM::SimStatePukNeeded, "Invalid SIM state");
}
// creates PIN which is different than one defined in MBED_CONF_APP_CELLULAR_SIM_PIN
static void create_random_pin(char* random_pin)
{
char s[11];
do {
sprintf(s,"%d", rand());
} while (strncmp(s, MBED_CONF_APP_CELLULAR_SIM_PIN, 4) == 0);
strncpy(random_pin, s, 4);
random_pin[4] = '\0';
}
void test_set_pin()
{
// run test only if sim is not in ready state as then sim interface will return NSAPI_ERROR_OK
nsapi_error_t err;
CellularSIM::SimState state = CellularSIM::SimStateUnknown;
if ((sim->get_sim_state(state) == NSAPI_ERROR_OK) && (state != CellularSIM::SimStateReady)) {
char random_pin[5];
create_random_pin(random_pin);
err = sim->set_pin(random_pin);
TEST_ASSERT_MESSAGE(err != 0, "Setting random pin should fail");
}
err = sim->set_pin(MBED_CONF_APP_CELLULAR_SIM_PIN);
char err_msg[60];
sprintf(err_msg, "Setting correct pin: %s failed with: %d", MBED_CONF_APP_CELLULAR_SIM_PIN, err);
TEST_ASSERT_MESSAGE(err == 0, err_msg);
}
void test_change_pin()
{
char random_pin[5];
create_random_pin(random_pin);
nsapi_error_t err = sim->change_pin(MBED_CONF_APP_CELLULAR_SIM_PIN, random_pin);
char err_msg[60];
sprintf(err_msg, "Change from original pin failed with: %d", err);
TEST_ASSERT_MESSAGE(err == NSAPI_ERROR_OK, err_msg);
err = sim->change_pin(random_pin, MBED_CONF_APP_CELLULAR_SIM_PIN);
sprintf(err_msg, "Change back original pin failed with: %d", err);
TEST_ASSERT_MESSAGE(err == NSAPI_ERROR_OK, err_msg);
}
#endif
#endif // CELLULAR_DEVICE

View File

@ -0,0 +1,46 @@
/*
* 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.
*/
#include "CellularTests.h"
#ifdef CELLULAR_DEVICE
using namespace mbed;
void test_sms_init()
{
// for some weird reason if we don't wait for few seconds we get SIM Busy error in initialize even is SIM is ready...
wait(3);
// check SIM state as we have tested sim and it might not be ready
for (int i = 0; i < MAX_SIM_READY_WAITING_TIME; i++) {
CellularSIM::SimState state;
if (sim->get_sim_state(state) == NSAPI_ERROR_OK && state == CellularSIM::SimStateReady) {
break;
}
wait(1);
}
nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodeText);
char err_msg[60];
sprintf(err_msg, "SMS initialize failed with: %d", err);
cellularDevice.close_sms();
sms = NULL;
TEST_ASSERT_MESSAGE(!err, err_msg);
}
#endif // CELLULAR_DEVICE

View File

@ -0,0 +1,120 @@
/*
* 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.
*/
#include "CellularTests.h"
#ifdef CELLULAR_DEVICE
using namespace mbed;
static UDPSocket socket;
#define SERVER_IP_ADDR "52.215.34.155"
#define SERVER_UDP_PORT 7
static rtos::Semaphore sock_event;
void test_socket_open()
{
nsapi_error_t err = socket.open(network);
TEST_ASSERT(err == NSAPI_ERROR_OK);
}
void test_socket_bind()
{
nsapi_error_t err = socket.bind(3030);
TEST_ASSERT(!err);
}
/*
void test_socket_set_blocking()
{
//socket.set_blocking(true);
socket.set_timeout(5000);
}
void test_socket_send_receive_blocking()
{
char receive_buffer[CELLULAR_MTU] = {0};
char send_buffer[] = { 'H', 'e', 'l', 'l', 'u', 'l', 'a', 'r', '!' };
int send_count = 0;
int send_tries = 1;
int max_send_tries = 3;
// Send to echo server
while (send_tries <= max_send_tries) {
tr_info("ONE!!!");
send_count = socket.sendto(SERVER_IP_ADDR, SERVER_UDP_PORT, send_buffer, sizeof(send_buffer));
TEST_ASSERT_MESSAGE(send_count == sizeof(send_buffer), "Sent count doesnt match sent buffer!");
send_tries++;
// Read response
SocketAddress address;
int receive_count = 0;
// 2 tries. First recv attempt should be blocked and wait for a max 5 seconds for socket read flag
int recv_tries = 2;
while (recv_tries >= 0) {
tr_info("RECV!!!");
receive_count = socket.recvfrom(&address, receive_buffer, sizeof(receive_buffer));
if (receive_count > 0) {
break;
}
recv_tries--;
wait(1);
}
TEST_ASSERT_MESSAGE(receive_count == send_count, "Receive and Sent count dont match!");
TEST_ASSERT_MESSAGE(strncmp(send_buffer, receive_buffer, send_count) == 0, "Sent data doesn't match received data while in ECHO");
}
}
*/
static void socket_sigio_cb()
{
sock_event.release();
}
void test_socket_set_non_blocking()
{
socket.set_blocking(false);
socket.sigio(socket_sigio_cb);
}
void test_socket_send_receive_non_blocking()
{
char receive_buffer[1500] = {0};
char send_buffer[] = { 'H', 'e', 'l', 'l', 'u', 'l', 'a', 'r', '!' };
// Send to echo server
int send_count = socket.sendto(SERVER_IP_ADDR, SERVER_UDP_PORT, send_buffer, sizeof(send_buffer));
TEST_ASSERT(send_count == sizeof(send_buffer));
int32_t event;
event = sock_event.wait(10000);
TEST_ASSERT_MESSAGE( event>=1, "No Socket event within 10 seconds");
// Read response
SocketAddress address;
int receive_count = socket.recvfrom(&address, receive_buffer, sizeof(receive_buffer));
TEST_ASSERT_MESSAGE(receive_count == send_count, "Receive and Sent count dont match!");
TEST_ASSERT_MESSAGE(strncmp(send_buffer, receive_buffer, send_count) == 0, "Sent data doesn't match received data while in ECHO");
}
void test_socket_close()
{
nsapi_error_t err = socket.close();
TEST_ASSERT(!err);
}
#endif // CELLULAR_DEVICE

View File

@ -0,0 +1,31 @@
{
"config": {
"sock-type": "UDP",
"network-interface":{
"help": "Options are ETHERNET,CELLULAR",
"value": "CELLULAR"
},
"cellular_sim_pin": {
"help": "PIN code",
"value": "\"1234\""
},
"trace-level": {
"help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG",
"macro_name": "MBED_TRACE_MAX_LEVEL",
"value": "TRACE_LEVEL_INFO"
}
},
"target_overrides": {
"*": {
"target.features_add": ["LWIP", "COMMON_PAL"],
"mbed-trace.enable": true,
"lwip.ipv4-enabled": true,
"lwip.ethernet-enabled": false,
"lwip.ppp-enabled": true,
"lwip.tcp-enabled": true,
"platform.stdio-convert-newlines": true,
"platform.stdio-baud-rate": 115200,
"platform.default-serial-baud-rate": 115200
}
}
}

View File

@ -0,0 +1,19 @@
#scan for folders having "Makefile" in them and remove 'this' to prevent loop
DIRS := $(filter-out ./, $(sort $(dir $(shell find . -name 'Makefile'))))
all:
for dir in $(DIRS); do \
cd $$dir; make gcov; cd ..; cd ..;\
done
clean:
for dir in $(DIRS); do \
cd $$dir; make clean; cd ..; cd ..;\
done
rm -rf ../source/*gcov ../source/*gcda ../source/*o
rm -rf stubs/*gcov stubs/*gcda stubs/*o
rm -rf results/*
rm -rf coverages/*
rm -rf results
rm -rf coverages

View File

@ -0,0 +1,562 @@
#---------
#
# MakefileWorker.mk
#
# Include this helper file in your makefile
# It makes
# A static library
# A test executable
#
# See this example for parameter settings
# examples/Makefile
#
#----------
# Inputs - these variables describe what to build
#
# INCLUDE_DIRS - Directories used to search for include files.
# This generates a -I for each directory
# SRC_DIRS - Directories containing source file to built into the library
# SRC_FILES - Specific source files to build into library. Helpful when not all code
# in a directory can be built for test (hopefully a temporary situation)
# TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner
# These do not go in a library. They are explicitly included in the test runner
# TEST_SRC_FILES - Specific source files to build into the unit test runner
# These do not go in a library. They are explicitly included in the test runner
# MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner
# These do not go in a library. They are explicitly included in the test runner
#----------
# You can adjust these variables to influence how to build the test target
# and where to put and name outputs
# See below to determine defaults
# COMPONENT_NAME - the name of the thing being built
# TEST_TARGET - name the test executable. By default it is
# $(COMPONENT_NAME)_tests
# Helpful if you want 1 > make files in the same directory with different
# executables as output.
# CPPUTEST_HOME - where CppUTest home dir found
# TARGET_PLATFORM - Influences how the outputs are generated by modifying the
# CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the
# normal objs and lib directories. Also modifies where to search for the
# CPPUTEST_LIB to link against.
# CPPUTEST_OBJS_DIR - a directory where o and d files go
# CPPUTEST_LIB_DIR - a directory where libs go
# CPPUTEST_ENABLE_DEBUG - build for debug
# CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete
# CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out
# of the test harness
# CPPUTEST_USE_GCOV - Turn on coverage analysis
# Clean then build with this flag set to Y, then 'make gcov'
# CPPUTEST_MAPFILE - generate a map file
# CPPUTEST_WARNINGFLAGS - overly picky by default
# OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make
# other targets. Like CSlim, which is part of fitnesse
# CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user
# specification of source files and directories that aren't below
# the user's Makefile in the directory tree, like:
# SRC_DIRS += ../../lib/foo
# It defaults to N, and shouldn't be necessary except in the above case.
#----------
#
# Other flags users can initialize to sneak in their settings
# CPPUTEST_CXXFLAGS - flags for the C++ compiler
# CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor
# CPPUTEST_CFLAGS - flags for the C complier
# CPPUTEST_LDFLAGS - Linker flags
#----------
# Some behavior is weird on some platforms. Need to discover the platform.
# Platforms
UNAME_OUTPUT = "$(shell uname -a)"
MACOSX_STR = Darwin
MINGW_STR = MINGW
CYGWIN_STR = CYGWIN
LINUX_STR = Linux
SUNOS_STR = SunOS
UNKNWOWN_OS_STR = Unknown
# Compilers
CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)"
CLANG_STR = clang
SUNSTUDIO_CXX_STR = SunStudio
UNAME_OS = $(UNKNWOWN_OS_STR)
ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR))
UNAME_OS = $(MINGW_STR)
endif
ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR))
UNAME_OS = $(CYGWIN_STR)
endif
ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR))
UNAME_OS = $(LINUX_STR)
endif
ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR))
UNAME_OS = $(MACOSX_STR)
#lion has a problem with the 'v' part of -a
UNAME_OUTPUT = "$(shell uname -pmnrs)"
endif
ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR))
UNAME_OS = $(SUNOS_STR)
SUNSTUDIO_CXX_ERR_STR = CC -flags
ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR))
CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)"
COMPILER_NAME = $(SUNSTUDIO_CXX_STR)
endif
endif
ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR))
COMPILER_NAME = $(CLANG_STR)
endif
#Kludge for mingw, it does not have cc.exe, but gcc.exe will do
ifeq ($(UNAME_OS),$(MINGW_STR))
CC := gcc
endif
#And another kludge. Exception handling in gcc 4.6.2 is broken when linking the
# Standard C++ library as a shared library. Unbelievable.
ifeq ($(UNAME_OS),$(MINGW_STR))
CPPUTEST_LDFLAGS += -static
endif
ifeq ($(UNAME_OS),$(CYGWIN_STR))
CPPUTEST_LDFLAGS += -static
endif
#Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic
ifeq ($(UNAME_OS),$(MACOSX_STR))
ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9)
CPPUTEST_PEDANTIC_ERRORS = N
endif
endif
ifndef COMPONENT_NAME
COMPONENT_NAME = name_this_in_the_makefile
endif
# Debug on by default
ifndef CPPUTEST_ENABLE_DEBUG
CPPUTEST_ENABLE_DEBUG = Y
endif
# new and delete for memory leak detection on by default
ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
CPPUTEST_USE_MEM_LEAK_DETECTION = Y
endif
# Use the standard C library
ifndef CPPUTEST_USE_STD_C_LIB
CPPUTEST_USE_STD_C_LIB = Y
endif
# Use the standard C++ library
ifndef CPPUTEST_USE_STD_CPP_LIB
CPPUTEST_USE_STD_CPP_LIB = Y
endif
# Use gcov, off by default
ifndef CPPUTEST_USE_GCOV
CPPUTEST_USE_GCOV = N
endif
ifndef CPPUTEST_PEDANTIC_ERRORS
CPPUTEST_PEDANTIC_ERRORS = Y
endif
# Default warnings
ifndef CPPUTEST_WARNINGFLAGS
CPPUTEST_WARNINGFLAGS = -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion
ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y)
# CPPUTEST_WARNINGFLAGS += -pedantic-errors
CPPUTEST_WARNINGFLAGS += -pedantic
endif
ifeq ($(UNAME_OS),$(LINUX_STR))
CPPUTEST_WARNINGFLAGS += -Wsign-conversion
endif
CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual
CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes
endif
#Wonderful extra compiler warnings with clang
ifeq ($(COMPILER_NAME),$(CLANG_STR))
# -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that.
# -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit)
# -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor
# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled.
CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables
CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded
endif
# Uhm. Maybe put some warning flags for SunStudio here?
ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR))
CPPUTEST_CXX_WARNINGFLAGS =
CPPUTEST_C_WARNINGFLAGS =
endif
# Default dir for temporary files (d, o)
ifndef CPPUTEST_OBJS_DIR
ifndef TARGET_PLATFORM
CPPUTEST_OBJS_DIR = objs
else
CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM)
endif
endif
# Default dir for the outout library
ifndef CPPUTEST_LIB_DIR
ifndef TARGET_PLATFORM
CPPUTEST_LIB_DIR = lib
else
CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM)
endif
endif
# No map by default
ifndef CPPUTEST_MAP_FILE
CPPUTEST_MAP_FILE = N
endif
# No extentions is default
ifndef CPPUTEST_USE_EXTENSIONS
CPPUTEST_USE_EXTENSIONS = N
endif
# No VPATH is default
ifndef CPPUTEST_USE_VPATH
CPPUTEST_USE_VPATH := N
endif
# Make empty, instead of 'N', for usage in $(if ) conditionals
ifneq ($(CPPUTEST_USE_VPATH), Y)
CPPUTEST_USE_VPATH :=
endif
ifndef TARGET_PLATFORM
#CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib
CPPUTEST_LIB_LINK_DIR = /usr/lib/x86_64-linux-gnu
else
CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM)
endif
# --------------------------------------
# derived flags in the following area
# --------------------------------------
# Without the C library, we'll need to disable the C++ library and ...
ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
CPPUTEST_USE_STD_CPP_LIB = N
CPPUTEST_USE_MEM_LEAK_DETECTION = N
CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED
CPPUTEST_CPPFLAGS += -nostdinc
endif
CPPUTEST_CPPFLAGS += -DCPPUTEST_COMPILATION
ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N)
CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED
else
ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE
CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h
endif
ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE
CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h
endif
endif
ifeq ($(CPPUTEST_ENABLE_DEBUG), Y)
CPPUTEST_CXXFLAGS += -g
CPPUTEST_CFLAGS += -g
CPPUTEST_LDFLAGS += -g
endif
ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N)
CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED
ifeq ($(CPPUTEST_USE_STD_C_LIB), Y)
CPPUTEST_CXXFLAGS += -nostdinc++
endif
endif
ifdef $(GMOCK_HOME)
GTEST_HOME = $(GMOCK_HOME)/gtest
CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include
GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a
LD_LIBRARIES += $(GMOCK_LIBRARY)
CPPUTEST_CPPFLAGS += -DINCLUDE_GTEST_TESTS
CPPUTEST_WARNINGFLAGS =
CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME)
GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a
LD_LIBRARIES += $(GTEST_LIBRARY)
endif
ifeq ($(CPPUTEST_USE_GCOV), Y)
CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage
CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage
endif
CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS)
CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS)
CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE)
CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE)
CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS)
TARGET_MAP = $(COMPONENT_NAME).map.txt
ifeq ($(CPPUTEST_MAP_FILE), Y)
CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP)
endif
# Link with CppUTest lib
CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a
ifeq ($(CPPUTEST_USE_EXTENSIONS), Y)
CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a
endif
ifdef CPPUTEST_STATIC_REALTIME
LD_LIBRARIES += -lrt
endif
TARGET_LIB = \
$(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a
ifndef TEST_TARGET
ifndef TARGET_PLATFORM
TEST_TARGET = $(COMPONENT_NAME)_tests
else
TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests
endif
endif
#Helper Functions
get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c)
get_dirs_from_dirspec = $(wildcard $1)
get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir)))
__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2))))
src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
src_to_o = $(call src_to,.o,$1)
src_to_d = $(call src_to,.d,$1)
src_to_gcda = $(call src_to,.gcda,$1)
src_to_gcno = $(call src_to,.gcno,$1)
time = $(shell date +%s)
delta_t = $(eval minus, $1, $2)
debug_print_list = $(foreach word,$1,echo " $(word)";) echo;
#Derived
STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP)
SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES)
OBJ = $(call src_to_o,$(SRC))
STUFF_TO_CLEAN += $(OBJ)
TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES)
TEST_OBJS = $(call src_to_o,$(TEST_SRC))
STUFF_TO_CLEAN += $(TEST_OBJS)
MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS))
MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC))
STUFF_TO_CLEAN += $(MOCKS_OBJS)
ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC)
# If we're using VPATH
ifeq ($(CPPUTEST_USE_VPATH), Y)
# gather all the source directories and add them
VPATH += $(sort $(dir $(ALL_SRC)))
# Add the component name to the objs dir path, to differentiate between same-name objects
CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR))
endif
#Test coverage with gcov
GCOV_OUTPUT = gcov_output.txt
GCOV_REPORT = gcov_report.txt
GCOV_ERROR = gcov_error.txt
GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC))
GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC))
TEST_OUTPUT = $(TEST_TARGET).txt
STUFF_TO_CLEAN += \
$(GCOV_OUTPUT)\
$(GCOV_REPORT)\
$(GCOV_REPORT).html\
$(GCOV_ERROR)\
$(GCOV_GCDA_FILES)\
$(GCOV_GCNO_FILES)\
$(TEST_OUTPUT)
#The gcda files for gcov need to be deleted before each run
#To avoid annoying messages.
GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR)
RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS) -ojunit
ifeq ($(CPPUTEST_USE_GCOV), Y)
ifeq ($(COMPILER_NAME),$(CLANG_STR))
LD_LIBRARIES += --coverage
else
LD_LIBRARIES += -lgcov
endif
endif
INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS))
INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir))
MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS))
INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir))
CPPUTEST_CPPFLAGS += $(INCLUDES) $(CPPUTESTFLAGS)
DEP_FILES = $(call src_to_d, $(ALL_SRC))
STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END)
STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output
# We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags
CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS)
CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS)
CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS)
LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS)
# Don't consider creating the archive a warning condition that does STDERR output
ARFLAGS := $(ARFLAGS)c
DEP_FLAGS=-MMD -MP
# Some macros for programs to be overridden. For some reason, these are not in Make defaults
RANLIB = ranlib
# Targets
.PHONY: all
all: start $(TEST_TARGET)
$(RUN_TEST_TARGET)
.PHONY: start
start: $(TEST_TARGET)
$(SILENCE)START_TIME=$(call time)
.PHONY: all_no_tests
all_no_tests: $(TEST_TARGET)
.PHONY: flags
flags:
@echo
@echo "OS ${UNAME_OS}"
@echo "Compile C and C++ source with CPPFLAGS:"
@$(call debug_print_list,$(CPPFLAGS))
@echo "Compile C++ source with CXXFLAGS:"
@$(call debug_print_list,$(CXXFLAGS))
@echo "Compile C source with CFLAGS:"
@$(call debug_print_list,$(CFLAGS))
@echo "Link with LDFLAGS:"
@$(call debug_print_list,$(LDFLAGS))
@echo "Link with LD_LIBRARIES:"
@$(call debug_print_list,$(LD_LIBRARIES))
@echo "Create libraries with ARFLAGS:"
@$(call debug_print_list,$(ARFLAGS))
TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START)
test-deps: $(TEST_DEPS)
$(TEST_TARGET): $(TEST_DEPS)
@echo Linking $@
$(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS)
$(TARGET_LIB): $(OBJ)
@echo Building archive $@
$(SILENCE)mkdir -p $(dir $@)
$(SILENCE)$(AR) $(ARFLAGS) $@ $^
$(SILENCE)$(RANLIB) $@
test: $(TEST_TARGET)
$(RUN_TEST_TARGET) | tee $(TEST_OUTPUT)
vtest: $(TEST_TARGET)
$(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT)
$(CPPUTEST_OBJS_DIR)/%.o: %.cc
@echo compiling $(notdir $<)
$(SILENCE)mkdir -p $(dir $@)
$(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $<
$(CPPUTEST_OBJS_DIR)/%.o: %.cpp
@echo compiling $(notdir $<)
$(SILENCE)mkdir -p $(dir $@)
$(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $<
$(CPPUTEST_OBJS_DIR)/%.o: %.c
@echo compiling $(notdir $<)
$(SILENCE)mkdir -p $(dir $@)
$(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $<
ifneq "$(MAKECMDGOALS)" "clean"
-include $(DEP_FILES)
endif
.PHONY: clean
clean:
@echo Making clean
$(SILENCE)$(RM) $(STUFF_TO_CLEAN)
$(SILENCE)rm -rf gcov objs #$(CPPUTEST_OBJS_DIR)
$(SILENCE)rm -rf $(CPPUTEST_LIB_DIR)
$(SILENCE)find . -name "*.gcno" | xargs rm -f
$(SILENCE)find . -name "*.gcda" | xargs rm -f
#realclean gets rid of all gcov, o and d files in the directory tree
#not just the ones made by this makefile
.PHONY: realclean
realclean: clean
$(SILENCE)rm -rf gcov
$(SILENCE)find . -name "*.gdcno" | xargs rm -f
$(SILENCE)find . -name "*.[do]" | xargs rm -f
gcov: test
ifeq ($(CPPUTEST_USE_VPATH), Y)
$(SILENCE)gcov --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR)
else
$(SILENCE)for d in $(SRC_DIRS) ; do \
gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \
done
$(SILENCE)for f in $(SRC_FILES) ; do \
gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \
done
endif
# $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT)
/usr/share/cpputest/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT)
$(SILENCE)cat $(GCOV_REPORT)
$(SILENCE)mkdir -p gcov
$(SILENCE)mv *.gcov gcov
$(SILENCE)mv gcov_* gcov
@echo "See gcov directory for details"
.PHONEY: format
format:
$(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR)
.PHONEY: debug
debug:
@echo
@echo "Target Source files:"
@$(call debug_print_list,$(SRC))
@echo "Target Object files:"
@$(call debug_print_list,$(OBJ))
@echo "Test Source files:"
@$(call debug_print_list,$(TEST_SRC))
@echo "Test Object files:"
@$(call debug_print_list,$(TEST_OBJS))
@echo "Mock Source files:"
@$(call debug_print_list,$(MOCKS_SRC))
@echo "Mock Object files:"
@$(call debug_print_list,$(MOCKS_OBJS))
@echo "All Input Dependency files:"
@$(call debug_print_list,$(DEP_FILES))
@echo Stuff to clean:
@$(call debug_print_list,$(STUFF_TO_CLEAN))
@echo Includes:
@$(call debug_print_list,$(INCLUDES))
-include $(OTHER_MAKEFILE_TO_INCLUDE)

View File

@ -0,0 +1,21 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularBase_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularBase.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularbasetest.cpp \
test_at_cellularbase.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularbase.h"
#include "AT_CellularBase.h"
TEST_GROUP(AT_CellularBase)
{
Test_AT_CellularBase* unit;
void setup()
{
unit = new Test_AT_CellularBase();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularBase, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularBase, test_AT_CellularBase_get_at_handler)
{
unit->test_AT_CellularBase_get_at_handler();
}
TEST(AT_CellularBase, test_AT_CellularBase_get_device_error)
{
unit->test_AT_CellularBase_get_device_error();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularBase);

View File

@ -0,0 +1,59 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularbase.h"
#include "EventQueue.h"
#include "AT_CellularBase.h"
#include "ATHandler_stub.h"
#include "FileHandle_stub.h"
#include <string.h>
using namespace mbed;
using namespace events;
Test_AT_CellularBase::Test_AT_CellularBase()
{
}
Test_AT_CellularBase::~Test_AT_CellularBase()
{
}
void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 100, ",");
AT_CellularBase at(ah);
CHECK(&ah == &at.get_at_handler());
}
void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularBase at(ah);
ATHandler_stub::device_err_value.errCode = 8;
CHECK_EQUAL(8, at.get_device_error().errCode);
ATHandler_stub::device_err_value.errCode = 0;
}

View File

@ -0,0 +1,33 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARBASE_H
#define TEST_AT_CELLULARBASE_H
class Test_AT_CellularBase
{
public:
Test_AT_CellularBase();
virtual ~Test_AT_CellularBase();
void test_AT_CellularBase_get_at_handler();
void test_AT_CellularBase_get_device_error();
};
#endif // TEST_AT_CELLULARBASE_H

View File

@ -0,0 +1,29 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularDevice_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularDevice.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellulardevicetest.cpp \
test_at_cellulardevice.cpp \
../../stubs/AT_CellularNetwork_stub.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularSMS_stub.cpp \
../../stubs/AT_CellularSIM_stub.cpp \
../../stubs/AT_CellularPower_stub.cpp \
../../stubs/AT_CellularInformation_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/NetworkInterface_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,99 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellulardevice.h"
TEST_GROUP(AT_CellularDevice)
{
Test_AT_CellularDevice* unit;
void setup()
{
unit = new Test_AT_CellularDevice();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularDevice, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularDevice, test_AT_CellularDevice_constructor)
{
unit->test_AT_CellularDevice_constructor();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_get_at_handler)
{
unit->test_AT_CellularDevice_get_at_handler();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_open_network)
{
unit->test_AT_CellularDevice_open_network();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_open_sms)
{
unit->test_AT_CellularDevice_open_sms();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_open_power)
{
unit->test_AT_CellularDevice_open_power();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_open_sim)
{
unit->test_AT_CellularDevice_open_sim();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_open_information)
{
unit->test_AT_CellularDevice_open_information();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_close_network)
{
unit->test_AT_CellularDevice_close_network();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_close_sms)
{
unit->test_AT_CellularDevice_close_sms();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_close_power)
{
unit->test_AT_CellularDevice_close_power();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_close_sim)
{
unit->test_AT_CellularDevice_close_sim();
}
TEST(AT_CellularDevice, test_AT_CellularDevice_close_information)
{
unit->test_AT_CellularDevice_close_information();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularDevice);

View File

@ -0,0 +1,157 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellulardevice.h"
#include "AT_CellularDevice.h"
#include "ATHandler_stub.h"
#include "AT_CellularBase_stub.h"
#include <string.h>
using namespace mbed;
using namespace events;
Test_AT_CellularDevice::Test_AT_CellularDevice()
{
}
Test_AT_CellularDevice::~Test_AT_CellularDevice()
{
}
void Test_AT_CellularDevice::test_AT_CellularDevice_constructor()
{
EventQueue que;
AT_CellularDevice dev(que);
CellularDevice *dev2 = new AT_CellularDevice(que);
delete dev2;
}
void Test_AT_CellularDevice::test_AT_CellularDevice_get_at_handler()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
FileHandle_stub fh2;
FileHandle_stub fh3;
dev.open_network(&fh1);
dev.open_sms(&fh2);
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
dev.open_sim(&fh3);
ATHandler_stub::fh_value = &fh1;
dev.open_power(&fh1);
ATHandler_stub::fh_value = NULL;
}
void Test_AT_CellularDevice::test_AT_CellularDevice_open_network()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
CHECK(!dev.open_network(NULL));
CHECK(dev.open_network(&fh1));
}
void Test_AT_CellularDevice::test_AT_CellularDevice_open_sms()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
CHECK(!dev.open_sms(NULL));
CHECK(dev.open_sms(&fh1));
}
void Test_AT_CellularDevice::test_AT_CellularDevice_open_power()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
CHECK(!dev.open_power(NULL));
CHECK(dev.open_power(&fh1));
}
void Test_AT_CellularDevice::test_AT_CellularDevice_open_sim()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
CHECK(! dev.open_sim(NULL));
CHECK(dev.open_sim(&fh1));
}
void Test_AT_CellularDevice::test_AT_CellularDevice_open_information()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
CHECK(!dev.open_information(NULL));
CHECK(dev.open_information(&fh1));
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_network()
{
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sms()
{
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_power()
{
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_sim()
{
}
void Test_AT_CellularDevice::test_AT_CellularDevice_close_information()
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::int_value = 0;
CHECK(dev.open_information(&fh1));
ATHandler_stub::fh_value = NULL;
AT_CellularBase_stub::handler_value = NULL;
dev.close_information();
ATHandler_stub::fh_value = &fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularBase_stub::handler_value = &at;
CHECK(dev.open_information(&fh1));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
dev.close_information();
ATHandler_stub::fh_value = NULL;
}

View File

@ -0,0 +1,53 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARDEVICE_H
#define TEST_AT_CELLULARDEVICE_H
class Test_AT_CellularDevice
{
public:
Test_AT_CellularDevice();
virtual ~Test_AT_CellularDevice();
void test_AT_CellularDevice_constructor();
void test_AT_CellularDevice_get_at_handler(); //tests also releasing of those
void test_AT_CellularDevice_open_network();
void test_AT_CellularDevice_open_sms();
void test_AT_CellularDevice_open_power();
void test_AT_CellularDevice_open_sim();
void test_AT_CellularDevice_open_information();
void test_AT_CellularDevice_close_network();
void test_AT_CellularDevice_close_sms();
void test_AT_CellularDevice_close_power();
void test_AT_CellularDevice_close_sim();
void test_AT_CellularDevice_close_information();
};
#endif // TEST_AT_CELLULARDEVICE_H

View File

@ -0,0 +1,22 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularInformation_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularInformation.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularinformationtest.cpp \
test_at_cellularinformation.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularinformation.h"
TEST_GROUP(AT_CellularInformation)
{
Test_AT_CellularInformation* unit;
void setup()
{
unit = new Test_AT_CellularInformation();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularInformation, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularInformation, test_AT_CellularInformation_get_manufacturer)
{
unit->test_AT_CellularInformation_get_manufacturer();
}
TEST(AT_CellularInformation, test_AT_CellularInformation_get_model)
{
unit->test_AT_CellularInformation_get_model();
}
TEST(AT_CellularInformation, test_AT_CellularInformation_get_revision)
{
unit->test_AT_CellularInformation_get_revision();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularInformation);

View File

@ -0,0 +1,81 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularinformation.h"
#include <string.h>
#include "ATHandler_stub.h"
#include "EventQueue.h"
#include "FileHandle_stub.h"
#include "ATHandler.h"
#include "AT_CellularInformation.h"
#include "AT_CellularBase.h"
using namespace mbed;
using namespace events;
Test_AT_CellularInformation::Test_AT_CellularInformation()
{
}
Test_AT_CellularInformation::~Test_AT_CellularInformation()
{
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_manufacturer()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularInformation aci(ah);
ATHandler_stub::nsapi_error_value = 8;
char buf[8];
CHECK(8 == aci.get_manufacturer(buf, 8));
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_model()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularInformation aci(ah);
ATHandler_stub::nsapi_error_value = 7;
char buf[8];
CHECK(7 == aci.get_model(buf, 8));
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_revision()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
//Used heap var here to visit heap constructor
AT_CellularInformation *aci = new AT_CellularInformation(ah);
ATHandler_stub::nsapi_error_value = 6;
char buf[8];
CHECK(6 == aci->get_revision(buf, 8));
delete aci;
}

View File

@ -0,0 +1,35 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARINFORMATION_H
#define TEST_AT_CELLULARINFORMATION_H
class Test_AT_CellularInformation
{
public:
Test_AT_CellularInformation();
virtual ~Test_AT_CellularInformation();
void test_AT_CellularInformation_get_manufacturer();
void test_AT_CellularInformation_get_model();
void test_AT_CellularInformation_get_revision();
};
#endif // TEST_AT_CELLULARINFORMATION_H

View File

@ -0,0 +1,25 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularNetwork_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularNetwork.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularnetworktest.cpp \
test_at_cellularnetwork.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/NetworkInterface_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/us_ticker_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,159 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularnetwork.h"
TEST_GROUP(AT_CellularNetwork)
{
Test_AT_CellularNetwork* unit;
void setup()
{
unit = new Test_AT_CellularNetwork();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularNetwork, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_constructor)
{
unit->test_AT_CellularNetwork_constructor();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_credentials)
{
unit->test_AT_CellularNetwork_set_credentials();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_connect)
{
unit->test_AT_CellularNetwork_connect();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_disconnect)
{
unit->test_AT_CellularNetwork_disconnect();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_stack)
{
unit->test_AT_CellularNetwork_get_stack();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_registration)
{
unit->test_AT_CellularNetwork_set_registration();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_registration_status)
{
unit->test_AT_CellularNetwork_get_registration_status();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_attach)
{
unit->test_AT_CellularNetwork_set_attach();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_attach)
{
unit->test_AT_CellularNetwork_get_attach();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_rate_control)
{
unit->test_AT_CellularNetwork_get_rate_control();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_apn_backoff_timer)
{
unit->test_AT_CellularNetwork_get_apn_backoff_timer();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_ip_address)
{
unit->test_AT_CellularNetwork_get_ip_address();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_access_technology)
{
unit->test_AT_CellularNetwork_set_access_technology();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_scan_plmn)
{
unit->test_AT_CellularNetwork_scan_plmn();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_ciot_optimization_config)
{
unit->test_AT_CellularNetwork_set_ciot_optimization_config();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_ciot_optimization_config)
{
unit->test_AT_CellularNetwork_get_ciot_optimization_config();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_stack_type)
{
unit->test_AT_CellularNetwork_set_stack_type();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_stack_type)
{
unit->test_AT_CellularNetwork_get_stack_type();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_pdpcontext_params)
{
unit->test_AT_CellularNetwork_get_pdpcontext_params();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_extended_signal_quality)
{
unit->test_AT_CellularNetwork_get_extended_signal_quality();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality)
{
unit->test_AT_CellularNetwork_get_signal_quality();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_cell_id)
{
unit->test_AT_CellularNetwork_get_cell_id();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_3gpp_error)
{
unit->test_AT_CellularNetwork_get_3gpp_error();
}
TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_operator_params)
{
unit->test_AT_CellularNetwork_get_operator_params();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularNetwork);

View File

@ -0,0 +1,336 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularnetwork.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularDevice.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
class my_AT_CN : public AT_CellularNetwork {
public:
my_AT_CN(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {}
virtual ~my_AT_CN() {}
NetworkStack *get_stack() {return AT_CellularNetwork::get_stack();}
};
void conn_stat_cb(nsapi_error_t error)
{
}
Test_AT_CellularNetwork::Test_AT_CellularNetwork()
{
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::int_value = -1;
}
Test_AT_CellularNetwork::~Test_AT_CellularNetwork()
{
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_constructor()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork *cn = new AT_CellularNetwork(at);
delete cn;
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_credentials()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP));
CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn"));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_connect()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
cn.set_stack_type(IPV4V6_STACK);
CHECK(NSAPI_ERROR_NO_CONNECTION == cn.connect("APN", "a", "b"));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_NO_CONNECTION == cn.connect("APN"));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_disconnect()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CHECK(NSAPI_ERROR_OK == cn.disconnect());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_stack()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
my_AT_CN cn(at);
CHECK(!cn.get_stack());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_registration()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.set_registration());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_registration_status()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CellularNetwork::RegistrationStatus stat;
CHECK(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_EREG, stat));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_attach()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.set_attach());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_attach()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CellularNetwork::AttachStatus stat;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_attach(stat));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_rate_control()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int ur;
CellularNetwork::RateControlExceptionReports reports;
CellularNetwork::RateControlUplinkTimeUnit timeUnit;
CHECK(NSAPI_ERROR_OK == cn.get_rate_control(reports, timeUnit, ur));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_apn_backoff_timer()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int time;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_apn_backoff_timer(time));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_ip_address()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CHECK(!cn.get_ip_address());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_access_technology()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CHECK(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::operator_t::RAT_UNKNOWN));
CHECK(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::operator_t::RAT_GSM_COMPACT));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_scan_plmn()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int c;
CellularNetwork::operList_t ops;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.scan_plmn(ops, c));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_ciot_optimization_config()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_ciot_optimization_config()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CellularNetwork::Supported_UE_Opt sup;
CellularNetwork::Preferred_UE_Opt pref;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_ciot_optimization_config(sup, pref));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_stack_type()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CHECK(NSAPI_ERROR_PARAMETER == cn.set_stack_type(IPV4_STACK));
CHECK(NSAPI_ERROR_OK == cn.set_stack_type(DEFAULT_STACK));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_stack_type()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CHECK(DEFAULT_STACK == cn.get_stack_type());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_pdpcontext_params()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
CellularNetwork::pdpContextList_t list;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_pdpcontext_params(list));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_extended_signal_quality()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int rx,be,rs,ec,rsrq,rsrp;
CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_extended_signal_quality(rx, be,rs,ec,rsrq, rsrp));
ATHandler_stub::int_value = 1;
CHECK(NSAPI_ERROR_OK == cn.get_extended_signal_quality(rx, be,rs,ec,rsrq, rsrp));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_signal_quality()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int rs,ber;
CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_signal_quality(rs,ber));
ATHandler_stub::int_value = 1;
CHECK(NSAPI_ERROR_OK == cn.get_signal_quality(rs,ber));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_cell_id()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int id;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_cell_id(id));
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_3gpp_error()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
ATHandler_stub::int_value = 8;
CHECK(8 == cn.get_3gpp_error());
}
void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_operator_params()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularNetwork cn(at);
int format;
CellularNetwork::operator_t ops;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == cn.get_operator_params(format, ops));
}

View File

@ -0,0 +1,77 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARNETWORK_H
#define TEST_AT_CELLULARNETWORK_H
class Test_AT_CellularNetwork
{
public:
Test_AT_CellularNetwork();
virtual ~Test_AT_CellularNetwork();
void test_AT_CellularNetwork_constructor();
void test_AT_CellularNetwork_set_credentials();
void test_AT_CellularNetwork_connect();
void test_AT_CellularNetwork_disconnect();
void test_AT_CellularNetwork_get_stack();
void test_AT_CellularNetwork_set_registration();
void test_AT_CellularNetwork_get_registration_status();
void test_AT_CellularNetwork_set_attach();
void test_AT_CellularNetwork_get_attach();
void test_AT_CellularNetwork_get_rate_control();
void test_AT_CellularNetwork_get_apn_backoff_timer();
void test_AT_CellularNetwork_get_ip_address();
void test_AT_CellularNetwork_set_access_technology();
void test_AT_CellularNetwork_scan_plmn();
void test_AT_CellularNetwork_set_ciot_optimization_config();
void test_AT_CellularNetwork_get_ciot_optimization_config();
void test_AT_CellularNetwork_set_stack_type();
void test_AT_CellularNetwork_get_stack_type();
void test_AT_CellularNetwork_get_pdpcontext_params();
void test_AT_CellularNetwork_get_extended_signal_quality();
void test_AT_CellularNetwork_get_signal_quality();
void test_AT_CellularNetwork_get_cell_id();
void test_AT_CellularNetwork_get_3gpp_error();
void test_AT_CellularNetwork_get_operator_params();
};
#endif // TEST_AT_CELLULARNETWORK_H

View File

@ -0,0 +1,23 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularPower_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularPower.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularpowertest.cpp \
test_at_cellularpower.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularpower.h"
TEST_GROUP(AT_CellularPower)
{
Test_AT_CellularPower* unit;
void setup()
{
unit = new Test_AT_CellularPower();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularPower, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularPower, test_AT_CellularPower_constructor)
{
unit->test_AT_CellularPower_constructor();
}
TEST(AT_CellularPower, test_AT_CellularPower_on)
{
unit->test_AT_CellularPower_on();
}
TEST(AT_CellularPower, test_AT_CellularPower_off)
{
unit->test_AT_CellularPower_off();
}
TEST(AT_CellularPower, test_AT_CellularPower_set_at_mode)
{
unit->test_AT_CellularPower_set_at_mode();
}
TEST(AT_CellularPower, test_AT_CellularPower_set_power_level)
{
unit->test_AT_CellularPower_set_power_level();
}
TEST(AT_CellularPower, test_AT_CellularPower_reset)
{
unit->test_AT_CellularPower_reset();
}
TEST(AT_CellularPower, test_AT_CellularPower_opt_power_save_mode)
{
unit->test_AT_CellularPower_opt_power_save_mode();
}
TEST(AT_CellularPower, test_AT_CellularPower_opt_receive_period)
{
unit->test_AT_CellularPower_opt_receive_period();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularPower);

View File

@ -0,0 +1,138 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularpower.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularPower.h"
#include "FileHandle_stub.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
Test_AT_CellularPower::Test_AT_CellularPower()
{
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
Test_AT_CellularPower::~Test_AT_CellularPower()
{
}
void Test_AT_CellularPower::test_AT_CellularPower_constructor()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower *pow = new AT_CellularPower(at);
delete pow;
}
void Test_AT_CellularPower::test_AT_CellularPower_on()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.on())
}
void Test_AT_CellularPower::test_AT_CellularPower_off()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.off())
}
void Test_AT_CellularPower::test_AT_CellularPower_set_at_mode()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.set_at_mode())
}
void Test_AT_CellularPower::test_AT_CellularPower_set_power_level()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.set_power_level(6));
}
void Test_AT_CellularPower::test_AT_CellularPower_reset()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.reset());
}
void Test_AT_CellularPower::test_AT_CellularPower_opt_power_save_mode()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(0,0));
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(10,0));
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(912,0));
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(1834,1834));
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(18345,18345));
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(101234,101234));
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_power_save_mode(1012345,1012345));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345,39612345));
}
void Test_AT_CellularPower::test_AT_CellularPower_opt_receive_period()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
}

View File

@ -0,0 +1,45 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARPOWER_H
#define TEST_AT_CELLULARPOWER_H
class Test_AT_CellularPower
{
public:
Test_AT_CellularPower();
virtual ~Test_AT_CellularPower();
void test_AT_CellularPower_constructor();
void test_AT_CellularPower_on();
void test_AT_CellularPower_off();
void test_AT_CellularPower_set_at_mode();
void test_AT_CellularPower_set_power_level();
void test_AT_CellularPower_reset();
void test_AT_CellularPower_opt_power_save_mode();
void test_AT_CellularPower_opt_receive_period();
};
#endif // TEST_AT_CELLULARPOWER_H

View File

@ -0,0 +1,24 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularSIM_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularSIM.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularsimtest.cpp \
test_at_cellularsim.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/us_ticker_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularsim.h"
TEST_GROUP(AT_CellularSIM)
{
Test_AT_CellularSIM* unit;
void setup()
{
unit = new Test_AT_CellularSIM();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularSIM, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularSIM, test_AT_CellularSIM_constructor)
{
unit->test_AT_CellularSIM_constructor();
}
TEST(AT_CellularSIM, test_AT_CellularSIM_set_pin)
{
unit->test_AT_CellularSIM_set_pin();
}
TEST(AT_CellularSIM, test_AT_CellularSIM_change_pin)
{
unit->test_AT_CellularSIM_change_pin();
}
TEST(AT_CellularSIM, test_AT_CellularSIM_set_pin_query)
{
unit->test_AT_CellularSIM_set_pin_query();
}
TEST(AT_CellularSIM, test_AT_CellularSIM_get_sim_state)
{
unit->test_AT_CellularSIM_get_sim_state();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularSIM);

View File

@ -0,0 +1,131 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularsim.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularSIM.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
Test_AT_CellularSIM::Test_AT_CellularSIM()
{
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = NULL;
ATHandler_stub::ssize_value = 0;
}
Test_AT_CellularSIM::~Test_AT_CellularSIM()
{
}
void Test_AT_CellularSIM::test_AT_CellularSIM_constructor()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM *sim = new AT_CellularSIM(at);
delete sim;
}
void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin("12"));
char table2[] = "READY";
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = table2;
ATHandler_stub::ssize_value = 5;
CHECK(NSAPI_ERROR_OK == sim.set_pin("12"));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_change_pin()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.change_pin("12", "34"));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin_query()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin_query("12", true));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.set_pin_query("12", false));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_get_sim_state()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
CellularSIM::SimState state;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
ATHandler_stub::ssize_value = -1;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state));
CHECK(CellularSIM::SimStateUnknown == state);
char table2[] = "READY";
ATHandler_stub::read_string_value = table2;
ATHandler_stub::ssize_value = 5;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state));
CHECK(CellularSIM::SimStateReady == state);
char table3[] = "SIM PIN";
ATHandler_stub::read_string_value = table3;
ATHandler_stub::ssize_value = 7;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state));
CHECK(CellularSIM::SimStatePinNeeded == state);
char table4[] = "SIM PUK";
ATHandler_stub::read_string_value = table4;
ATHandler_stub::ssize_value = 7;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state));
CHECK(CellularSIM::SimStatePukNeeded == state);
char table5[] = "SOME CRAP";
ATHandler_stub::read_string_value = table5;
ATHandler_stub::ssize_value = 9;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sim.get_sim_state(state));
CHECK(CellularSIM::SimStateUnknown == state);
}

View File

@ -0,0 +1,39 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARSIM_H
#define TEST_AT_CELLULARSIM_H
class Test_AT_CellularSIM
{
public:
Test_AT_CellularSIM();
virtual ~Test_AT_CellularSIM();
void test_AT_CellularSIM_constructor();
void test_AT_CellularSIM_set_pin();
void test_AT_CellularSIM_change_pin();
void test_AT_CellularSIM_set_pin_query();
void test_AT_CellularSIM_get_sim_state();
};
#endif // TEST_AT_CELLULARSIM_H

View File

@ -0,0 +1,25 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularSMS_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularSMS.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularsmstest.cpp \
test_at_cellularsms.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/us_ticker_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
../../stubs/mbed_wait_api_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularsms.h"
TEST_GROUP(AT_CellularSMS)
{
Test_AT_CellularSMS* unit;
void setup()
{
unit = new Test_AT_CellularSMS();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularSMS, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularSMS, test_AT_CellularSMS_constructor)
{
unit->test_AT_CellularSMS_constructor();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_initialize)
{
unit->test_AT_CellularSMS_initialize();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_send_sms)
{
unit->test_AT_CellularSMS_send_sms();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_get_sms)
{
unit->test_AT_CellularSMS_get_sms();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_set_sms_callback)
{
unit->test_AT_CellularSMS_set_sms_callback();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_set_cpms)
{
unit->test_AT_CellularSMS_set_cpms();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_set_csca)
{
unit->test_AT_CellularSMS_set_csca();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_set_cscs)
{
unit->test_AT_CellularSMS_set_cscs();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_delete_all_messages)
{
unit->test_AT_CellularSMS_delete_all_messages();
}
TEST(AT_CellularSMS, test_AT_CellularSMS_set_extra_sim_wait_time)
{
unit->test_AT_CellularSMS_set_extra_sim_wait_time();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularSMS);

View File

@ -0,0 +1,207 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularsms.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "ATHandler_stub.h"
#include "AT_CellularSMS.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
using namespace mbed;
using namespace events;
Test_AT_CellularSMS::Test_AT_CellularSMS()
{
ATHandler_stub::return_given_size = false;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
Test_AT_CellularSMS::~Test_AT_CellularSMS()
{
}
void Test_AT_CellularSMS::test_AT_CellularSMS_constructor()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS *sms = new AT_CellularSMS(at);
delete sms;
}
void Test_AT_CellularSMS::test_AT_CellularSMS_initialize()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.initialize(CellularSMS::CellularSMSMmodeText));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
CHECK(NSAPI_ERROR_PARAMETER == sms.send_sms(NULL, "2", 1));
sms.initialize(CellularSMS::CellularSMSMmodeText);
ATHandler_stub::size_value = 1;
CHECK(1 == sms.send_sms("1", "22", 2));
ATHandler_stub::size_value = 2;
CHECK(2 == sms.send_sms("1", "22", 2));
sms.initialize(CellularSMS::CellularSMSMmodePDU);
CHECK(2 == sms.send_sms("1", "23", 2));
ATHandler_stub::nsapi_error_ok_counter = 1;
ATHandler_stub::size_value = 32;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.send_sms("1", "23232323", 8));
ATHandler_stub::nsapi_error_ok_counter = 2;
ATHandler_stub::size_value = 32;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.send_sms("1", "23232323", 8));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
char table[] = "232323232323232323232323232323232323232323232323232323\
232323232323232323232323232323232323232323232323232323\
232323232323232323232323232323232323232323232323232323\
23232323232323232323232323232323232323\0";
ATHandler_stub::size_value = 0;
ATHandler_stub::return_given_size = true;
CHECK(218 == sms.send_sms("1", table, strlen(table)));
CHECK(218 == sms.send_sms("12", table, strlen(table)));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
char buf[16];
char phone[21];
char stamp[21];
int size;
CHECK(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size));
ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::int_value = 0;
CHECK(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
ATHandler_stub::resp_info_true_counter = 2;
ATHandler_stub::int_value = 11;
CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
//TODO: Should make add_info to happen, before calling get_sms!
ATHandler_stub::resp_info_true_counter = 2;
ATHandler_stub::int_value = 11;
sms.initialize(CellularSMS::CellularSMSMmodePDU);
CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
sms.set_sms_callback(NULL);
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4"));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2"));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages());
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
sms.set_extra_sim_wait_time(56);
}

View File

@ -0,0 +1,49 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARSMS_H
#define TEST_AT_CELLULARSMS_H
class Test_AT_CellularSMS
{
public:
Test_AT_CellularSMS();
virtual ~Test_AT_CellularSMS();
void test_AT_CellularSMS_constructor();
void test_AT_CellularSMS_initialize();
void test_AT_CellularSMS_send_sms();
void test_AT_CellularSMS_get_sms();
void test_AT_CellularSMS_set_sms_callback();
void test_AT_CellularSMS_set_cpms();
void test_AT_CellularSMS_set_csca();
void test_AT_CellularSMS_set_cscs();
void test_AT_CellularSMS_delete_all_messages();
void test_AT_CellularSMS_set_extra_sim_wait_time();
};
#endif // TEST_AT_CELLULARSMS_H

View File

@ -0,0 +1,26 @@
include ../../makefile_defines.txt
COMPONENT_NAME = AT_CellularStack_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/AT_CellularStack.cpp
TEST_SRC_FILES = \
main.cpp \
at_cellularstacktest.cpp \
test_at_cellularstack.cpp \
../../stubs/ATHandler_stub.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/us_ticker_stub.cpp \
../../stubs/NetworkStack_stub.cpp \
../../stubs/SocketAddress_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularstack.h"
TEST_GROUP(AT_CellularStack)
{
Test_AT_CellularStack* unit;
void setup()
{
unit = new Test_AT_CellularStack();
}
void teardown()
{
delete unit;
}
};
TEST(AT_CellularStack, Create)
{
CHECK(unit != NULL);
}
TEST(AT_CellularStack, test_AT_CellularStack_constructor)
{
unit->test_AT_CellularStack_constructor();
}
TEST(AT_CellularStack, test_AT_CellularStack_get_ip_address)
{
unit->test_AT_CellularStack_get_ip_address();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_open)
{
unit->test_AT_CellularStack_socket_open();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_close)
{
unit->test_AT_CellularStack_socket_close();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_bind)
{
unit->test_AT_CellularStack_socket_bind();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_listen)
{
unit->test_AT_CellularStack_socket_listen();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_connect)
{
unit->test_AT_CellularStack_socket_connect();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_accept)
{
unit->test_AT_CellularStack_socket_accept();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_send)
{
unit->test_AT_CellularStack_socket_send();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_recv)
{
unit->test_AT_CellularStack_socket_recv();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_sendto)
{
unit->test_AT_CellularStack_socket_sendto();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_recvfrom)
{
unit->test_AT_CellularStack_socket_recvfrom();
}
TEST(AT_CellularStack, test_AT_CellularStack_socket_attach)
{
unit->test_AT_CellularStack_socket_attach();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(AT_CellularStack);

View File

@ -0,0 +1,325 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularstack.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularStack.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "ATHandler_stub.h"
#include "SocketAddress.h"
using namespace mbed;
using namespace events;
class MyStack : public AT_CellularStack {
public:
bool bool_value;
bool max_sock_value;
nsapi_error_t create_error;
int max_packet_size;
MyStack(ATHandler &atr, int cid, nsapi_ip_stack_t typ) : AT_CellularStack(atr, cid, typ)
{
bool_value = false;
max_sock_value = 0;
create_error = NSAPI_ERROR_OK;
max_packet_size = 0;
}
virtual int get_max_socket_count(){return max_sock_value;}
virtual int get_max_packet_size(){return max_packet_size;}
virtual bool is_protocol_supported(nsapi_protocol_t protocol){return bool_value;}
virtual nsapi_error_t socket_close_impl(int sock_id){return NSAPI_ERROR_OK;}
virtual nsapi_error_t create_socket_impl(CellularSocket *socket){return create_error;}
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size){return NSAPI_ERROR_OK;}
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size) {return NSAPI_ERROR_OK;}
virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) {return AT_CellularStack::socket_open(handle, proto);}
virtual nsapi_error_t socket_close(nsapi_socket_t handle) {return AT_CellularStack::socket_close(handle);}
virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) {return AT_CellularStack::socket_bind(handle, address);}
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) {return AT_CellularStack::socket_listen(handle, backlog);}
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) {return AT_CellularStack::socket_connect(handle, address);}
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address=0) {return AT_CellularStack::socket_accept(server, handle, address);}
virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle,
const void *data, nsapi_size_t size) {return AT_CellularStack::socket_send(handle, data, size);}
virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle,
void *data, nsapi_size_t size) {return AT_CellularStack::socket_recv(handle, data, size);}
virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address,
const void *data, nsapi_size_t size) {return AT_CellularStack::socket_sendto(handle, address, data, size);}
virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address,
void *buffer, nsapi_size_t size) {return AT_CellularStack::socket_recvfrom(handle, address, buffer, size);}
virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) {return AT_CellularStack::socket_attach(handle, callback, data);}
};
Test_AT_CellularStack::Test_AT_CellularStack()
{
ATHandler_stub::ssize_value = 0;
ATHandler_stub::bool_value = false;
ATHandler_stub::read_string_value = NULL;
}
Test_AT_CellularStack::~Test_AT_CellularStack()
{
}
void Test_AT_CellularStack::test_AT_CellularStack_constructor()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack *st = new MyStack(at, 0, IPV4_STACK);
delete st;
}
void Test_AT_CellularStack::test_AT_CellularStack_get_ip_address()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
CHECK(0 == strlen(st.get_ip_address()));
char table[] = "1.2.3.4.5.65.7.8.9.10.11\0";
ATHandler_stub::ssize_value = -1;
ATHandler_stub::bool_value = true;
ATHandler_stub::read_string_value = table;
CHECK(NULL == st.get_ip_address());
ATHandler_stub::ssize_value = strlen(table);
ATHandler_stub::bool_value = true;
ATHandler_stub::read_string_value = table;
CHECK(st.get_ip_address());
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_open()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
st.bool_value = false;
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP));
st.bool_value = true;
st.max_sock_value = 0;
nsapi_socket_t sock;
CHECK(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP));
MyStack st2(at, 0, IPV6_STACK);
st2.bool_value = true;
st2.max_sock_value = 1;
nsapi_socket_t sock2;
CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock2, NSAPI_TCP));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_close()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t soc = NULL;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(soc));
st.bool_value = true;
st.max_sock_value = 1;
nsapi_socket_t sock;
CHECK(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP));
st.max_sock_value = 0;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock));
MyStack st2(at, 0, IPV6_STACK);
st2.max_sock_value = 1;
st2.bool_value = true;
nsapi_socket_t sock2;
CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock2, NSAPI_TCP));
CHECK(NSAPI_ERROR_OK == st2.socket_close(sock2));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_bind()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t sock;
SocketAddress addr;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_ALREADY;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr));
CHECK(NSAPI_ERROR_ALREADY == st.socket_bind(sock, addr));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_listen()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t sock;
CHECK(0 == st.socket_listen(sock, 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_connect()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
SocketAddress addr;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr));
nsapi_socket_t sock;
CHECK(NSAPI_ERROR_OK == st.socket_connect(sock, addr));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_accept()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t sock;
CHECK(0 == st.socket_accept(NULL, &sock));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_send()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4));
nsapi_socket_t sock;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(sock, "addr", 4));
SocketAddress addr;
st.max_sock_value = 1;
st.bool_value = true;
st.socket_open(&sock, NSAPI_TCP);
st.socket_connect(sock, addr);
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(sock, "addr", 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t sock;
SocketAddress addr;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4));
st.max_sock_value = 1;
st.bool_value = true;
st.socket_open(&sock, NSAPI_TCP);
st.socket_connect(sock, addr);
st.create_error = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == st.socket_sendto(sock, addr, "addr", 4));
st.create_error = NSAPI_ERROR_OK;
st.max_packet_size = 6;
CHECK(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_recv()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
char table[4];
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
char table[4];
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4));
nsapi_socket_t sock;
SocketAddress addr;
st.max_sock_value = 1;
st.bool_value = true;
st.socket_open(&sock, NSAPI_TCP);
st.socket_connect(sock, addr);
st.create_error = NSAPI_ERROR_CONNECTION_LOST;
CHECK(NSAPI_ERROR_CONNECTION_LOST == st.socket_recvfrom(sock, &addr, table, 4));
st.create_error = NSAPI_ERROR_OK;
st.max_packet_size = 6;
CHECK(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_attach()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
st.socket_attach(NULL, NULL, NULL);
nsapi_socket_t sock;
st.max_sock_value = 1;
st.bool_value = true;
st.socket_open(&sock, NSAPI_TCP);
st.socket_attach(sock, NULL, NULL);
}

View File

@ -0,0 +1,55 @@
/*
* 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.
*/
#ifndef TEST_AT_CELLULARSTACK_H
#define TEST_AT_CELLULARSTACK_H
class Test_AT_CellularStack
{
public:
Test_AT_CellularStack();
virtual ~Test_AT_CellularStack();
void test_AT_CellularStack_constructor();
void test_AT_CellularStack_get_ip_address();
void test_AT_CellularStack_socket_open();
void test_AT_CellularStack_socket_close();
void test_AT_CellularStack_socket_bind();
void test_AT_CellularStack_socket_listen();
void test_AT_CellularStack_socket_connect();
void test_AT_CellularStack_socket_accept();
void test_AT_CellularStack_socket_send();
void test_AT_CellularStack_socket_recv();
void test_AT_CellularStack_socket_sendto();
void test_AT_CellularStack_socket_recvfrom();
void test_AT_CellularStack_socket_attach();
};
#endif // TEST_AT_CELLULARSTACK_H

View File

@ -0,0 +1,27 @@
include ../../makefile_defines.txt
COMPONENT_NAME = ATHandler_unit
#This must be changed manually
SRC_FILES = \
../../../framework/AT/ATHandler.cpp
TEST_SRC_FILES = \
main.cpp \
athandlertest.cpp \
test_athandler.cpp \
../../stubs/AT_CellularBase_stub.cpp \
../../stubs/EventQueue_stub.cpp \
../../stubs/FileHandle_stub.cpp \
../../stubs/CellularUtil_stub.cpp \
../../stubs/us_ticker_stub.cpp \
../../stubs/mbed_wait_api_stub.cpp \
../../stubs/mbed_assert_stub.cpp \
../../stubs/mbed_poll_stub.cpp \
../../stubs/Timer_stub.cpp \
../../stubs/equeue_stub.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,218 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_athandler.h"
TEST_GROUP(ATHandler)
{
Test_ATHandler* unit;
void setup()
{
unit = new Test_ATHandler();
}
void teardown()
{
delete unit;
}
};
TEST(ATHandler, Create)
{
CHECK(unit != NULL);
}
TEST(ATHandler, test_ATHandler_constructor)
{
unit->test_ATHandler_constructor();
}
TEST(ATHandler, test_ATHandler_get_file_handle)
{
unit->test_ATHandler_get_file_handle();
}
TEST(ATHandler, test_ATHandler_set_file_handle)
{
unit->test_ATHandler_set_file_handle();
}
TEST(ATHandler, test_ATHandler_lock)
{
unit->test_ATHandler_lock();
}
TEST(ATHandler, test_ATHandler_unlock)
{
unit->test_ATHandler_unlock();
}
TEST(ATHandler, test_ATHandler_unlock_return_error)
{
unit->test_ATHandler_unlock_return_error();
}
TEST(ATHandler, test_ATHandler_set_urc_handler)
{
unit->test_ATHandler_set_urc_handler();
}
TEST(ATHandler, test_ATHandler_get_last_error)
{
unit->test_ATHandler_get_last_error();
}
TEST(ATHandler, test_ATHandler_get_last_device_error)
{
unit->test_ATHandler_get_last_device_error();
}
TEST(ATHandler, test_ATHandler_inc_ref_count)
{
unit->test_ATHandler_inc_ref_count();
}
TEST(ATHandler, test_ATHandler_dec_ref_count)
{
unit->test_ATHandler_dec_ref_count();
}
TEST(ATHandler, test_ATHandler_get_ref_count)
{
unit->test_ATHandler_get_ref_count();
}
TEST(ATHandler, test_ATHandler_set_at_timeout)
{
unit->test_ATHandler_set_at_timeout();
}
TEST(ATHandler, test_ATHandler_restore_at_timeout)
{
unit->test_ATHandler_restore_at_timeout();
}
TEST(ATHandler, test_ATHandler_clear_error)
{
unit->test_ATHandler_clear_error();
}
TEST(ATHandler, test_ATHandler_process_oob)
{
unit->test_ATHandler_process_oob();
}
TEST(ATHandler, test_ATHandler_set_filehandle_sigio)
{
unit->test_ATHandler_set_filehandle_sigio();
}
TEST(ATHandler, test_ATHandler_flush)
{
unit->test_ATHandler_flush();
}
TEST(ATHandler, test_ATHandler_cmd_start)
{
unit->test_ATHandler_cmd_start();
}
TEST(ATHandler, test_ATHandler_write_int)
{
unit->test_ATHandler_write_int();
}
TEST(ATHandler, test_ATHandler_write_string)
{
unit->test_ATHandler_write_string();
}
TEST(ATHandler, test_ATHandler_cmd_stop)
{
unit->test_ATHandler_cmd_stop();
}
TEST(ATHandler, test_ATHandler_write_bytes)
{
unit->test_ATHandler_write_bytes();
}
TEST(ATHandler, test_ATHandler_set_stop_tag)
{
unit->test_ATHandler_set_stop_tag();
}
TEST(ATHandler, test_ATHandler_set_delimiter)
{
unit->test_ATHandler_set_delimiter();
}
TEST(ATHandler, test_ATHandler_skip_param)
{
unit->test_ATHandler_skip_param();
}
TEST(ATHandler, test_ATHandler_read_bytes)
{
unit->test_ATHandler_read_bytes();
}
TEST(ATHandler, test_ATHandler_read_string)
{
unit->test_ATHandler_read_string();
}
TEST(ATHandler, test_ATHandler_read_int)
{
unit->test_ATHandler_read_int();
}
TEST(ATHandler, test_ATHandler_resp_start)
{
unit->test_ATHandler_resp_start();
}
TEST(ATHandler, test_ATHandler_resp_stop)
{
unit->test_ATHandler_resp_stop();
}
TEST(ATHandler, test_ATHandler_info_resp)
{
unit->test_ATHandler_info_resp();
}
TEST(ATHandler, test_ATHandler_info_elem)
{
unit->test_ATHandler_info_elem();
}
TEST(ATHandler, test_ATHandler_consume_to_stop_tag)
{
unit->test_ATHandler_consume_to_stop_tag();
}
TEST(ATHandler, test_ATHandler_enable_debug)
{
unit->test_ATHandler_enable_debug();
}
TEST(ATHandler, test_ATHandler_get_3gpp_error)
{
unit->test_ATHandler_get_3gpp_error();
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(ATHandler);

View File

@ -0,0 +1,773 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_athandler.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularStack.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "mbed_poll_stub.h"
#include "Timer_stub.h"
using namespace mbed;
using namespace events;
void urc_callback()
{
}
Test_ATHandler::Test_ATHandler()
{
}
Test_ATHandler::~Test_ATHandler()
{
}
void Test_ATHandler::test_ATHandler_constructor()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler *at = new ATHandler(&fh1, que, 0, ",");
delete at;
at = new ATHandler(&fh1, que, 0, NULL);
delete at;
}
void Test_ATHandler::test_ATHandler_get_file_handle()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK_EQUAL(&fh1, at.get_file_handle());
}
void Test_ATHandler::test_ATHandler_set_file_handle()
{
EventQueue que;
FileHandle_stub fh1, fh2;
ATHandler at(&fh1, que, 0, ",");
at.set_file_handle(&fh2);
}
void Test_ATHandler::test_ATHandler_lock()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.lock();
}
void Test_ATHandler::test_ATHandler_unlock()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
filehandle_stub_short_value_counter = 1;
fh1.short_value = POLLIN;
at.unlock();
}
void Test_ATHandler::test_ATHandler_unlock_return_error()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(NSAPI_ERROR_OK == at.unlock_return_error());
}
void Test_ATHandler::test_ATHandler_set_urc_handler()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
const char ch[] = "testtesttesttest";
at.set_urc_handler(ch, &urc_callback);
}
void Test_ATHandler::test_ATHandler_get_last_error()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(NSAPI_ERROR_OK == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_get_last_device_error()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(0 == at.get_last_device_error().errCode);
}
void Test_ATHandler::test_ATHandler_inc_ref_count()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.inc_ref_count();
}
void Test_ATHandler::test_ATHandler_dec_ref_count()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.dec_ref_count();
}
void Test_ATHandler::test_ATHandler_get_ref_count()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(1 == at.get_ref_count());
at.inc_ref_count();
CHECK(2 == at.get_ref_count());
at.inc_ref_count();
CHECK(3 == at.get_ref_count());
at.dec_ref_count();
at.dec_ref_count();
CHECK(1 == at.get_ref_count());
}
void Test_ATHandler::test_ATHandler_set_at_timeout()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.set_at_timeout(8);
at.set_at_timeout(80, true);
}
void Test_ATHandler::test_ATHandler_restore_at_timeout()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.set_at_timeout(80, true);
at.set_at_timeout(800);
at.restore_at_timeout();
}
void Test_ATHandler::test_ATHandler_clear_error()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.clear_error();
}
void Test_ATHandler::test_ATHandler_process_oob()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
filehandle_stub_short_value_counter = 1;
fh1.short_value = POLLIN;
at.set_urc_handler("s", &urc_callback);
at.process_oob();
filehandle_stub_short_value_counter = 2;
at.process_oob();
//at.fill_buffer();
uint8_t buf[5];
at.clear_error();
char table[] = "ssssssssssssssssssssssssssssssss\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
at.read_bytes(buf, 5);
filehandle_stub_short_value_counter = 2;
at.process_oob();
at.clear_error();
timer_stub_value = 0;
filehandle_stub_table_pos = 0;
at.read_bytes(buf, 5);
filehandle_stub_short_value_counter = 1;
at.process_oob();
char table2[4];
table2[0] = '\r';
table2[1] = '\r';
table2[2] = '\n';
table2[3] = 0;
filehandle_stub_table = table2;
at.clear_error();
timer_stub_value = 0;
filehandle_stub_table_pos = 0;
at.read_bytes(buf, 1);
filehandle_stub_short_value_counter = 1;
at.process_oob();
filehandle_stub_table = table;
filehandle_stub_short_value_counter = 0;
filehandle_stub_table_pos = 0;
filehandle_stub_table = NULL;
}
void Test_ATHandler::test_ATHandler_set_filehandle_sigio()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.set_filehandle_sigio();
}
void Test_ATHandler::test_ATHandler_flush()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
filehandle_stub_short_value_counter = 1;
fh1.short_value = POLLIN;
at.flush();
}
void Test_ATHandler::test_ATHandler_cmd_start()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 1;
fh1.size_value = 1;
at.cmd_start("s");
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = 0;
at.cmd_start("s");
at.cmd_start("s");
}
void Test_ATHandler::test_ATHandler_write_int()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.write_int(4);
at.clear_error();
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 1;
fh1.size_value = 1;
at.write_int(4);
at.write_int(2147483647);
at.write_int(2147483647+1);
// at.at_error(0, DeviceErrorType(0));
// at.write_int(4);
}
void Test_ATHandler::test_ATHandler_write_string()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.write_string("help");
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
at.clear_error();
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 1;
fh1.size_value = 1;
at.cmd_start("s");
at.write_string("help", true);
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
at.clear_error();
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 1;
fh1.size_value = 3;
at.write_string("help", true);
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
at.clear_error();
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 1;
fh1.size_value = 7;
at.write_string("help", true);
CHECK(NSAPI_ERROR_OK == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_cmd_stop()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.cmd_stop();
at.write_string("help", true);
at.cmd_stop();
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_write_bytes()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
uint8_t data[] = "data";
at.write_bytes(data, 4);
at.write_bytes(data, 4);
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_set_stop_tag()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.set_stop_tag("s");
}
void Test_ATHandler::test_ATHandler_set_delimiter()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.set_delimiter('+');
}
void Test_ATHandler::test_ATHandler_skip_param()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.skip_param();
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
at.skip_param();
CHECK(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0";
filehandle_stub_table = table1;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
at.skip_param();
char table2[] = "sssOK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
at.skip_param();
char table3[] = "sssssssOK\nssss\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
//Need to create a new instance because stop tag already found
ATHandler at2(&fh1, que, 0, ",");
at2.flush();
at2.clear_error();
at2.resp_start();
at2.skip_param();
at2.skip_param(4, 3);
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at2.flush();
at2.clear_error();
at2.resp_start();
at2.skip_param(4, 3);
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at2.flush();
at2.clear_error();
at2.resp_start();
at2.skip_param(24, 17);
}
void Test_ATHandler::test_ATHandler_read_bytes()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
uint8_t buf[5];
CHECK(-1 == at.read_bytes(buf, 25));
CHECK(-1 == at.read_bytes(buf, 5));
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
at.clear_error();
CHECK(5 == at.read_bytes(buf, 5));
}
void Test_ATHandler::test_ATHandler_read_string()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
char table[] = "\"s,\"OK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
char buf[5];
uint8_t buf2[5];
at.flush();
at.clear_error();
at.resp_start();
at.read_bytes(buf2, 5);
CHECK(-1 == at.read_string(buf, 15));
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
at.read_bytes(buf2, 1);
CHECK(1 == at.read_string(buf, 5, true));
char table2[] = "\"s\"OK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
at.read_bytes(buf2, 1);
CHECK(1 == at.read_string(buf, 5, true));
char table3[] = "sss\rsss\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("s");
at.read_string(buf, 5, true);
char table4[] = "\"s\"\0";
filehandle_stub_table = table4;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("s");
at.read_string(buf, 5, true);
filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0;
}
void Test_ATHandler::test_ATHandler_read_int()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
int32_t ret= at.read_int();
CHECK(-1 == ret);
char table[] = "\",\"OK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
ret= at.read_int();
CHECK(-1 == ret);
char table2[] = "\"2,\"OK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
ret= at.read_int();
CHECK(2 == ret);
}
void Test_ATHandler::test_ATHandler_resp_start()
{
EventQueue que;
FileHandle_stub fh1;
filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0;
ATHandler at(&fh1, que, 0, ",");
at.resp_start();
at.resp_start();
char table2[] = "\"2,\"OK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("ssssaaaassssaaaassss"); //too long prefix
char table3[] = "+CME ERROR: 108\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
char table4[] = "+CMS ERROR: 6\0";
filehandle_stub_table = table4;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
char table5[] = "ERROR\r\n\0";
filehandle_stub_table = table5;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
char table6[] = "OK\r\n\0";
filehandle_stub_table = table6;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
char table7[] = "ssssss\0";
filehandle_stub_table = table7;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.set_urc_handler("ss", NULL);
at.resp_start();
}
void Test_ATHandler::test_ATHandler_resp_stop()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
char table[] = "21 OK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
at.info_elem('2');
at.set_stop_tag("OK\r\n");
at.resp_stop();
char table3[] = "+CME ERROR: 108\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start();
at.resp_stop();
char table7[] = "ssssss\0";
filehandle_stub_table = table7;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("ss", false);
at.resp_stop();
}
void Test_ATHandler::test_ATHandler_info_resp()
{
EventQueue que;
FileHandle_stub fh1;
filehandle_stub_table = NULL;
ATHandler at(&fh1, que, 0, ",");
CHECK(at.info_resp());
at.resp_start();
CHECK(!at.info_resp());
char table2[] = "21 OK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("21");
CHECK(at.info_resp());
CHECK(!at.info_resp());
char table3[] = "21 OK\r\n\0";
filehandle_stub_table = table3;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
CHECK(at.info_resp());
}
void Test_ATHandler::test_ATHandler_info_elem()
{
EventQueue que;
FileHandle_stub fh1;
char table[] = "21 OK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
ATHandler at(&fh1, que, 0, ",");
CHECK(!at.info_elem(char(79)));
char table2[] = "21 OK\r\n\0";
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("21");
CHECK(at.info_elem(char(79)));
CHECK(at.info_elem('2'));
filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start("21");
CHECK(!at.info_elem('2'));
}
void Test_ATHandler::test_ATHandler_consume_to_stop_tag()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(at.consume_to_stop_tag());
}
void Test_ATHandler::test_ATHandler_enable_debug()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
at.enable_debug(true);
at.enable_debug(false);
}
void Test_ATHandler::test_ATHandler_get_3gpp_error()
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
int ret = at.get_3gpp_error();
}

View File

@ -0,0 +1,101 @@
/*
* 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.
*/
#ifndef TEST_ATHANDLER_H
#define TEST_ATHANDLER_H
class Test_ATHandler
{
public:
Test_ATHandler();
virtual ~Test_ATHandler();
void test_ATHandler_constructor();
void test_ATHandler_get_file_handle();
void test_ATHandler_set_file_handle();
void test_ATHandler_lock();
void test_ATHandler_unlock();
void test_ATHandler_unlock_return_error();
void test_ATHandler_set_urc_handler();
void test_ATHandler_get_last_error();
void test_ATHandler_get_last_device_error();
void test_ATHandler_inc_ref_count();
void test_ATHandler_dec_ref_count();
void test_ATHandler_get_ref_count();
void test_ATHandler_set_at_timeout();
void test_ATHandler_restore_at_timeout();
void test_ATHandler_clear_error();
void test_ATHandler_process_oob();
void test_ATHandler_set_filehandle_sigio();
void test_ATHandler_flush();
void test_ATHandler_cmd_start();
void test_ATHandler_write_int();
void test_ATHandler_write_string();
void test_ATHandler_cmd_stop();
void test_ATHandler_write_bytes();
void test_ATHandler_set_stop_tag();
void test_ATHandler_set_delimiter();
void test_ATHandler_skip_param();
void test_ATHandler_read_bytes();
void test_ATHandler_read_string();
void test_ATHandler_read_int();
void test_ATHandler_resp_start();
void test_ATHandler_resp_stop();
void test_ATHandler_info_resp();
void test_ATHandler_info_elem();
void test_ATHandler_consume_to_stop_tag();
void test_ATHandler_enable_debug();
void test_ATHandler_get_3gpp_error();
};
#endif // TEST_ATHANDLER_H

View File

@ -0,0 +1,17 @@
include ../../makefile_defines.txt
COMPONENT_NAME = util_unit
#This must be changed manually
SRC_FILES = \
../../../framework/common/CellularUtil.cpp
TEST_SRC_FILES = \
main.cpp \
utiltest.cpp \
test_util.cpp \
include ../../MakefileWorker.mk
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

View File

@ -0,0 +1,28 @@
/*
* 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.
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}
IMPORT_TEST_GROUP(util);

View File

@ -0,0 +1,177 @@
/*
* 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_util.h"
#include <string.h>
#include "CellularUtil.h"
using namespace mbed_cellular_util;
Test_util::Test_util()
{
}
Test_util::~Test_util()
{
}
void Test_util::test_util_uint_to_binary_string()
{
char str[33];
uint_to_binary_str(15, str, 33, 32);
str[32] = '\0';
// 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111"
STRCMP_EQUAL("00000000000000000000000000001111", str);
// test NULL pointer
uint_to_binary_str(15, NULL, 0, 32);
// test give too small buffer
char too_small[5];
uint_to_binary_str(15, too_small, 5, 6);
}
void Test_util::test_util_char_str_to_hex()
{
// basic conversion test, happy days
char hex_buf[50];
uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
STRCMP_EQUAL("31323334", hex_buf);
LONGS_EQUAL(8, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
STRCMP_EQUAL("7775687575", hex_buf);
LONGS_EQUAL(10, number_of_hex_chars);
// First don't omit the leading zero and then omit and check that leading zero is missing
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
STRCMP_EQUAL("0A7775687575", hex_buf);
LONGS_EQUAL(12, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true);
hex_buf[number_of_hex_chars] = '\0';
STRCMP_EQUAL("A7775687575", hex_buf);
LONGS_EQUAL(11, number_of_hex_chars);
// test giving a null pointer
number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf);
LONGS_EQUAL(0, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL);
LONGS_EQUAL(0, number_of_hex_chars);
}
void Test_util::test_util_convert_ipv6()
{
// leading zeros omitted
char ipv6[64];
strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64);
convert_ipv6(ipv6);
STRCMP_EQUAL("101:101:101:101:101:101:101:101", ipv6);
LONGS_EQUAL(31, strlen(ipv6));
// some omitted and some not so much
strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64);
convert_ipv6(ipv6);
STRCMP_EQUAL("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6);
LONGS_EQUAL(38, strlen(ipv6));
// test giving a null pointer
convert_ipv6(NULL);
}
void Test_util::test_util_prefer_ipv6()
{
char tt[20] = "62.241.198.246";
char temp[64] = "2001:14B8:1000:000:000:000:000:002";
// not enough space to swap, arrays should stay the same
prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp));
STRCMP_EQUAL("62.241.198.246", tt);
STRCMP_EQUAL("2001:14B8:1000:000:000:000:000:002", temp);
// should swap as first one was ip4 and later was ipv6 and enough space
char tt2[64] = "62.241.198.246";
prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp));
STRCMP_EQUAL("62.241.198.246", temp);
STRCMP_EQUAL("2001:14B8:1000:000:000:000:000:002", tt2);
}
void Test_util::test_util_separate_ip_addresses()
{
char* s = (char*)malloc(128);
char ip[64] = {0};
char subnet[64] = {0};
strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
STRCMP_EQUAL("001:203:405:607:809:A0B:C0D:E0F", subnet);
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
STRCMP_EQUAL("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4\0", 8);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("1.2.3.4", ip);
STRCMP_EQUAL("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4.5.6.7.8\0", 16);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("1.2.3.4", ip);
STRCMP_EQUAL("5.6.7.8", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("102:304:506:708:90A:B0C:D0E:F10", ip);
STRCMP_EQUAL("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
STRCMP_EQUAL("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("1.2.3.4", ip);
STRCMP_EQUAL("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
STRCMP_EQUAL("1.2.3.4", ip);
STRCMP_EQUAL("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
STRCMP_EQUAL("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
}

View File

@ -0,0 +1,39 @@
/*
* 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.
*/
#ifndef TEST_UTIL_H
#define TEST_UTIL_H
class Test_util
{
public:
Test_util();
virtual ~Test_util();
void test_util_uint_to_binary_string();
void test_util_char_str_to_hex();
void test_util_convert_ipv6();
void test_util_prefer_ipv6();
void test_util_separate_ip_addresses();
};
#endif // TEST_UTIL_H

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) 2015, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_util.h"
TEST_GROUP(util)
{
Test_util* unit;
void setup()
{
unit = new Test_util();
}
void teardown()
{
delete unit;
}
};
TEST(util, Create)
{
CHECK(unit != NULL);
}
TEST(util, test_util_uint_to_binary_string)
{
unit->test_util_uint_to_binary_string();
}
TEST(util, char_str_to_hex)
{
unit->test_util_char_str_to_hex();
}
TEST(util, convert_ipv6)
{
unit->test_util_convert_ipv6();
}
TEST(util, prefer_ipv6)
{
unit->test_util_prefer_ipv6();
}
TEST(util, separate_ip_addresses)
{
unit->test_util_separate_ip_addresses();
}

View File

@ -0,0 +1,32 @@
#--- Inputs ----#
CPPUTEST_HOME = /usr
CPPUTEST_USE_EXTENSIONS = Y
CPPUTEST_USE_VPATH = Y
CPPUTEST_USE_GCOV = Y
CPPUTEST_USE_MEM_LEAK_DETECTION = N
CPP_PLATFORM = gcc
INCLUDE_DIRS =\
.\
../../stubs\
../../target_h\
../../..\
../../../../../features \
../../../../../features/netsocket \
../../../../.. \
../../../../../rtos \
../../../../../rtos/TARGET_CORTEX \
../../../../../platform \
../../../../../hal \
../../../../../events \
../../../../../events/equeue \
../../../../../drivers \
../../../framework\
../../../framework/common\
../../../framework/AT\
../../../framework/API\
/usr/include\
$(CPPUTEST_HOME)/include\
CPPUTESTFLAGS = -D__thumb2__ -w -D__INLINE=__inline
CPPUTEST_CFLAGS += -std=gnu99

View File

@ -0,0 +1,48 @@
#!/bin/bash
echo
echo Build Cellular unit tests
echo
#replace by empty string if no branch coverage is needed
#branch_cov="--rc lcov_branch_coverage=1"
branch_cov=""
#branch_data="--rc branch-coverage=1"
branch_data="--no-branch-coverage"
# Remember to add new test folder to Makefile
make clean >/dev/null 2>&1
make all
echo
echo Create results
echo
mkdir results
find ./ -name '*.xml' | xargs cp -t ./results/
echo
echo Create coverage document
echo
mkdir coverages
cd coverages
lcov -q -d ../. -c -o app.info $branch_cov
lcov -q -r app.info "/test*" -o app.info $branch_cov
lcov -q -r app.info "/usr*" -o app.info $branch_cov
lcov -q -r app.info "/UNITTESTS/common*" -o app.info $branch_cov
lcov -q -r app.info "/UNITTESTS/*" -o app.info $branch_cov
lcov -q -r app.info "/UNITTESTS/stubs*" -o app.info $branch_cov
lcov -q -r app.info "/UNITTESTS/target_h*" -o app.info $branch_cov
lcov -q -r app.info "/mbed-client*" -o app.info $branch_cov
lcov -q -r app.info "/mbed-os/events*" -o app.info $branch_cov
lcov -q -r app.info "/mbed-os/features/netsocket*" -o app.info $branch_cov
lcov -q -r app.info "/mbed-os/platform*" -o app.info $branch_cov
genhtml $branch_data app.info
cd ..
echo
echo
echo
echo Have a nice bug hunt!
echo
echo
echo

View File

@ -0,0 +1,420 @@
/*
* 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.
*/
#include "ATCmdParser.h"
#include "mbed_poll.h"
#include "mbed_debug.h"
#ifdef LF
#undef LF
#define LF 10
#else
#define LF 10
#endif
#ifdef CR
#undef CR
#define CR 13
#else
#define CR 13
#endif
// getc/putc handling with timeouts
int ATCmdParser::putc(char c)
{
pollfh fhs;
fhs.fh = _fh;
fhs.events = POLLOUT;
int count = poll(&fhs, 1, _timeout);
if (count > 0 && (fhs.revents & POLLOUT)) {
return _fh->write(&c, 1) == 1 ? 0 : -1;
} else {
return -1;
}
}
int ATCmdParser::getc()
{
pollfh fhs;
fhs.fh = _fh;
fhs.events = POLLIN;
int count = poll(&fhs, 1, _timeout);
if (count > 0 && (fhs.revents & POLLIN)) {
unsigned char ch;
return _fh->read(&ch, 1) == 1 ? ch : -1;
} else {
return -1;
}
}
void ATCmdParser::flush()
{
while (_fh->readable()) {
unsigned char ch;
_fh->read(&ch, 1);
}
}
// read/write handling with timeouts
int ATCmdParser::write(const char *data, int size)
{
int i = 0;
for ( ; i < size; i++) {
if (putc(data[i]) < 0) {
return -1;
}
}
return i;
}
int ATCmdParser::read(char *data, int size)
{
int i = 0;
for ( ; i < size; i++) {
int c = getc();
if (c < 0) {
return -1;
}
data[i] = c;
}
return i;
}
// printf/scanf handling
int ATCmdParser::vprintf(const char *format, va_list args)
{
if (vsprintf(_buffer, format, args) < 0) {
return false;
}
int i = 0;
for ( ; _buffer[i]; i++) {
if (putc(_buffer[i]) < 0) {
return -1;
}
}
return i;
}
int ATCmdParser::vscanf(const char *format, va_list args)
{
// Since format is const, we need to copy it into our buffer to
// add the line's null terminator and clobber value-matches with asterisks.
//
// We just use the beginning of the buffer to avoid unnecessary allocations.
int i = 0;
int offset = 0;
while (format[i]) {
if (format[i] == '%' && format[i+1] != '%' && format[i+1] != '*') {
_buffer[offset++] = '%';
_buffer[offset++] = '*';
i++;
} else {
_buffer[offset++] = format[i++];
}
}
// Scanf has very poor support for catching errors
// fortunately, we can abuse the %n specifier to determine
// if the entire string was matched.
_buffer[offset++] = '%';
_buffer[offset++] = 'n';
_buffer[offset++] = 0;
// To workaround scanf's lack of error reporting, we actually
// make two passes. One checks the validity with the modified
// format string that only stores the matched characters (%n).
// The other reads in the actual matched values.
//
// We keep trying the match until we succeed or some other error
// derails us.
int j = 0;
while (true) {
// Ran out of space
if (j+1 >= _buffer_size - offset) {
return false;
}
// Recieve next character
int c = getc();
if (c < 0) {
return -1;
}
_buffer[offset + j++] = c;
_buffer[offset + j] = 0;
// Check for match
int count = -1;
sscanf(_buffer+offset, _buffer, &count);
// We only succeed if all characters in the response are matched
if (count == j) {
// Store the found results
vsscanf(_buffer+offset, format, args);
return j;
}
}
}
// Command parsing with line handling
bool ATCmdParser::vsend(const char *command, va_list args)
{
// Create and send command
if (vsprintf(_buffer, command, args) < 0) {
return false;
}
for (int i = 0; _buffer[i]; i++) {
if (putc(_buffer[i]) < 0) {
return false;
}
}
// Finish with newline
for (size_t i = 0; _output_delimiter[i]; i++) {
if (putc(_output_delimiter[i]) < 0) {
return false;
}
}
debug_if(_dbg_on, "AT> %s\n", _buffer);
return true;
}
bool ATCmdParser::vrecv(const char *response, va_list args)
{
restart:
_aborted = false;
// Iterate through each line in the expected response
while (response[0]) {
// Since response is const, we need to copy it into our buffer to
// add the line's null terminator and clobber value-matches with asterisks.
//
// We just use the beginning of the buffer to avoid unnecessary allocations.
int i = 0;
int offset = 0;
bool whole_line_wanted = false;
while (response[i]) {
if (response[i] == '%' && response[i+1] != '%' && response[i+1] != '*') {
_buffer[offset++] = '%';
_buffer[offset++] = '*';
i++;
} else {
_buffer[offset++] = response[i++];
// Find linebreaks, taking care not to be fooled if they're in a %[^\n] conversion specification
if (response[i - 1] == '\n' && !(i >= 3 && response[i-3] == '[' && response[i-2] == '^')) {
whole_line_wanted = true;
break;
}
}
}
// Scanf has very poor support for catching errors
// fortunately, we can abuse the %n specifier to determine
// if the entire string was matched.
_buffer[offset++] = '%';
_buffer[offset++] = 'n';
_buffer[offset++] = 0;
debug_if(_dbg_on, "AT? %s\n", _buffer);
// To workaround scanf's lack of error reporting, we actually
// make two passes. One checks the validity with the modified
// format string that only stores the matched characters (%n).
// The other reads in the actual matched values.
//
// We keep trying the match until we succeed or some other error
// derails us.
int j = 0;
while (true) {
// Receive next character
int c = getc();
if (c < 0) {
debug_if(_dbg_on, "AT(Timeout)\n");
return false;
}
// Simplify newlines (borrowed from retarget.cpp)
if ((c == CR && _in_prev != LF) ||
(c == LF && _in_prev != CR)) {
_in_prev = c;
c = '\n';
} else if ((c == CR && _in_prev == LF) ||
(c == LF && _in_prev == CR)) {
_in_prev = c;
// onto next character
continue;
} else {
_in_prev = c;
}
_buffer[offset + j++] = c;
_buffer[offset + j] = 0;
// Check for oob data
for (struct oob *oob = _oobs; oob; oob = oob->next) {
if ((unsigned)j == oob->len && memcmp(
oob->prefix, _buffer+offset, oob->len) == 0) {
debug_if(_dbg_on, "AT! %s\n", oob->prefix);
oob->cb();
if (_aborted) {
debug_if(_dbg_on, "AT(Aborted)\n");
return false;
}
// oob may have corrupted non-reentrant buffer,
// so we need to set it up again
goto restart;
}
}
// Check for match
int count = -1;
if (whole_line_wanted && c != '\n') {
// Don't attempt scanning until we get delimiter if they included it in format
// This allows recv("Foo: %s\n") to work, and not match with just the first character of a string
// (scanf does not itself match whitespace in its format string, so \n is not significant to it)
} else {
sscanf(_buffer+offset, _buffer, &count);
}
// We only succeed if all characters in the response are matched
if (count == j) {
debug_if(_dbg_on, "AT= %s\n", _buffer+offset);
// Reuse the front end of the buffer
memcpy(_buffer, response, i);
_buffer[i] = 0;
// Store the found results
vsscanf(_buffer+offset, _buffer, args);
// Jump to next line and continue parsing
response += i;
break;
}
// Clear the buffer when we hit a newline or ran out of space
// running out of space usually means we ran into binary data
if (c == '\n' || j+1 >= _buffer_size - offset) {
debug_if(_dbg_on, "AT< %s", _buffer+offset);
j = 0;
}
}
}
return true;
}
// Mapping to vararg functions
int ATCmdParser::printf(const char *format, ...)
{
va_list args;
va_start(args, format);
int res = vprintf(format, args);
va_end(args);
return res;
}
int ATCmdParser::scanf(const char *format, ...)
{
va_list args;
va_start(args, format);
int res = vscanf(format, args);
va_end(args);
return res;
}
bool ATCmdParser::send(const char *command, ...)
{
va_list args;
va_start(args, command);
bool res = vsend(command, args);
va_end(args);
return res;
}
bool ATCmdParser::recv(const char *response, ...)
{
va_list args;
va_start(args, response);
bool res = vrecv(response, args);
va_end(args);
return res;
}
// oob registration
void ATCmdParser::oob(const char *prefix, Callback<void()> cb)
{
struct oob *oob = new struct oob;
oob->len = strlen(prefix);
oob->prefix = prefix;
oob->cb = cb;
oob->next = _oobs;
_oobs = oob;
}
void ATCmdParser::abort()
{
_aborted = true;
}
bool ATCmdParser::process_oob()
{
if (!_fh->readable()) {
return false;
}
int i = 0;
while (true) {
// Receive next character
int c = getc();
if (c < 0) {
return false;
}
_buffer[i++] = c;
_buffer[i] = 0;
// Check for oob data
struct oob *oob = _oobs;
while (oob) {
if (i == (int)oob->len && memcmp(
oob->prefix, _buffer, oob->len) == 0) {
debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
oob->cb();
return true;
}
oob = oob->next;
}
// Clear the buffer when we hit a newline or ran out of space
// running out of space usually means we ran into binary data
if (i+1 >= _buffer_size ||
strcmp(&_buffer[i-_output_delim_size], _output_delimiter) == 0) {
debug_if(_dbg_on, "AT< %s", _buffer);
i = 0;
}
}
}

View File

@ -0,0 +1,227 @@
/*
* 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.
*/
#include <ctype.h>
#include "nsapi_types.h"
#include "ATHandler.h"
#include "EventQueue.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
#include "CellularLog.h"
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;
ssize_t ATHandler_stub::ssize_value = 0;
char* ATHandler_stub::read_string_value = NULL;
size_t ATHandler_stub::size_value = 0;
size_t ATHandler_stub::return_given_size = false;
bool ATHandler_stub::bool_value = false;
uint8_t ATHandler_stub::uint8_value = 0;
FileHandle_stub *ATHandler_stub::fh_value = NULL;
device_err_t ATHandler_stub::device_err_value;
Callback<void()> ATHandler_stub::callback = NULL;
uint8_t ATHandler_stub::resp_info_true_counter = false;
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter) :
_nextATHandler(0),
_fileHandle(fh),
_queue(queue)
{
}
void ATHandler::enable_debug(bool enable)
{
}
ATHandler::~ATHandler()
{
}
void ATHandler::inc_ref_count()
{
}
void ATHandler::dec_ref_count()
{
}
int ATHandler::get_ref_count()
{
return ATHandler_stub::int_value;
}
FileHandle *ATHandler::get_file_handle()
{
return ATHandler_stub::fh_value;
}
void ATHandler::set_file_handle(FileHandle *fh)
{
}
void ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
{
ATHandler_stub::callback = cb;
}
nsapi_error_t ATHandler::get_last_error() const
{
if (ATHandler_stub::nsapi_error_ok_counter) {
ATHandler_stub::nsapi_error_ok_counter--;
return NSAPI_ERROR_OK;
}
return ATHandler_stub::nsapi_error_value;
}
void ATHandler::lock()
{
}
void ATHandler::unlock()
{
}
nsapi_error_t ATHandler::unlock_return_error()
{
return ATHandler_stub::nsapi_error_value;
}
void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout)
{
}
void ATHandler::restore_at_timeout()
{
}
void ATHandler::process_oob()
{
}
void ATHandler::clear_error()
{
}
void ATHandler::skip_param(uint32_t count) {
}
void ATHandler::skip_param(ssize_t len, uint32_t count)
{
}
ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
{
return ATHandler_stub::ssize_value;
}
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
{
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value);
}
return ATHandler_stub::ssize_value;
}
int ATHandler::read_int()
{
return ATHandler_stub::int_value;
}
void ATHandler::set_delimiter(char delimiter)
{
}
void ATHandler::set_default_delimiter()
{
}
void ATHandler::set_stop_tag(const char *stop_tag_seq)
{
}
int ATHandler::get_3gpp_error()
{
return ATHandler_stub::int_value;
}
void ATHandler::resp_start(const char *prefix, bool stop)
{
}
bool ATHandler::info_resp()
{
if (ATHandler_stub::resp_info_true_counter) {
ATHandler_stub::resp_info_true_counter--;
return true;
}
return ATHandler_stub::bool_value;
}
bool ATHandler::info_elem(char start_tag)
{
return ATHandler_stub::bool_value;
}
bool ATHandler::consume_to_stop_tag()
{
return ATHandler_stub::bool_value;
}
void ATHandler::resp_stop()
{
}
void ATHandler::cmd_start(const char* cmd)
{
}
void ATHandler::write_int(int param)
{
}
void ATHandler::write_string(const char* param, bool useQuotations)
{
}
size_t ATHandler::write_bytes(const uint8_t* param, size_t len)
{
if (ATHandler_stub::return_given_size) {
return len;
}
return ATHandler_stub::size_value;
}
void ATHandler::cmd_stop()
{
}
device_err_t ATHandler::get_last_device_error() const
{
return ATHandler_stub::device_err_value;
}
void ATHandler::flush()
{
}

View File

@ -0,0 +1,41 @@
/*
* 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.
*/
#include "stdint.h"
#include "stdbool.h"
#include <cstddef>
#include "nsapi_types.h"
#include "ATHandler.h"
#include "FileHandle_stub.h"
#include "Callback.h"
namespace ATHandler_stub {
extern nsapi_error_t nsapi_error_value;
extern uint8_t nsapi_error_ok_counter;
extern int int_value;
extern ssize_t ssize_value;
extern char* read_string_value;
extern size_t size_value;
extern size_t return_given_size;
extern bool bool_value;
extern uint8_t resp_info_true_counter;
extern uint8_t uint8_value;
extern mbed::FileHandle_stub *fh_value;
extern mbed::device_err_t device_err_value;
extern mbed::Callback<void()> callback;
}

View File

@ -0,0 +1,43 @@
/*
* 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.
*/
#include "nsapi_types.h"
#include "AT_CellularBase.h"
#include "AT_CellularBase_stub.h"
using namespace mbed;
ATHandler *AT_CellularBase_stub::handler_value = NULL;
ATHandler *AT_CellularBase_stub::handler_at_constructor_value = NULL;
device_err_t AT_CellularBase_stub::device_err_value;
AT_CellularBase::AT_CellularBase(ATHandler& at) : _at(at)
{
AT_CellularBase_stub::handler_at_constructor_value = &_at;
}
ATHandler& AT_CellularBase::get_at_handler()
{
return *AT_CellularBase_stub::handler_value;
}
device_err_t AT_CellularBase::get_device_error() const
{
return AT_CellularBase_stub::device_err_value;
}

View File

@ -0,0 +1,24 @@
/*
* 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.
*/
#include "ATHandler.h"
namespace AT_CellularBase_stub {
extern mbed::ATHandler *handler_value;
extern mbed::ATHandler *handler_at_constructor_value;
extern mbed::device_err_t device_err_value;
}

View File

@ -0,0 +1,91 @@
/*
* 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.
*/
#include "AT_CellularDevice.h"
AT_CellularDevice::AT_CellularDevice(EventQueue &queue) :
_atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _multiplexer(0), _information(0), _queue(queue)
{
}
AT_CellularDevice::~AT_CellularDevice()
{
}
ATHandler* AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
{
return NULL;
}
void AT_CellularDevice::release_at_handler(ATHandler* at_handler)
{
}
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
{
return NULL;
}
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
{
return NULL;
}
CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh)
{
return NULL;
}
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
{
return NULL;
}
CellularMultiplexer *AT_CellularDevice::open_multiplexer(FileHandle *fh)
{
return NULL;
}
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
{
return NULL;
}
void AT_CellularDevice::close_network()
{
}
void AT_CellularDevice::close_sms()
{
}
void AT_CellularDevice::close_power()
{
}
void AT_CellularDevice::close_sim()
{
}
void AT_CellularDevice::close_multiplexer()
{
}
void AT_CellularDevice::close_information()
{
}

View File

@ -0,0 +1,44 @@
/*
* 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.
*/
#include "AT_CellularInformation.h"
#include "nsapi_types.h"
using namespace mbed;
AT_CellularInformation::AT_CellularInformation(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularInformation::~AT_CellularInformation()
{
}
nsapi_error_t AT_CellularInformation::get_manufacturer(char *buf, size_t buf_size)
{
return 0;
}
nsapi_error_t AT_CellularInformation::get_model(char *buf, size_t buf_size)
{
return 0;
}
nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size)
{
return 0;
}

View File

@ -0,0 +1,35 @@
/*
* 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.
*/
#include "AT_CellularMultiplexer.h"
#include "CellularLog.h"
#include "nsapi_types.h"
using namespace mbed;
AT_CellularMultiplexer::AT_CellularMultiplexer(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularMultiplexer::~AT_CellularMultiplexer()
{
}
nsapi_error_t AT_CellularMultiplexer::multiplexer_mode_start()
{
return 0;
}

View File

@ -0,0 +1,233 @@
/*
* 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.
*/
#include "AT_CellularNetwork.h"
#include "CellularNetwork.h"
#include "CellularUtil.h"
#include "CellularLog.h"
#include "FileHandle.h"
#include "nsapi_types.h"
using namespace mbed;
using namespace mbed_cellular_util;
AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler)
{
}
AT_CellularNetwork::~AT_CellularNetwork()
{
}
nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
const char *username, const char *password)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
AuthenticationType type, const char *username, const char *password)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::connect(const char *apn,
const char *username, const char *password)
{
return connect();
}
nsapi_error_t AT_CellularNetwork::connect()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::open_data_channel()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::disconnect()
{
return NSAPI_ERROR_OK;
}
void AT_CellularNetwork::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
}
nsapi_connection_status_t AT_CellularNetwork::get_connection_status() const
{
return NSAPI_STATUS_LOCAL_UP;
}
nsapi_error_t AT_CellularNetwork::set_blocking(bool blocking)
{
return NSAPI_ERROR_OK;;
}
nsapi_error_t AT_CellularNetwork::set_context_to_be_activated()
{
return NSAPI_ERROR_OK;
}
//bool AT_CellularNetwork::set_new_context(nsapi_ip_stack_t stack, int cid)
//{
// return false;
//}
//bool AT_CellularNetwork::get_context(nsapi_ip_stack_t requested_stack)
//{
// return false;
//}
nsapi_ip_stack_t AT_CellularNetwork::string_to_stack_type(const char* pdp_type)
{
return IPV4_STACK;
}
nsapi_error_t AT_CellularNetwork::set_registration_urc(bool urc_on)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type, RegistrationStatus &status)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_cell_id(int &cell_id)
{
return NSAPI_ERROR_OK;
}
bool AT_CellularNetwork::has_registration(RegistrationType reg_type)
{
return false;
}
nsapi_error_t AT_CellularNetwork::set_attach(int timeout)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoffTime)
{
return NSAPI_ERROR_OK;
}
NetworkStack *AT_CellularNetwork::get_stack()
{
return NULL;
}
const char *AT_CellularNetwork::get_ip_address()
{
return NULL;
}
nsapi_error_t AT_CellularNetwork::set_stack_type(nsapi_ip_stack_t stack_type)
{
return NSAPI_ERROR_OK;
}
nsapi_ip_stack_t AT_CellularNetwork::get_stack_type()
{
return IPV4_STACK;
}
bool AT_CellularNetwork::get_modem_stack_type(nsapi_ip_stack_t requested_stack)
{
return false;
}
void AT_CellularNetwork::urc_no_carrier()
{
}
nsapi_error_t AT_CellularNetwork::set_access_technology_impl(operator_t::RadioAccessTechnology opsAct)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_access_technology(operator_t::RadioAccessTechnology opAct)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt supported_opt,
Preferred_UE_Opt preferred_opt)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt& supported_opt,
Preferred_UE_Opt& preferred_opt)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_rate_control(
CellularNetwork::RateControlExceptionReports &reports,
CellularNetwork::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_pdpcontext_params(pdpContextList_t& params_list)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_operator_params(int &format, operator_t &operator_params)
{
return NSAPI_ERROR_OK;
}
int AT_CellularNetwork::get_3gpp_error()
{
return 0;
}

View File

@ -0,0 +1,66 @@
/*
* 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.
*/
#include "AT_CellularPower.h"
#include "CellularUtil.h"
#include "CellularLog.h"
using namespace mbed_cellular_util;
using namespace mbed;
AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularPower::~AT_CellularPower()
{
}
nsapi_error_t AT_CellularPower::on()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::off()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::set_at_mode()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::set_power_level(int func_level)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::reset()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int active_time)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value)
{
return NSAPI_ERROR_OK;
}

View File

@ -0,0 +1,54 @@
/*
* 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.
*/
#include "AT_CellularSIM.h"
#include "CellularLog.h"
using namespace mbed;
AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularSIM::~AT_CellularSIM()
{
}
nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::get_imsi(char* imsi)
{
return NSAPI_ERROR_OK;
}

View File

@ -0,0 +1,190 @@
/*
* 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.
*/
#include <time.h>
#include "AT_CellularSMS.h"
#include "CellularLog.h"
using namespace mbed;
#define CTRL_Z "\x1a"
#define ESC "\x1b"
const int SMS_STATUS_SIZE = 12 + 1;
const int FIRST_OCTET_DELIVER_SUBMIT = 17;
const int TP_VALIDITY_PERIOD_24_HOURS = 167;
const int TP_PROTOCOL_IDENTIFIER = 0;
const int SMS_DATA_CODING_SCHEME = 0;
const uint16_t SMS_MAX_8BIT_CONCATENATED_SINGLE_SMS_SIZE = 134;
const uint16_t SMS_MAX_GSM7_CONCATENATED_SINGLE_SMS_SIZE = 153;
AT_CellularSMS::AT_CellularSMS(ATHandler &at) : AT_CellularBase(at), _cb(0), _mode(CellularSMSMmodeText),
_use_8bit_encoding(false), _sim_wait_time(0), _sms_message_ref_number(1), _sms_info(NULL)
{
}
AT_CellularSMS::~AT_CellularSMS()
{
}
void AT_CellularSMS::cmt_urc()
{
}
void AT_CellularSMS::cmti_urc()
{
}
nsapi_error_t AT_CellularSMS::set_cnmi()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
{
return NSAPI_ERROR_OK;
}
void AT_CellularSMS::set_extra_sim_wait_time(int sim_wait_time)
{
}
char* AT_CellularSMS::create_pdu(const char* phone_number, const char* message, uint8_t message_length, uint8_t msg_parts,
uint8_t msg_part_number, uint8_t& header_size)
{
return NULL;
}
nsapi_size_or_error_t AT_CellularSMS::send_sms(const char* phone_number, const char* message, int msg_len)
{
return NSAPI_ERROR_OK;
}
void AT_CellularSMS::set_sms_callback(Callback<void()> func)
{
}
nsapi_error_t AT_CellularSMS::set_cpms(const char *memr, const char *memw, const char *mems)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_csca(const char *sca, int type)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::set_cscs(const char *chr_set)
{
return NSAPI_ERROR_OK;
}
//nsapi_error_t AT_CellularSMS::set_csms(int msg_service)
//{
// return NSAPI_ERROR_OK;
//}
nsapi_error_t AT_CellularSMS::delete_sms(sms_info_t* sms)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::delete_all_messages()
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char* buf, uint16_t len, char* phone_num, char* time_stamp)
{
return NSAPI_ERROR_OK;
}
// read msg in PDU mode
nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t* sms, char* buf, char* phone_num, char* time_stamp)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::get_sms(char* buf, uint16_t len, char* phone_num, uint16_t phone_len,
char* time_stamp, uint16_t time_len, int *buf_size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::get_data_from_pdu(const char* pdu, sms_info_t *info, int *part_number, char *phone_number, char *msg)
{
return NSAPI_ERROR_OK;
}
// read params from User DEfined Header
int AT_CellularSMS::read_udh_from_pdu(const char* pdu, sms_info_t *info, int &part_number, int &padding_bits)
{
return 0;
}
nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload(const char* pdu, int msg_len, int scheme, char *msg, int padding_bits)
{
return NSAPI_ERROR_OK;
}
void AT_CellularSMS::free_linked_list()
{
}
void AT_CellularSMS::add_info(sms_info_t* info, int index, int part_number)
{
}
// reads all the messages to the linked list AT_CellularSMS::_sms_info
nsapi_error_t AT_CellularSMS::list_messages()
{
return NSAPI_ERROR_OK;
}
AT_CellularSMS::sms_info_t* AT_CellularSMS::get_oldest_sms_index()
{
return NULL;
}
// if time_string_1 is greater (more fresh date) then return 1, same 0, smaller -1. Error -2
int AT_CellularSMS::compare_time_strings(const char* time_string_1, const char* time_string_2)
{
return 0;
}
bool AT_CellularSMS::create_time(const char* time_string, time_t* time)
{
return 0;
}

View File

@ -0,0 +1,90 @@
/*
* 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.
*/
#include "AT_CellularStack.h"
#include "CellularUtil.h"
#include "CellularLog.h"
using namespace mbed_cellular_util;
AT_CellularStack::AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : _at(atHandler), _socket(NULL), _cid(cid), _stack_type(stack_type)
{
}
AT_CellularStack::~AT_CellularStack()
{
}
const char *AT_CellularStack::get_ip_address()
{
return NULL;
}
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_close(nsapi_socket_t handle)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_bind(nsapi_socket_t handle, const SocketAddress &addr)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_send(nsapi_socket_t handle, const void *data, unsigned size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &addr, const void *data, unsigned size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_recv(nsapi_socket_t handle, void *data, unsigned size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_recvfrom(nsapi_socket_t handle, SocketAddress *addr, void *buffer, unsigned size)
{
return NSAPI_ERROR_OK;
}
void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data)
{
}

View File

@ -0,0 +1,113 @@
/*
* Copyright (c) , 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.
*/
#include "CellularUtil.h"
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
namespace mbed_cellular_util {
#define MAX_STRING_LEN 200
void str_copy_skip_char(char *dest, uint16_t dest_size, const char *src, char c)
{
}
void str_remove_char(char *src, char c)
{
}
void uint_to_binary_str(uint32_t num, char* str, uint8_t str_size, uint8_t bit_cnt)
{
}
// converts the given str to hex string to buf
uint16_t char_str_to_hex(const char* str, uint16_t len, char *buf, bool omit_leading_zero)
{
return 0;
}
void convert_ipv6(char* ip)
{
}
char* find_dot_number(char* str, int dot_number)
{
return NULL;
}
void separate_ip4like_addresses(char* orig, char* ip, size_t ip_size, char* ip2, size_t ip2_size)
{
}
void separate_ip_addresses(char* orig, char* ip, size_t ip_size, char* ip2, size_t ip2_size)
{
}
void prefer_ipv6(char* ip, size_t ip_size, char* ip2, size_t ip2_size)
{
}
void int_to_hex_str(uint8_t num, char* buf)
{
buf[0] = '0';
buf[1] = '2';
}
int hex_str_to_int(const char *hex_string, int hex_string_length)
{
return 0;
}
int hex_str_to_char_str(const char* str, uint16_t len, char *buf)
{
return 0;
}
void uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt)
{
}
int char_str_to_hex_str(const char* str, uint16_t len, char *buf, bool omit_leading_zero)
{
//The code is dependent on this, so this is easiest just to put here
if (!str || !buf) {
return 0;
}
char *ptr = buf;
int i=0;
while (i < len) {
if (omit_leading_zero == true && i == 0 && !(str[i]>>4 & 0x0F)) {
*ptr++ = hex_values[(str[i]) & 0x0F];
} else {
*ptr++ = hex_values[((str[i])>>4) & 0x0F];
*ptr++ = hex_values[(str[i]) & 0x0F];
}
i++;
}
return ptr-buf;
}
uint16_t get_dynamic_ip_port()
{
return 0;
}
} // namespace mbed_cellular_util

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) , 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.
*/
#include "EventQueue.h"
#include "Callback.h"
using namespace mbed;
namespace events {
EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer) {
}
EventQueue::~EventQueue() {
}
void EventQueue::dispatch(int ms) {
}
void EventQueue::break_dispatch() {
}
unsigned EventQueue::tick() {
return 0;
}
void EventQueue::cancel(int id) {
}
void EventQueue::background(Callback<void(int)> update) {
}
void EventQueue::chain(EventQueue *target) {
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) , 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.
*/
#include "FileHandle_stub.h"
namespace mbed {
off_t FileHandle::size()
{
return 0;
}
std::FILE *fdopen(FileHandle *fh, const char *mode)
{
return NULL;
}
}

View File

@ -0,0 +1,78 @@
/*
* Copyright (c) , 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 __FILE_HANDLE_STUB_H__
#define __FILE_HANDLE_STUB_H__
#include "FileHandle.h"
namespace mbed {
static uint8_t filehandle_stub_short_value_counter = 0;
static char *filehandle_stub_table = NULL;
static uint8_t filehandle_stub_table_pos = 0;
class FileHandle_stub : public FileHandle
{
public:
size_t size_value;
FileHandle_stub() {size_value = 0;}
virtual ssize_t read(void *buffer, size_t size){
if (filehandle_stub_table) {
ssize_t ret = strlen(filehandle_stub_table) - filehandle_stub_table_pos;
if (size < ret) {
ret = size;
}
memcpy(buffer, filehandle_stub_table, ret);
filehandle_stub_table_pos += ret;
return ret;
}
return 0;
}
virtual ssize_t write(const void *buffer, size_t size){
if( size_value ) {
size_value--;
return size;
}
return 0;
}
virtual off_t seek(off_t offset, int whence = SEEK_SET){return 0;}
virtual int close(){}
virtual short poll(short events) const{
if (filehandle_stub_short_value_counter) {
filehandle_stub_short_value_counter--;
return short_value;
}
return 0;
}
virtual void sigio(Callback<void()> func){func();}
short short_value;
};
}
#endif

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2015, 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.
*/
#include "netsocket/NetworkInterface.h"
#include "netsocket/NetworkStack.h"
#include <string.h>
// Default network-interface state
const char *NetworkInterface::get_mac_address()
{
return 0;
}
const char *NetworkInterface::get_ip_address()
{
return 0;
}
const char *NetworkInterface::get_netmask()
{
return 0;
}
const char *NetworkInterface::get_gateway()
{
return 0;
}
nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::set_dhcp(bool dhcp)
{
return NSAPI_ERROR_UNSUPPORTED;
}
// DNS operations go through the underlying stack by default
nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address)
{
return NSAPI_ERROR_UNSUPPORTED;
}
void NetworkInterface::attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
}
nsapi_connection_status_t NetworkInterface::get_connection_status() const
{
return NSAPI_STATUS_LOCAL_UP;
}
nsapi_error_t NetworkInterface::set_blocking(bool blocking)
{
return NSAPI_ERROR_UNSUPPORTED;
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2015, 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.
*/
#include "NetworkStack.h"
#include "nsapi_dns.h"
#include "mbed.h"
#include "stddef.h"
#include <new>
// Default NetworkStack operations
nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
// Conversion function for network stacks
NetworkStack *nsapi_create_stack(nsapi_stack_t *stack)
{
return NULL;
}
NetworkStack *nsapi_create_stack(NetworkStack *stack)
{
return NULL;
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) , 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.
*/
#include "Semaphore.h"
namespace rtos {
Semaphore::Semaphore(int32_t count)
{
}
Semaphore::Semaphore(int32_t count, uint16_t max_count)
{
}
void Semaphore::constructor(int32_t count, uint16_t max_count)
{
}
int32_t Semaphore::wait(uint32_t millisec)
{
return 0;
}
int32_t Semaphore::wait_until(uint64_t millisec)
{
return 0;
}
osStatus Semaphore::release(void)
{
return 0;
}
Semaphore::~Semaphore()
{
}
}

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2015, 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.
*/
#include "SocketAddress.h"
#include "NetworkInterface.h"
#include "NetworkStack.h"
#include <string.h>
#include "mbed.h"
static bool ipv4_is_valid(const char *addr)
{
return false;
}
static bool ipv6_is_valid(const char *addr)
{
return false;
}
static void ipv4_from_address(uint8_t *bytes, const char *addr)
{
}
static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk)
{
return 0;
}
static void ipv6_from_address(uint8_t *bytes, const char *addr)
{
}
static void ipv4_to_address(char *addr, const uint8_t *bytes)
{
}
static void ipv6_to_address(char *addr, const uint8_t *bytes)
{
}
SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port)
{
}
SocketAddress::SocketAddress(const char *addr, uint16_t port)
{
}
SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port)
{
}
SocketAddress::SocketAddress(const SocketAddress &addr)
{
}
bool SocketAddress::set_ip_address(const char *addr)
{
return false;
}
void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
{
}
void SocketAddress::set_addr(nsapi_addr_t addr)
{
}
void SocketAddress::set_port(uint16_t port)
{
}
const char *SocketAddress::get_ip_address() const
{
return NULL;
}
const void *SocketAddress::get_ip_bytes() const
{
return NULL;
}
nsapi_version_t SocketAddress::get_ip_version() const
{
nsapi_version_t ver;
return ver;
}
nsapi_addr_t SocketAddress::get_addr() const
{
nsapi_addr_t addr;
return _addr;
}
uint16_t SocketAddress::get_port() const
{
return 0;
}
SocketAddress::operator bool() const
{
return false;
}
bool operator==(const SocketAddress &a, const SocketAddress &b)
{
return false;
}
bool operator!=(const SocketAddress &a, const SocketAddress &b)
{
return false;
}

View File

@ -0,0 +1,63 @@
/*
* Copyright (c) , 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.
*/
#include "Timer.h"
#include "Timer_stub.h"
namespace mbed {
Timer::Timer() {
}
Timer::Timer(const ticker_data_t *data) {
}
Timer::~Timer() {
}
void Timer::start() {
}
void Timer::stop() {;
}
int Timer::read_us() {
return 0;
}
float Timer::read() {
return 0;
}
int Timer::read_ms() {
timer_stub_value += timer_stub_step;
return timer_stub_value;
}
us_timestamp_t Timer::read_high_resolution_us() {
return 0;
}
void Timer::reset()
{
}
Timer::operator float() {
return 0;
}
} // namespace mbed

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) , 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 TIMER_STUB_H
#define TIMER_STUB_H
static uint16_t timer_stub_value = 0;
static uint16_t timer_stub_step = 20;
#endif

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) , 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.
*/
#include "equeue.h"
int equeue_create(equeue_t *queue, size_t size)
{
return 0;
}
int equeue_create_inplace(equeue_t *queue, size_t size, void *buffer)
{
return 0;
}
void equeue_destroy(equeue_t *queue)
{
}
void equeue_dispatch(equeue_t *queue, int ms)
{
}
void equeue_break(equeue_t *queue)
{
}
int equeue_call(equeue_t *queue, void (*cb)(void *), void *data)
{
return 0;
}
int equeue_call_in(equeue_t *queue, int ms, void (*cb)(void *), void *data)
{
return 0;
}
int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data)
{
return 0;
}
void *equeue_alloc(equeue_t *queue, size_t size)
{
return NULL;
}
void equeue_dealloc(equeue_t *queue, void *event)
{
}
void equeue_event_delay(void *event, int ms)
{
}
void equeue_event_period(void *event, int ms)
{
}
void equeue_event_dtor(void *event, void (*dtor)(void *))
{
}
int equeue_post(equeue_t *queue, void (*cb)(void *), void *event)
{
return 0;
}
void equeue_cancel(equeue_t *queue, int id)
{
}
void equeue_background(equeue_t *queue,
void (*update)(void *timer, int ms), void *timer)
{
}
void equeue_chain(equeue_t *queue, equeue_t *target)
{
}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) , 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.
*/
#include "mbed_assert.h"
void mbed_assert_internal(const char *expr, const char *file, int line)
{
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) , 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.
*/
#include "mbed_poll.h"
#include "mbed_poll_stub.h"
int mbed_poll_stub::revents_value = POLLOUT;
int mbed_poll_stub::int_value = 0;
namespace mbed {
int poll(pollfh fhs[], unsigned nfhs, int timeout)
{
fhs->revents = mbed_poll_stub::revents_value;
return mbed_poll_stub::int_value;
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) , 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_POLL_STUB_H__
#define __MBED_POLL_STUB_H__
#include <stdint.h>
namespace mbed_poll_stub {
extern int revents_value;
extern int int_value;
}
#endif

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) , 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.
*/
#include "mbed_wait_api.h"
void wait(float s) {
}
void wait_ms(int ms) {
}
void wait_us(int us) {
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) , 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.
*/
#include "stdlib.h"
#include "us_ticker_api.h"
const ticker_data_t* get_us_ticker_data(void)
{
return NULL;
}
void us_ticker_irq_handler(void)
{
}
void us_ticker_init(void)
{
}
uint32_t us_ticker_read(void)
{
return 0;
}
void us_ticker_set_interrupt(timestamp_t timestamp)
{
}
void us_ticker_disable_interrupt(void)
{
}
void us_ticker_clear_interrupt(void)
{
}
void us_ticker_fire_interrupt(void)
{
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) , 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 __AT_CMD_PARSER_H__
#define __AT_CMD_PARSER_H__
#include "mbed.h"
#include <cstdarg>
#include "FileHandle.h"
class ATCmdParser
{
public:
ATCmdParser(mbed::FileHandle *fh, const char *output_delimiter = "\r",
int buffer_size = 256, int timeout = 8000, bool debug = false){}
~ATCmdParser(){}
};
#endif //__AT_CMD_PARSER_H__

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , 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.
*/

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) , 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 __PINNAMES_H__
#define __PINNAMES_H__
typedef enum {
} PinName;
#endif

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , 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.
*/

Some files were not shown because too many files have changed in this diff Show More