diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp index 4f2be58fbe..0a6d649e74 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp @@ -60,7 +60,7 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_manufacturer) AT_CellularInformation aci(ah); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "some"; + ATHandler_stub::read_string_value = (char *)"some"; ATHandler_stub::ssize_value = 4; char buf[8]; @@ -82,7 +82,7 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_model) AT_CellularInformation aci(ah); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "model"; + ATHandler_stub::read_string_value = (char *)"model"; ATHandler_stub::ssize_value = 5; char buf[8]; EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_model(buf, 8)); @@ -105,7 +105,7 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision) AT_CellularInformation *aci = new AT_CellularInformation(ah); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "revision"; + ATHandler_stub::read_string_value = (char *)"revision"; ATHandler_stub::ssize_value = 8; char buf[9]; @@ -129,7 +129,7 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number AT_CellularInformation aci(ah); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "1234567"; + ATHandler_stub::read_string_value = (char *)"1234567"; ATHandler_stub::ssize_value = 7; char buf[8]; @@ -147,7 +147,7 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number EXPECT_TRUE(strlen(buf) == 0); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "1234567"; + ATHandler_stub::read_string_value = (char *)"1234567"; ATHandler_stub::ssize_value = 7; AT_CellularBase_stub::supported_bool = true; EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp index e54a8d2844..a498db66f8 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -252,7 +252,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = ""; + ATHandler_stub::read_string_table[0] = (char *)""; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); @@ -261,7 +261,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "IPV6"; + ATHandler_stub::read_string_table[0] = (char *)"IPV6"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_NO_CONNECTION == cn.activate_context()); @@ -270,8 +270,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IP"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IP"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); @@ -281,8 +281,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV4V6"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IPV4V6"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(IPV4_STACK)); EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); @@ -293,8 +293,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV6"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IPV6"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(IPV6_STACK)); EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); @@ -305,8 +305,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV4V6"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IPV4V6"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(DEFAULT_STACK)); EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); @@ -317,8 +317,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV4V6"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IPV4V6"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(DEFAULT_STACK)); EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); @@ -329,8 +329,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV6"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IPV6"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(DEFAULT_STACK)); EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); @@ -341,8 +341,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IP"; + ATHandler_stub::read_string_table[0] = (char *)"internet"; + ATHandler_stub::read_string_table[1] = (char *)"IP"; ATHandler_stub::int_value = 1; EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(DEFAULT_STACK)); EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); @@ -795,9 +795,9 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_scan_plmn) ATHandler_stub::read_string_index = 3; - ATHandler_stub::read_string_table[0] = "44444"; - ATHandler_stub::read_string_table[1] = "33333"; - ATHandler_stub::read_string_table[2] = "12345"; + ATHandler_stub::read_string_table[0] = (char *)"44444"; + ATHandler_stub::read_string_table[1] = (char *)"33333"; + ATHandler_stub::read_string_table[2] = (char *)"12345"; ATHandler_stub::int_value = 1; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::info_elem_true_counter = 1; @@ -922,13 +922,13 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_pdpcontext_params) ATHandler_stub::int_valid_count_table[0] = 9; ATHandler_stub::read_string_index = 7; - ATHandler_stub::read_string_table[6] = "internet"; - ATHandler_stub::read_string_table[5] = "1.2.3.4.5.6.7.8.9.10.11.112.13.14.15.16.1.2.3.44.55.6.7.8.9.10.11.12.13.14.15.16"; - ATHandler_stub::read_string_table[4] = "23.33.44.1.2.3.55.123.225.34.11.1.0.0.123.234"; - ATHandler_stub::read_string_table[3] = "1.2.3.4"; - ATHandler_stub::read_string_table[2] = "0.255.0.255"; - ATHandler_stub::read_string_table[1] = "25.66.77.88"; - ATHandler_stub::read_string_table[0] = "004.003.002.001"; + ATHandler_stub::read_string_table[6] = (char *)"internet"; + ATHandler_stub::read_string_table[5] = (char *)"1.2.3.4.5.6.7.8.9.10.11.112.13.14.15.16.1.2.3.44.55.6.7.8.9.10.11.12.13.14.15.16"; + ATHandler_stub::read_string_table[4] = (char *)"23.33.44.1.2.3.55.123.225.34.11.1.0.0.123.234"; + ATHandler_stub::read_string_table[3] = (char *)"1.2.3.4"; + ATHandler_stub::read_string_table[2] = (char *)"0.255.0.255"; + ATHandler_stub::read_string_table[1] = (char *)"25.66.77.88"; + ATHandler_stub::read_string_table[0] = (char *)"004.003.002.001"; EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list)); CellularNetwork::pdpcontext_params_t *params = list.get_head(); @@ -1005,8 +1005,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_cell_id) EXPECT_TRUE(id == -1); ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[1] = "00C3"; - ATHandler_stub::read_string_table[0] = "1234FFC1"; //== cellid and in dec: 305463233 + ATHandler_stub::read_string_table[1] = (char *)"00C3"; + ATHandler_stub::read_string_table[0] = (char *)"1234FFC1"; //== cellid and in dec: 305463233 ATHandler_stub::int_value = 1; // Get registration status to modify cell_id CellularNetwork::RegistrationType type; @@ -1043,7 +1043,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_operator_params) ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; ATHandler_stub::int_value = 0; ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "12345"; + ATHandler_stub::read_string_table[0] = (char *)"12345"; EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); EXPECT_TRUE(format == 0); EXPECT_TRUE(strcmp(ops.op_long, "12345") == 0); @@ -1054,7 +1054,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_operator_params) ops.op_long[0] = 0; ATHandler_stub::int_value = 1; ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "12345"; + ATHandler_stub::read_string_table[0] = (char *)"12345"; EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); EXPECT_TRUE(format == 1); EXPECT_TRUE(strlen(ops.op_long) == 0); @@ -1065,7 +1065,7 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_operator_params) ops.op_short[0] = 0; ATHandler_stub::int_value = 2; ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "12345"; + ATHandler_stub::read_string_table[0] = (char *)"12345"; EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); EXPECT_TRUE(format == 2); EXPECT_TRUE(strlen(ops.op_long) == 0); @@ -1097,8 +1097,8 @@ TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_operator_names) ATHandler_stub::resp_info_true_counter = 1; ATHandler_stub::bool_value = false; ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[1] = "12345"; - ATHandler_stub::read_string_table[0] = "56789"; + ATHandler_stub::read_string_table[1] = (char *)"12345"; + ATHandler_stub::read_string_table[0] = (char *)"56789"; ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; name_list.delete_all(); EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_names(name_list)); diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp index eb82bc6c9a..e4fe6a1ce1 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp @@ -73,7 +73,7 @@ TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12")); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "READY"; + ATHandler_stub::read_string_value = (char *)"READY"; ATHandler_stub::ssize_value = 5; EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); @@ -131,22 +131,22 @@ TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state) EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); EXPECT_TRUE(CellularSIM::SimStateUnknown == state); - ATHandler_stub::read_string_value = "READY"; + ATHandler_stub::read_string_value = (char *)"READY"; ATHandler_stub::ssize_value = 5; EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); EXPECT_TRUE(CellularSIM::SimStateReady == state); - ATHandler_stub::read_string_value = "SIM PIN"; + ATHandler_stub::read_string_value = (char *)"SIM PIN"; ATHandler_stub::ssize_value = 7; EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); EXPECT_TRUE(CellularSIM::SimStatePinNeeded == state); - ATHandler_stub::read_string_value = "SIM PUK"; + ATHandler_stub::read_string_value = (char *)"SIM PUK"; ATHandler_stub::ssize_value = 7; EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); EXPECT_TRUE(CellularSIM::SimStatePukNeeded == state); - ATHandler_stub::read_string_value = "SOME CRAP"; + ATHandler_stub::read_string_value = (char *)"SOME CRAP"; ATHandler_stub::ssize_value = 9; EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); EXPECT_TRUE(CellularSIM::SimStateUnknown == state); @@ -161,7 +161,7 @@ TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi) char imsi[16]; AT_CellularSIM sim(at); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "123456789012345"; + ATHandler_stub::read_string_value = (char *)"123456789012345"; ATHandler_stub::ssize_value = 15; EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_imsi(imsi)); EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, imsi) == 0); @@ -190,7 +190,7 @@ TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid) char buf[16]; AT_CellularSIM sim(at); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "123456789012345"; + ATHandler_stub::read_string_value = (char *)"123456789012345"; ATHandler_stub::ssize_value = 15; EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_iccid(buf, 16)); EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, buf) == 0); diff --git a/UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp b/UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp new file mode 100644 index 0000000000..f9411f3c51 --- /dev/null +++ b/UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp @@ -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. + */ + +#include "gtest/gtest.h" +#include "LoRaMac.h" + +using namespace events; + +class Test_LoRaMac : public testing::Test { +protected: + LoRaMac *object; + + virtual void SetUp() + { + object = new LoRaMac(); + } + + virtual void TearDown() + { + delete object; + } +}; + +TEST_F(Test_LoRaMac, constructor) +{ + EXPECT_TRUE(object); +} + +void my_cb() +{ + +} + +TEST_F(Test_LoRaMac, initialize) +{ + EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb)); +} + + diff --git a/UNITTESTS/features/lorawan/loramac/unittest.cmake b/UNITTESTS/features/lorawan/loramac/unittest.cmake new file mode 100644 index 0000000000..70b39ac5ce --- /dev/null +++ b/UNITTESTS/features/lorawan/loramac/unittest.cmake @@ -0,0 +1,58 @@ +#[[ + * 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. +]] + +# Unit test suite name +set(TEST_SUITE_NAME "lorawan_LoRaMac") + +# Source files +set(unittest-sources + ../features/lorawan/lorastack/mac/LoRaMac.cpp +) + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + target_h + ../features/lorawan/lorastack/mac +) + +# Test & stub files +set(unittest-test-sources + ../features/lorawan/loramac/Test_LoRaMac.cpp + stubs/LoRaPHY_stub.cpp + stubs/LoRaWANStack_stub.cpp + stubs/mbed_assert_stub.c + stubs/LoRaMacCrypto_stub.cpp + stubs/LoRaMacChannelPlan_stub.cpp + stubs/LoRaWANTimer_stub.cpp + stubs/LoRaMacCommand_stub.cpp + stubs/EventQueue_stub.cpp + +) + +# defines +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_ADR_ON=true -DMBED_CONF_LORA_PUBLIC_NETWORK=true -DMBED_CONF_LORA_NB_TRIALS=2 -DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_ADR_ON=true -DMBED_CONF_LORA_PUBLIC_NETWORK=true -DMBED_CONF_LORA_NB_TRIALS=2 -DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_DUTY_CYCLE_ON=true -DMBED_CONF_LORA_MAX_SYS_RX_ERROR=10 -DMBED_CONF_LORA_NWKSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_DUTY_CYCLE_ON=true -DMBED_CONF_LORA_MAX_SYS_RX_ERROR=10 -DMBED_CONF_LORA_NWKSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_APPSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_APPSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_DEVICE_ADDRESS=\"0x00000000\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_DEVICE_ADDRESS=\"0x00000000\"") + diff --git a/UNITTESTS/features/lorawan/loramaccrypto/Test_LoRaMacCrypto.cpp b/UNITTESTS/features/lorawan/loramaccrypto/Test_LoRaMacCrypto.cpp new file mode 100644 index 0000000000..8bd28b0025 --- /dev/null +++ b/UNITTESTS/features/lorawan/loramaccrypto/Test_LoRaMacCrypto.cpp @@ -0,0 +1,40 @@ +/* + * 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 "gtest/gtest.h" +#include "LoRaMacCrypto.h" + +class Test_LoRaMacCrypto : public testing::Test { +protected: + LoRaMacCrypto *object; + + virtual void SetUp() + { + object = new LoRaMacCrypto(); + } + + virtual void TearDown() + { + delete object; + } +}; + +TEST_F(Test_LoRaMacCrypto, constructor) +{ + EXPECT_TRUE(object); +} + diff --git a/UNITTESTS/features/lorawan/loramaccrypto/unittest.cmake b/UNITTESTS/features/lorawan/loramaccrypto/unittest.cmake new file mode 100644 index 0000000000..d3972d3ca2 --- /dev/null +++ b/UNITTESTS/features/lorawan/loramaccrypto/unittest.cmake @@ -0,0 +1,40 @@ +#[[ + * 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. +]] + +# Unit test suite name +set(TEST_SUITE_NAME "lorawan_LoRaMacCrypto") + +# Source files +set(unittest-sources + ../features/lorawan/lorastack/mac/LoRaMacCrypto.cpp +) + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + target_h + ../features/lorawan/lorastack/mac +) + +# Test & stub files +set(unittest-test-sources + ../features/lorawan/loramaccrypto/Test_LoRaMacCrypto.cpp + stubs/cipher_stub.c + stubs/aes_stub.c + stubs/cmac_stub.c + +) + diff --git a/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp b/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp new file mode 100644 index 0000000000..4c4a5dffed --- /dev/null +++ b/UNITTESTS/features/lorawan/lorawanstack/Test_LoRaWANStack.cpp @@ -0,0 +1,40 @@ +/* + * 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 "gtest/gtest.h" +#include "LoRaWANStack.h" + +class Test_LoRaWANStack : public testing::Test { +protected: + LoRaWANStack *object; + + virtual void SetUp() + { + object = new LoRaWANStack(); + } + + virtual void TearDown() + { + delete object; + } +}; + +TEST_F(Test_LoRaWANStack, constructor) +{ + EXPECT_TRUE(object); +} + diff --git a/UNITTESTS/features/lorawan/lorawanstack/unittest.cmake b/UNITTESTS/features/lorawan/lorawanstack/unittest.cmake new file mode 100644 index 0000000000..9442d5a6c4 --- /dev/null +++ b/UNITTESTS/features/lorawan/lorawanstack/unittest.cmake @@ -0,0 +1,54 @@ +#[[ + * 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. +]] + +# Unit test suite name +set(TEST_SUITE_NAME "lorawan_LoRaWANStack") + +# Source files +set(unittest-sources + ../features/lorawan/LoRaWANStack.cpp +) + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + target_h + ../features/lorawan +) + +# Test & stub files +set(unittest-test-sources + ../features/lorawan/lorawanstack/Test_LoRaWANStack.cpp + stubs/LoRaPHY_stub.cpp + stubs/LoRaMac_stub.cpp + stubs/mbed_assert_stub.c + stubs/LoRaMacCrypto_stub.cpp + stubs/LoRaMacChannelPlan_stub.cpp + stubs/LoRaWANTimer_stub.cpp + stubs/LoRaMacCommand_stub.cpp + stubs/EventQueue_stub.cpp + stubs/equeue_stub.c + +) + +# defines +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true -DMBED_CONF_LORA_DEVICE_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true -DMBED_CONF_LORA_DEVICE_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") + + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_APPLICATION_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\" -DMBED_CONF_LORA_APPLICATION_KEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_APPLICATION_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\" -DMBED_CONF_LORA_APPLICATION_KEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"") + diff --git a/UNITTESTS/stubs/EventQueue_stub.cpp b/UNITTESTS/stubs/EventQueue_stub.cpp index e3436647b7..71c030df22 100644 --- a/UNITTESTS/stubs/EventQueue_stub.cpp +++ b/UNITTESTS/stubs/EventQueue_stub.cpp @@ -47,6 +47,11 @@ void EventQueue::cancel(int id) { } +int EventQueue::time_left(int id) +{ + return 0; +} + void EventQueue::background(Callback update) { } diff --git a/UNITTESTS/stubs/aes_stub.c b/UNITTESTS/stubs/aes_stub.c new file mode 100644 index 0000000000..ca54d09030 --- /dev/null +++ b/UNITTESTS/stubs/aes_stub.c @@ -0,0 +1,161 @@ + + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include + +#include "mbedtls/aes.h" + + +void mbedtls_aes_init( mbedtls_aes_context *ctx ) +{ +} + +void mbedtls_aes_free( mbedtls_aes_context *ctx ) +{ +} + +#if defined(MBEDTLS_CIPHER_MODE_XTS) +void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ) +{ +} + +void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ) +{ +} +#endif + +#if !defined(MBEDTLS_AES_SETKEY_ENC_ALT) +int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, + unsigned int keybits ) +{ + return( 0 ); +} +#endif + +#if !defined(MBEDTLS_AES_SETKEY_DEC_ALT) +int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, + unsigned int keybits ) +{ + return 0; +} +#endif + +#if defined(MBEDTLS_CIPHER_MODE_XTS) +int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits) +{ + return 0; +} + +int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits) +{ + return 0; +} +#endif + +int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ) +{ + return( 0 ); +} + +void mbedtls_aes_encrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ) +{ +} + +int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ) +{ + return( 0 ); +} + +void mbedtls_aes_decrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ) +{ +} + +int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, + int mode, + const unsigned char input[16], + unsigned char output[16] ) +{ + return 0; +} + +int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) +{ + return( 0 ); +} + + +#if defined(MBEDTLS_CIPHER_MODE_XTS) +int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, + int mode, + size_t length, + const unsigned char data_unit[16], + const unsigned char *input, + unsigned char *output ) +{ + return( 0 ); +} +#endif + +int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) +{ + return( 0 ); +} + +int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) +{ + return( 0 ); +} + +int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) +{ + return( 0 ); +} + +int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ) +{ + return( 0 ); +} diff --git a/UNITTESTS/stubs/cipher_stub.c b/UNITTESTS/stubs/cipher_stub.c new file mode 100644 index 0000000000..350e4fa0de --- /dev/null +++ b/UNITTESTS/stubs/cipher_stub.c @@ -0,0 +1,166 @@ +/** + * \file cipher.c + * + * \brief Generic cipher wrapper for mbed TLS + * + * \author Adriaan de Jong + * + * Copyright (C) 2006-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. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include "mbedtls/cipher.h" +#include "mbedtls/cipher_internal.h" +#include "mbedtls/platform_util.h" + +#include +#include + +#if defined(MBEDTLS_GCM_C) +#include "mbedtls/gcm.h" +#endif + +#if defined(MBEDTLS_CCM_C) +#include "mbedtls/ccm.h" +#endif + +#if defined(MBEDTLS_CMAC_C) +#include "mbedtls/cmac.h" +#endif + + +const int *mbedtls_cipher_list( void ) +{ + return NULL; +} + +const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type ) +{ + return( NULL ); +} + +const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name ) +{ + return( NULL ); +} + +const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id, + int key_bitlen, + const mbedtls_cipher_mode_t mode ) +{ + return( NULL ); +} + +void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx ) +{ +} + +void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ) +{ +} + +int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ) +{ + return( 0 ); +} + +int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key, + int key_bitlen, const mbedtls_operation_t operation ) +{ + return( 0 ); +} + +int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len ) +{ + return( 0 ); +} + +int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx ) +{ + return( 0 ); +} + +int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, + const unsigned char *ad, size_t ad_len ) +{ + return( 0 ); +} + +int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input, + size_t ilen, unsigned char *output, size_t *olen ) +{ + return( 0 ); +} + +int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, + unsigned char *output, size_t *olen ) +{ + return( 0 ); +} + +int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode ) +{ + return( 0 ); +} + +int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, + unsigned char *tag, size_t tag_len ) +{ + return( 0 ); +} + +int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, + const unsigned char *tag, size_t tag_len ) +{ + return( 0 ); +} + +int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen ) +{ + return( 0 ); +} + +int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, + unsigned char *tag, size_t tag_len ) +{ + return( 0 ); +} + +int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, + const unsigned char *tag, size_t tag_len ) +{ + return( 0 ); +} + diff --git a/UNITTESTS/stubs/cmac_stub.c b/UNITTESTS/stubs/cmac_stub.c new file mode 100644 index 0000000000..e2277f17ad --- /dev/null +++ b/UNITTESTS/stubs/cmac_stub.c @@ -0,0 +1,51 @@ + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + + +#include "mbedtls/cmac.h" +#include "mbedtls/platform_util.h" +#include + + +int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, + const unsigned char *key, size_t keybits ) +{ + return 0; +} + +int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, + const unsigned char *input, size_t ilen ) +{ + return( 0 ); +} + +int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, + unsigned char *output ) +{ + return( 0 ); +} + +int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ) +{ + return( 0 ); +} + +int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info, + const unsigned char *key, size_t keylen, + const unsigned char *input, size_t ilen, + unsigned char *output ) +{ + return( 0 ); +} + +int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length, + const unsigned char *input, size_t in_len, + unsigned char *output ) +{ + return( 0 ); +} +