diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/6lowpan_nd/README.md b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/6lowpan_nd/README.md deleted file mode 100644 index e457bf62930..00000000000 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/6lowpan_nd/README.md +++ /dev/null @@ -1,88 +0,0 @@ -# Example how to connect to mesh network -This application establishes connection to mbed 6LoWPAN gateway. After successful -connection tahe application disconnects from the network. - -## Pre-requisites -To build and run this example the requirements below are necessary: - -* A computer with the following software installed - - * CMake - * yotta - * python - * arm gcc toolchain - * a serial terminal emulator (e.g. screen, pyserial, cu) - * optionally, for debugging, pyOCD and pyUSB -* A frdm-k64f development board -* A mbed 6LoWPAN shield -* A mbed 6LoWPAN Gateway -* A micro-USB cable -* A micro-USB charger for mbed 6LoWPAN Gateway - -## Getting Started -1. Connect the frdm-k64f and 6LoWPAN RF shield together -2. Flash mbed 6LoWPAN gateway. -3. Open a terminal in the root mbed-mesh-api directory -4. Check that there are no missing dependencies - - ``` - $ yt ls - ``` - -5. Build the examples. This will take a long time if it is the first time that the examples have been built. - - ``` - $ yt target frdm-k64f-gcc - $ yt build - ``` - -6. Start the mbed 6LoWPAN Gateway by connecting USB charger - -7. Copy `build/frdm-k64f-gcc/test/mbed-mesh-api.bin` to your mbed board and wait until the LED next to the USB port stops blinking. - -8. Start the serial terminal emulator and connect to the virtual serial port presented by frdm-k64f. For settings, use 9600 baud, 8N1, no flow control. - -9. Press the reset button on the board. - -10. The output in the serial terminal emulator window should indicate a log that network is established. - -## Using a debugger -Optionally, connect using a debugger to set breakpoints and follow program flow. Proceed normally up to and including step 7, then: - -1. Open a new terminal window, then start the pyOCD GDB server. - - ``` - $ python pyOCD/test/gdb_server.py - ``` - - The output should look like this: - - ``` - Welcome to the PyOCD GDB Server Beta Version - INFO:root:new board id detected: 02400201B1130E4E4CXXXXXX - id => usbinfo | boardname - 0 => MB MBED CM (0xd28, 0x204) [k64f] - INFO:root:DAP SWD MODE initialised - INFO:root:IDCODE: 0x2BA01477 - INFO:root:K64F not in secure state - INFO:root:6 hardware breakpoints, 4 literal comparators - INFO:root:4 hardware watchpoints - INFO:root:CPU core is Cortex-M4 - INFO:root:FPU present - INFO:root:GDB server started at port:3333 - ``` - -2. Open a new terminal window, go to the root directory of your copy of mbed-6lowpan-adapter, then start GDB and connect to the GDB server. - - ``` - $ arm-none-eabi-gdb -ex "target remote localhost:3333" -ex load ./build/frdm-k64f-gcc/test/mbed-mesh-api-test-6lowpan_nd - ``` - -3. In a third terminal window, start the serial terminal emulator and connect to the virtual serial port presented by frdm-k64f. - -4. Once the program has loaded, start it. - - ``` - (gdb) mon reset halt - (gdb) c - ``` diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/6lowpan_nd/main.cpp b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/6lowpan_nd/main.cpp deleted file mode 100644 index e8f1ac0763f..00000000000 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/6lowpan_nd/main.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * 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 -#include "mbed-drivers/test_env.h" -#include "atmel-rf-driver/driverRFPhy.h" // rf_device_register -#include "mbed-mesh-api/MeshInterfaceFactory.h" -#include "mbed-mesh-api/Mesh6LoWPAN_ND.h" -#include "mbed-mesh-api/MeshThread.h" -// For tracing we need to define flag, have include and define group -#define HAVE_DEBUG 1 -#include "ns_trace.h" -#define TRACE_GROUP "mesh_appl" - -// Bootstrap mode, if undefined then 6LoWPAN-ND mode is used -#define BOOTSTRAP_MODE_THREAD - -// mesh network state -static mesh_connection_status_t mesh_network_state = MESH_DISCONNECTED; - -static AbstractMesh *meshApi; - -// mesh network callback, called when network state changes -void mesh_network_callback(mesh_connection_status_t mesh_state) -{ - tr_info("mesh_network_callback() %d", mesh_state); - mesh_network_state = mesh_state; - if (mesh_network_state == MESH_CONNECTED) { - tr_info("Connected to mesh network!"); - // Once connected, disconnect from network - meshApi->disconnect(); - } else if (mesh_network_state == MESH_DISCONNECTED) { - tr_info("Disconnected from mesh network!"); - delete meshApi; - tr_info("Mesh networking done!"); - } else { - tr_error("Networking error!"); - } -} - -void app_start(int, char **) -{ - mesh_error_t status; - - // set tracing baud rate - static Serial &pc = get_stdio_serial(); - pc.baud(115200); - - // create 6LoWPAN_ND interface -#ifdef BOOTSTRAP_MODE_THREAD - meshApi = MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD); - uint8_t eui64[8]; - int8_t rf_device = rf_device_register(); - rf_read_mac_address(eui64); - char *pskd = (char *)"Secret password"; - // Use tr_info traces and RF interface after MeshAPi has been created. - // as interface initializes mesh system that RF device is using - tr_info("Mesh API test application - Thread mode"); - // initialize the interface with registered device and callback - status = ((MeshThread *)meshApi)->init(rf_device, mesh_network_callback, eui64, pskd); -#else - meshApi = (Mesh6LoWPAN_ND *)MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND); - // Use tr_info traces and RF interface after MeshAPi has been created. - // as interface initializes mesh system that RF device is using - tr_info("Mesh API test application - 6LoWPAN-ND mode"); - // initialize the interface with registered device and callback - status = ((Mesh6LoWPAN_ND *)meshApi)->init(rf_device_register(), mesh_network_callback); -#endif - - // Set ns_trace configuration level - // set_trace_config(TRACE_ACTIVE_LEVEL_INFO|TRACE_MODE_COLOR|TRACE_CARRIAGE_RETURN); - - if (status != MESH_ERROR_NONE) { - tr_error("Can't initialize mesh network"); - return; - } - - // connect interface to the network - status = meshApi->connect(); - if (status != MESH_ERROR_NONE) { - tr_error("Can't connect to Mesh network!"); - return; - } -} diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/main.cpp b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/main.cpp deleted file mode 100644 index b921d2866dc..00000000000 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/main.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * 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.h" -#include "mbed-mesh-api/Mesh6LoWPAN_ND.h" -#include "mbed-mesh-api/MeshThread.h" -#include "mbed-mesh-api/MeshInterfaceFactory.h" -#include "atmel-rf-driver/driverRFPhy.h" // rf_device_register -#include "test_cases.h" -#include "mbed-drivers/test_env.h" -#include "core-util/FunctionPointer.h" -#define HAVE_DEBUG 1 -#include "ns_trace.h" - -#define TRACE_GROUP "main" // for traces - -using namespace mbed::util; - -/** - * Test with 6LoWPAN ND or Thread bootstrap - * If TEST_THREAD_BOOTSTRAP is not defined then 6LoWPAN ND bootstrap is used. - */ -#define TEST_THREAD_BOOTSTRAP - -class TestMeshApi; -TestMeshApi *testMeshApi; - -static int8_t rf_device_id = -1; - -class TestMeshApi -{ -private: - int testId; - int tests_pass; - int loopCount; - -public: - TestMeshApi() : testId(0), tests_pass(1), loopCount(0) { - tr_info("TestMeshApi"); - } - - void runTests() { - switch (testId) { - case 0: - test_mesh_api_init(rf_device_id); - break; - case 1: - test_mesh_api_init_thread(rf_device_id); - break; - case 2: - test_mesh_api_disconnect(rf_device_id, MESH_TYPE_6LOWPAN_ND); - break; - case 3: - test_mesh_api_disconnect(rf_device_id, MESH_TYPE_THREAD); - break; -#ifndef TEST_THREAD_BOOTSTRAP - case 4: - test_mesh_api_connect(rf_device_id, MESH_TYPE_6LOWPAN_ND); - break; - case 5: - test_mesh_api_delete_connected(rf_device_id, MESH_TYPE_6LOWPAN_ND); - break; - case 6: - test_mesh_api_connect_disconnect(rf_device_id, MESH_TYPE_6LOWPAN_ND); - break; -#else // TEST_THREAD_BOOTSTRAP - case 4: - test_mesh_api_connect_disconnect(rf_device_id, MESH_TYPE_THREAD); - break; - case 5: - test_mesh_api_delete_connected(rf_device_id, MESH_TYPE_THREAD); - break; - case 6: - test_mesh_api_connect(rf_device_id, MESH_TYPE_THREAD); - break; - case 7: - test_mesh_api_data_poll_rate_set_thread(rf_device_id); - break; -#endif // TEST_THREAD_BOOTSTRAP - default: - endTest(tests_pass); - break; - } - - testId++; - } - - void testResult(int status) { - tests_pass = tests_pass && status; - } - - void endTest(bool status) { - if (loopCount > 0) { - printf("\r\n#####\r\n"); - printf("\r\nTest loops left %d, current result=%d\r\n", loopCount, tests_pass); - printf("\r\n#####\r\n"); - loopCount--; - testId = 0; - /* Schedule tests run again */ - FunctionPointer0 fpNextTest(testMeshApi, &TestMeshApi::runTests); - minar::Scheduler::postCallback(fpNextTest.bind()).delay(minar::milliseconds(3000)); - } else { - MBED_HOSTTEST_RESULT(status); - } - } -}; - - -void test_result_notify(int result, AbstractMesh *meshAPI) -{ - if (meshAPI != NULL) { - delete meshAPI; - } - /* inform results to main class */ - FunctionPointer1 fpResult(testMeshApi, &TestMeshApi::testResult); - minar::Scheduler::postCallback(fpResult.bind(result)); - - /* Schedule next test to run */ - FunctionPointer0 fpNextTest(testMeshApi, &TestMeshApi::runTests); - minar::Scheduler::postCallback(fpNextTest.bind()).delay(minar::milliseconds(1000)); -} - - -void app_start(int, char **) -{ - MBED_HOSTTEST_TIMEOUT(5); - MBED_HOSTTEST_SELECT(default); - MBED_HOSTTEST_DESCRIPTION(Mesh network API tests); - MBED_HOSTTEST_START("mbed-mesh-api"); - - // set tracing baud rate - static Serial &pc = get_stdio_serial(); - pc.baud(115200); - - // before registering RF device mesh network needs to be created - Mesh6LoWPAN_ND *mesh_api = (Mesh6LoWPAN_ND *)MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND); - delete mesh_api; - rf_device_id = rf_device_register(); - - testMeshApi = new TestMeshApi; - - FunctionPointer0 fp(testMeshApi, &TestMeshApi::runTests); - minar::Scheduler::postCallback(fp.bind()); -} diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/test_cases.cpp b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/test_cases.cpp deleted file mode 100644 index 1f425d3cae3..00000000000 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/test_cases.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * 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.h" -#include "mbed-mesh-api/Mesh6LoWPAN_ND.h" -#include "mbed-mesh-api/MeshThread.h" -#include "mbed-mesh-api/MeshInterfaceFactory.h" -#include "mbed-mesh-api/mesh_interface_types.h" -#include "sal/test/ctest_env.h" -#include "atmel-rf-driver/driverRFPhy.h" // rf_device_register -#include "test_cases.h" -#include "mbed-drivers/test_env.h" -#define HAVE_DEBUG 1 -#include "ns_trace.h" - -#define TRACE_GROUP "main" // for traces - -#define TEST_RESULT_PRINT()\ - do {\ - TEST_PRINT("{{summary %s [%s] (%d/%d FAILED)}}\r\n", __func__, (TEST_RESULT()?"PASS":"FAIL"), tests_failed_global, tests_total_global);\ - }while (0) - -static uint8_t mesh_network_state = MESH_DISCONNECTED; -AbstractMesh *mesh_api = NULL; - -extern void test_result_notify(int result, AbstractMesh *meshAPI); - -// Thread device type, currently defined statically, change also -// YOTTA_CFG_MBED_MESH_API_THREAD_DEVICE_TYPE from static_config.h to match selection -#define TEST_THREAD_DEVICE_TYPE_SED false - -/* - * Callback from mesh network. Called when network state changes. - */ -void test_callback_connect_disconnect(mesh_connection_status_t mesh_state) -{ - tr_info("test_callback_connect_disconnect() %d", mesh_state); - mesh_network_state = mesh_state; - if (mesh_network_state == MESH_CONNECTED) { - tr_info("Connected to mesh network!"); - mesh_error_t err = mesh_api->disconnect(); - TEST_EQ(err, MESH_ERROR_NONE); - } else if (mesh_network_state == MESH_DISCONNECTED) { - tr_info("Disconnected from mesh network!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } else { - // untested branch, catch erros by bad state checking... - TEST_EQ(mesh_network_state, MESH_CONNECTED); - tr_error("Networking error!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } -} - -void test_mesh_api_connect_disconnect(int8_t rf_device_id, mesh_network_type_t type) -{ - mesh_error_t err; - TEST_PRINT("\r\nBegin %s, type=%d\r\n", __func__, type); - - mesh_api = MeshInterfaceFactory::createInterface(type); - // initialize interface - if (type == MESH_TYPE_THREAD) { - uint8_t eui64[8]; - char *pskd; - rf_read_mac_address(eui64); - pskd = (char *)"Secret password"; - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_connect_disconnect, eui64, pskd); - } else { - err = mesh_api->init(rf_device_id, test_callback_connect_disconnect); - } - - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - return; - } - - err = mesh_api->connect(); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - return; - } - // control goes to test callback -} - -void test_callback_init(mesh_connection_status_t mesh_state) -{ - tr_info("test_callback_init() %d", mesh_state); -} - -void test_mesh_api_init(int8_t rf_device_id) -{ - mesh_error_t err; - TEST_PRINT("\r\nBegin %s\r\n", __func__); - mesh_api = (Mesh6LoWPAN_ND *)MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND); - - do { - // no callback set - err = mesh_api->init(rf_device_id, NULL); - if (!TEST_EQ(err, MESH_ERROR_PARAM)) { - break; - } - - // bad rf-device_id - err = mesh_api->init(rf_device_id + 1, test_callback_init); - if (!TEST_EQ(err, MESH_ERROR_MEMORY)) { - break; - } - - // successful re-initialization - err = mesh_api->init(rf_device_id, test_callback_init); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - break; - } - - /* Thread can't be instantiated if ND is initialized */ - MeshThread *meshThread = (MeshThread *)MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD); - if (!TEST_EQ(meshThread, NULL)) { - break; - } - break; - } while (1); - - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); -} - -void test_mesh_api_init_thread(int8_t rf_device_id) -{ - mesh_error_t err; - uint8_t eui64[8]; - char *pskd; - - TEST_PRINT("\r\nBegin %s\r\n", __func__); - rf_read_mac_address(eui64); - pskd = (char *)"Secret password"; - - mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD); - - do { - // no callback set - err = ((MeshThread *)mesh_api)->init(rf_device_id, NULL); - if (!TEST_EQ(err, MESH_ERROR_PARAM)) { - break; - } - - // No address in eui64 - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_init, NULL, pskd); - if (!TEST_EQ(err, MESH_ERROR_PARAM)) { - break; - } - - // bad rf-device_id - err = ((MeshThread *)mesh_api)->init(rf_device_id + 1, test_callback_init, eui64, pskd); - if (!TEST_EQ(err, MESH_ERROR_MEMORY)) { - break; - } - - // successful re-initialization - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_init, eui64, pskd); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - break; - } - - /* Thread can't be instantiated if it has been initialized already */ - MeshThread *apiThread = (MeshThread *)MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD); - if (!TEST_EQ(apiThread, NULL)) { - break; - } - - /* 6LoWPAN ND can't be instantiated if Thread has been initialized */ - Mesh6LoWPAN_ND *apiND = (Mesh6LoWPAN_ND *)MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND); - if (!TEST_EQ(apiND, NULL)) { - break; - } - - break; - } while (1); - - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); -} - -/* - * Callback from mesh network for mesh_api_connect test - */ -void test_callback_connect(mesh_connection_status_t mesh_state) -{ - mesh_error_t err; - tr_info("test_callback_connect() %d", mesh_state); - mesh_network_state = mesh_state; - - if (mesh_network_state == MESH_CONNECTED) { - tr_info("Connected to mesh network!"); - // try to connect again, should fail - err = mesh_api->connect(); - if (!TEST_EQ(err, MESH_ERROR_STATE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } else { - // disconnect - err = mesh_api->disconnect(); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } - } - } else if (mesh_network_state == MESH_DISCONNECTED) { - tr_info("Disconnected from mesh network!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } else { - // untested branch, catch errors by bad state checking... - TEST_EQ(true, false); - tr_error("Networking error!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } -} - -void test_mesh_api_connect(int8_t rf_device_id, mesh_network_type_t type) -{ - mesh_error_t err; - - TEST_PRINT("\r\nBegin %s, type=%d\r\n", __func__, type); - mesh_api = MeshInterfaceFactory::createInterface(type); - - do { - // connect uninitialized - err = mesh_api->connect(); - if (!TEST_EQ(err, MESH_ERROR_PARAM)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - - // initialize interface - if (type == MESH_TYPE_THREAD) { - uint8_t eui64[8]; - char *pskd; - rf_read_mac_address(eui64); - pskd = (char *)"Secret password"; - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_connect, eui64, pskd); - } else { - err = mesh_api->init(rf_device_id, test_callback_connect); - } - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - - // successful connect - err = mesh_api->connect(); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - //test continues in callback - break; - } while (1); -} - -/* - * Callback from mesh network for mesh_api_connect test - */ -void test_callback_disconnect(mesh_connection_status_t mesh_state) -{ - tr_info("test_callback_disconnect() %d", mesh_state); - TEST_EQ(true, false); - tr_error("Networking error, callback received!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); -} - -void test_mesh_api_disconnect(int8_t rf_device_id, mesh_network_type_t type) -{ - mesh_error_t err; - - TEST_PRINT("\r\nBegin %s\r\n", __func__); - mesh_api = MeshInterfaceFactory::createInterface(type); - - do { - // disconnect not initialized, callback not called - err = mesh_api->disconnect(); - if (!TEST_EQ(err, MESH_ERROR_UNKNOWN)) { - break; - } - - // initialize interface - if (type == MESH_TYPE_THREAD) { - uint8_t eui64[8]; - char *pskd; - rf_read_mac_address(eui64); - pskd = (char *)"Secret password"; - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_disconnect, eui64, pskd); - } else { - err = mesh_api->init(rf_device_id, test_callback_disconnect); - } - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - break; - } - - // disconnect not connected - err = mesh_api->disconnect(); - if (!TEST_EQ(err, MESH_ERROR_UNKNOWN)) { - break; - } - break; - } while (1); - - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); -} - -/* - * Callback from mesh network for test_mesh_api_delete_connected test - */ -void test_callback_delete_connected(mesh_connection_status_t mesh_state) -{ - tr_info("test_callback_delete() %d", mesh_state); - if (mesh_state == MESH_CONNECTED) { - delete mesh_api; - mesh_api = NULL; - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } else { - tr_error("Networking error!"); - TEST_EQ(true, false); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } -} - -void test_mesh_api_delete_connected(int8_t rf_device_id, mesh_network_type_t type) -{ - mesh_error_t err; - - TEST_PRINT("\r\nBegin %s, type=%d\r\n", __func__, type); - mesh_api = MeshInterfaceFactory::createInterface(type); - - do { - // initialize interface - if (type == MESH_TYPE_THREAD) { - uint8_t eui64[8]; - char *pskd; - rf_read_mac_address(eui64); - pskd = (char *)"Secret password"; - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_delete_connected, eui64, pskd); - } else { - err = mesh_api->init(rf_device_id, test_callback_delete_connected); - } - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - - // successful connect - err = mesh_api->connect(); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - //test continues in callback - break; - } while (1); -} - - -/* - * Callback from mesh network for test_mesh_api_data_poll_rate_set_thread test - */ -void test_callback_data_poll_rate_set_thread(mesh_connection_status_t mesh_state) -{ - tr_info("test_callback_data_poll_rate_set() %d", mesh_state); - mesh_network_state = mesh_state; - - if (mesh_network_state == MESH_CONNECTED) { - tr_info("Connected to mesh network!"); - -#if (TEST_THREAD_DEVICE_TYPE_SED == true) - mesh_error_t err; - // set data polling rate to 0 (enables fast polling mode) - err = ((MeshThread*)mesh_api)->data_poll_rate_set(0); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - return; - } - - // try to set data polling rate to 100000 - err = ((MeshThread*)mesh_api)->data_poll_rate_set(864001+1); - if (!TEST_EQ(err, MESH_ERROR_PARAM)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - return; - } - - // OK case, set data polling rate to 5 - err = ((MeshThread*)mesh_api)->data_poll_rate_set(5); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - return; - } -#endif - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } else if (mesh_network_state == MESH_DISCONNECTED) { - tr_info("Disconnected from mesh network!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } else { - // untested branch, catch errors by bad state checking... - TEST_EQ(true, false); - tr_error("Networking error!"); - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - } -} - -void test_mesh_api_data_poll_rate_set_thread(int8_t rf_device_id) -{ - mesh_error_t err; - - TEST_PRINT("\r\nBegin %s\r\n", __func__); - - mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD); - - do { - // try to set data polling rate when not initialized - err = ((MeshThread*)mesh_api)->data_poll_rate_set(1); - if (!TEST_EQ(err, MESH_ERROR_UNKNOWN)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - - uint8_t eui64[8]; - rf_read_mac_address(eui64); - err = ((MeshThread *)mesh_api)->init(rf_device_id, test_callback_data_poll_rate_set_thread, eui64, NULL); - - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - - // try to set data polling rate when not connected - err = ((MeshThread*)mesh_api)->data_poll_rate_set(1); - if (!TEST_EQ(err, MESH_ERROR_UNKNOWN)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - - // successful connect - err = mesh_api->connect(); - if (!TEST_EQ(err, MESH_ERROR_NONE)) { - TEST_RESULT_PRINT(); - test_result_notify(test_pass_global, mesh_api); - break; - } - //test continues in callback - break; - } while (1); -} - diff --git a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/test_cases.h b/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/test_cases.h deleted file mode 100644 index f268fe177d5..00000000000 --- a/features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/test/system_test/test_cases.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015 ARM Limited. All rights reserved. - * 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_CASES__H__ -#define __TEST_CASES__H__ - -/* positive cases */ -void test_mesh_api_connect_disconnect(int8_t rf_device_id, mesh_network_type_t type); - -/* failure cases */ -void test_mesh_api_init(int8_t rf_device_id); -void test_mesh_api_init_thread(int8_t rf_device_id); -void test_mesh_api_connect(int8_t rf_device_id, mesh_network_type_t type); -void test_mesh_api_disconnect(int8_t rf_device_id, mesh_network_type_t type); -void test_mesh_api_delete_connected(int8_t rf_device_id, mesh_network_type_t type); -void test_mesh_api_data_poll_rate_set_thread(int8_t rf_device_id); - -#endif /* __TEST_CASES__H__ */