Skip to content

Connection status cb #6134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7416270
Initial cellular feature
Feb 9, 2018
986168e
Updated cellular
Feb 10, 2018
2c022dd
Smoke test changes with easy-connect
Feb 10, 2018
9beb531
Changed to use platform baudrate to uart.
Feb 10, 2018
5bb2b4d
Unittests added
Feb 11, 2018
9cc1d8a
renamed mbed_mux to cellular_mux
Feb 12, 2018
0895af0
working example?
Feb 12, 2018
f8d0e57
Fixed to call callback when connected...
Feb 12, 2018
1820953
Added cellular stack API
Feb 12, 2018
27c57c3
Changed register to accept only roaming and homenetwork as registered…
Feb 12, 2018
2e69de5
Updated cellular doxygen
Feb 12, 2018
0257f28
Removed dead code from athandler.
Feb 12, 2018
30c80fb
more unittests added
Feb 12, 2018
3ce6618
Merge branch 'master' into unittests
Feb 12, 2018
3a37ab5
Update AT_CellularPower.cpp
Feb 12, 2018
23b69a2
Merge pull request #1 from AriParkkila/unittests
jarvte Feb 13, 2018
f150c46
Updated license texts.
Feb 13, 2018
e8e993c
Removed ASSERT from mux.
Feb 13, 2018
7ae2da7
Changed requested stack for new pdp context
Feb 13, 2018
dc16b46
Change cellular socket port 0 to dynamic range
Feb 13, 2018
8d912b7
Removed mbed.h
Feb 13, 2018
5cdc242
Fixed doxygen warning.
Feb 13, 2018
ecf3c18
Smaller thread stack size for dispatcher thread to save memory.
Feb 13, 2018
8dc4afc
Fixed IAR 7.8 compile
Feb 14, 2018
acd3348
PR review fixed: removed dead code, removed magic numbers.
Feb 14, 2018
0e41da3
Device info buffer moved from stack to static
Feb 14, 2018
9cbbf6e
- Removed extra whitespaces from AT prefix definitions. The format is…
Feb 15, 2018
6a298ab
Merge remote-tracking branch 'upstream/master'
Feb 15, 2018
d7a90ce
Connection status callback added.
Feb 15, 2018
3c33251
Deactivate PDP context on disconnect when using AT stack.
Feb 15, 2018
5e04288
PR review fix:
Feb 15, 2018
71105e3
Removed unnecessary memsets of ATHandler's receving buffer
Feb 16, 2018
7b6b3e8
Added cellular greentea tests
Feb 16, 2018
03432a0
Merge pull request #2 from AriParkkila/greentea-tests
Feb 16, 2018
563a3db
Enable connection status callback with EasyCellularConnection
Feb 19, 2018
78e50b6
Updated greentea tests for cellular status callback
Feb 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions features/cellular/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lcov/
results/
coverages/
gcov/
*.exe
*.o
*.d
*.a
*.gcda
*.gcno
cpputest_*.xml
*_unit_tests*
1 change: 1 addition & 0 deletions features/cellular/.mbedignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UNITTESTS/*
56 changes: 56 additions & 0 deletions features/cellular/Makefile.test
Original file line number Diff line number Diff line change
@@ -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)
82 changes: 82 additions & 0 deletions features/cellular/TESTS/cellular/cellular_all/CellularTests.h
Original file line number Diff line number Diff line change
@@ -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
103 changes: 103 additions & 0 deletions features/cellular/TESTS/cellular/cellular_all/main.cpp
Original file line number Diff line number Diff line change
@@ -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"

#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);
}
120 changes: 120 additions & 0 deletions features/cellular/TESTS/cellular/cellular_all/network.cpp
Original file line number Diff line number Diff line change
@@ -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 bool wait_register()
{
log_info("Try registering to network...");
if (network->set_registration() != NSAPI_ERROR_OK) {
log_error("Network registration request failed.");
return false;
}

CellularNetwork::RegistrationStatus status;
for (int i=0; i<180; i++) {
log_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) {
log_info("status %d...", status);
switch (status) {
case CellularNetwork::RegisteredRoaming:
// fall-through
case CellularNetwork::RegisteredHomeNetwork:
log_info("Registered to network.");
return true;
case CellularNetwork::RegisteredSMSOnlyRoaming:
// fall-through
case CellularNetwork::RegisteredSMSOnlyHome:
log_warn("SMS only network registration!");
return true;
case CellularNetwork::RegisteredCSFBNotPreferredRoaming:
// fall-through
case CellularNetwork::RegisteredCSFBNotPreferredHome:
log_warn("Not preferred network registration!");
return true;
case CellularNetwork::AttachedEmergencyOnly:
log_warn("Emergency only network registration!");
return true;
case CellularNetwork::RegistrationDenied:
log_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()
{
log_info("Register to network.");
TEST_ASSERT(wait_register());
log_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);
}

static volatile bool _status_cb = false;
static Semaphore _cb_semaphore(0);

static void status_callback(nsapi_event_t event, intptr_t param)
{
_status_cb = true;
/* Depending on mode of connect operation (async/sync) might get called before semaphore is acquired */
_cb_semaphore.release();
}

void test_connect()
{
_status_cb = false;
network->attach(&status_callback);
nsapi_error_t err = network->connect();
TEST_ASSERT(!err);

if(!_status_cb) {
TEST_ASSERT(_cb_semaphore.wait(1000 * 10) == 1);
}
network->attach(NULL);
}

void test_get_ip_address()
{
const char *ip = network->get_ip_address();
TEST_ASSERT(ip && ip[0]);
log_info("IP: %s\r\n", ip);
}

void test_disconnect()
{
nsapi_error_t err = network->disconnect();
TEST_ASSERT(!err);
}

#endif // CELLULAR_DEVICE
Loading