Merge pull request #8233 from AnttiKauppila/lora_unittests

Lora unittests
pull/8337/head
Martin Kojtal 2018-10-05 22:20:47 +02:00 committed by GitHub
commit 943130c1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
123 changed files with 7820 additions and 349 deletions

View File

@ -119,6 +119,13 @@ set(unittest-includes-base
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
"${PROJECT_SOURCE_DIR}/../features/lorawan"
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack"
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/mac"
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/phy"
"${PROJECT_SOURCE_DIR}/../features/lorawan/system"
"${PROJECT_SOURCE_DIR}/../features/mbedtls"
"${PROJECT_SOURCE_DIR}/../features/mbedtls/inc"
)
# Create a list for test suites.

View File

@ -20,17 +20,17 @@ set(unittest-sources
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.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
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.c
stubs/CellularDevice_stub.cpp
)

View File

@ -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));

View File

@ -20,9 +20,9 @@ set(unittest-sources
# Test files
set(unittest-test-sources
features/cellular/framework/AT//at_cellularinformation/at_cellularinformationtest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -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));

View File

@ -21,14 +21,14 @@ set(unittest-sources
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/NetworkInterface_stub.cpp
stubs/NetworkStack_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/SocketAddress_stub.cpp
stubs/randLIB_stub.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/NetworkInterface_stub.cpp
stubs/NetworkStack_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.c
stubs/SocketAddress_stub.cpp
stubs/randLIB_stub.cpp
)

View File

@ -24,5 +24,5 @@ set(unittest-test-sources
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -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);

View File

@ -25,5 +25,5 @@ set(unittest-test-sources
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -25,6 +25,6 @@ set(unittest-test-sources
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_assert_stub.c
stubs/mbed_wait_api_stub.cpp
)

View File

@ -27,5 +27,5 @@ set(unittest-test-sources
stubs/us_ticker_stub.cpp
stubs/NetworkStack_stub.cpp
stubs/SocketAddress_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -25,7 +25,7 @@ set(unittest-test-sources
stubs/FileHandle_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_wait_api_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_assert_stub.c
stubs/mbed_poll_stub.cpp
stubs/Timer_stub.cpp
stubs/equeue_stub.c

View File

@ -0,0 +1,560 @@
/*
* 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"
#include "LoRaPHY_stub.h"
#include "LoRaMacCrypto_stub.h"
#include "LoRaMacCommand_stub.h"
#include "LoRaWANTimer_stub.h"
#include "EventQueue_stub.h"
using namespace events;
class my_phy : public LoRaPHY
{
public:
my_phy(){};
virtual ~my_phy(){};
};
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)
{
my_phy phy;
object->bind_phy(phy);
lorawan_connect_t conn;
uint8_t key[16];
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = key;
conn.connection_u.otaa.nb_trials = 2;
object->prepare_join(&conn, true);
LoRaWANTimer_stub::call_cb_immediately = true;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb));
}
TEST_F(Test_LoRaMac, disconnect)
{
object->disconnect();
}
TEST_F(Test_LoRaMac, nwk_joined)
{
EXPECT_EQ(false, object->nwk_joined());
}
TEST_F(Test_LoRaMac, add_channel_plan)
{
lorawan_channelplan_t plan;
EXPECT_EQ(LORAWAN_STATUS_OK, object->add_channel_plan(plan));
object->set_tx_ongoing(true);
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->add_channel_plan(plan));
}
TEST_F(Test_LoRaMac, remove_channel_plan)
{
EXPECT_EQ(LORAWAN_STATUS_OK, object->remove_channel_plan());
object->set_tx_ongoing(true);
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->remove_channel_plan());
}
TEST_F(Test_LoRaMac, get_channel_plan)
{
lorawan_channelplan_t plan;
EXPECT_EQ(LORAWAN_STATUS_OK, object->get_channel_plan(plan));
}
TEST_F(Test_LoRaMac, remove_single_channel)
{
EXPECT_EQ(LORAWAN_STATUS_OK, object->remove_single_channel(1));
object->set_tx_ongoing(true);
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->remove_single_channel(1));
}
TEST_F(Test_LoRaMac, multicast_channel_link)
{
multicast_params_t p;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->multicast_channel_link(NULL));
object->set_tx_ongoing(true);
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->multicast_channel_link(&p));
object->set_tx_ongoing(false);
EXPECT_EQ(LORAWAN_STATUS_OK, object->multicast_channel_link(&p));
}
TEST_F(Test_LoRaMac, multicast_channel_unlink)
{
multicast_params_t p;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->multicast_channel_unlink(NULL));
object->set_tx_ongoing(true);
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->multicast_channel_unlink(&p));
object->set_tx_ongoing(false);
EXPECT_EQ(LORAWAN_STATUS_OK, object->multicast_channel_unlink(&p));
}
TEST_F(Test_LoRaMac, send)
{
loramac_mhdr_t mac_hdr;
uint8_t buf[15];
mac_hdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP;
object->send(&mac_hdr, 1, buf, 15);
}
TEST_F(Test_LoRaMac, get_default_tx_datarate)
{
object->get_default_tx_datarate();
}
TEST_F(Test_LoRaMac, enable_adaptive_datarate)
{
object->enable_adaptive_datarate(true);
}
TEST_F(Test_LoRaMac, set_channel_data_rate)
{
object->set_channel_data_rate(8);
}
TEST_F(Test_LoRaMac, tx_ongoing)
{
object->tx_ongoing();
}
TEST_F(Test_LoRaMac, set_tx_ongoing)
{
object->set_tx_ongoing(true);
}
TEST_F(Test_LoRaMac, reset_ongoing_tx)
{
object->reset_ongoing_tx(true);
}
TEST_F(Test_LoRaMac, prepare_ongoing_tx)
{
uint8_t buf[16];
object->prepare_ongoing_tx(1, buf, 16, 1, 0);
}
TEST_F(Test_LoRaMac, send_ongoing_tx)
{
object->send_ongoing_tx();
}
TEST_F(Test_LoRaMac, get_device_class)
{
object->get_device_class();
}
void exp_cb()
{
}
TEST_F(Test_LoRaMac, set_device_class)
{
object->set_device_class(CLASS_B, exp_cb);
}
TEST_F(Test_LoRaMac, setup_link_check_request)
{
object->setup_link_check_request();
}
TEST_F(Test_LoRaMac, prepare_join)
{
lorawan_connect_t conn;
object->prepare_join(&conn, false);
my_phy phy;
object->bind_phy(phy);
EXPECT_EQ(LORAWAN_STATUS_OK, object->join(false));
uint8_t key[16];
conn.connection_u.otaa.app_key = NULL;
conn.connection_u.otaa.app_eui = NULL;
conn.connection_u.otaa.dev_eui = NULL;
conn.connection_u.otaa.nb_trials = 0;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = NULL;
conn.connection_u.otaa.dev_eui = NULL;
conn.connection_u.otaa.nb_trials = 0;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = NULL;
conn.connection_u.otaa.nb_trials = 0;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = key;
conn.connection_u.otaa.nb_trials = 0;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
LoRaPHY_stub::bool_table[0] = false;
LoRaPHY_stub::bool_counter = 0;
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = key;
conn.connection_u.otaa.nb_trials = 2;
EXPECT_EQ(LORAWAN_STATUS_OK, object->prepare_join(&conn, true));
conn.connection_u.abp.dev_addr = 0;
conn.connection_u.abp.nwk_id = 0;
conn.connection_u.abp.nwk_skey = NULL;
conn.connection_u.abp.app_skey = NULL;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
conn.connection_u.abp.dev_addr = 1;
conn.connection_u.abp.nwk_id = 0;
conn.connection_u.abp.nwk_skey = NULL;
conn.connection_u.abp.app_skey = NULL;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
conn.connection_u.abp.dev_addr = 1;
conn.connection_u.abp.nwk_id = 2;
conn.connection_u.abp.nwk_skey = NULL;
conn.connection_u.abp.app_skey = NULL;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
conn.connection_u.abp.dev_addr = 1;
conn.connection_u.abp.nwk_id = 2;
conn.connection_u.abp.nwk_skey = key;
conn.connection_u.abp.app_skey = NULL;
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
conn.connection_u.abp.dev_addr = 1;
conn.connection_u.abp.nwk_id = 2;
conn.connection_u.abp.nwk_skey = key;
conn.connection_u.abp.app_skey = key;
EXPECT_EQ(LORAWAN_STATUS_OK, object->prepare_join(&conn, false));
EXPECT_EQ(LORAWAN_STATUS_OK, object->prepare_join(NULL, false));
}
TEST_F(Test_LoRaMac, join)
{
my_phy phy;
object->bind_phy(phy);
EXPECT_EQ(LORAWAN_STATUS_OK, object->join(false));
lorawan_connect_t conn;
uint8_t key[16];
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = key;
conn.connection_u.otaa.nb_trials = 2;
object->prepare_join(&conn, true);
EXPECT_EQ(LORAWAN_STATUS_CONNECT_IN_PROGRESS, object->join(true));
}
TEST_F(Test_LoRaMac, on_radio_tx_done)
{
my_phy phy;
object->bind_phy(phy);
object->on_radio_tx_done(100);
}
TEST_F(Test_LoRaMac, on_radio_rx_done)
{
uint8_t buf[16];
object->on_radio_rx_done(buf, 16, 0, 0);
}
TEST_F(Test_LoRaMac, on_radio_tx_timeout)
{
object->on_radio_tx_timeout();
}
TEST_F(Test_LoRaMac, on_radio_rx_timeout)
{
object->on_radio_rx_timeout(true);
}
TEST_F(Test_LoRaMac, continue_joining_process)
{
my_phy phy;
object->bind_phy(phy);
lorawan_connect_t conn;
uint8_t key[16];
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = key;
conn.connection_u.otaa.nb_trials = 2;
object->prepare_join(&conn, true);
object->continue_joining_process();
}
TEST_F(Test_LoRaMac, continue_sending_process)
{
my_phy phy;
object->bind_phy(phy);
object->continue_sending_process();
}
TEST_F(Test_LoRaMac, get_mcps_confirmation)
{
object->get_mcps_confirmation();
}
TEST_F(Test_LoRaMac, get_mcps_indication)
{
object->get_mcps_indication();
}
TEST_F(Test_LoRaMac, get_mlme_confirmation)
{
object->get_mlme_confirmation();
}
TEST_F(Test_LoRaMac, get_mlme_indication)
{
object->get_mlme_indication();
}
TEST_F(Test_LoRaMac, post_process_mcps_req)
{
uint8_t data[16];
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
my_phy phy;
object->bind_phy(phy);
object->join(false);
object->prepare_ongoing_tx(1, data, 15, 0x01, 2);
object->send_ongoing_tx();
object->post_process_mcps_req();
LoRaPHY_stub::bool_counter = 0;
object->prepare_ongoing_tx(1, data, 15, 0x02, 2);
object->send_ongoing_tx();
object->post_process_mcps_req();
//_mcps_confirmation.ack_received missing here
uint8_t payload[16] = {};
LoRaPHY_stub::uint16_value = 5;
payload[0] = FRAME_TYPE_DATA_CONFIRMED_DOWN << 5;
payload[5] = 1 << 5;
//address != _params.dev_addr
payload[2] = 2;
object->on_radio_rx_done(payload, 16, 0, 0);
object->post_process_mcps_req();
payload[2] = 0;
//mic failure
payload[13] = 2;
object->on_radio_rx_done(payload, 16, 0, 0);
object->post_process_mcps_req();
payload[13] = 0;
//crypto failure
LoRaMacCrypto_stub::int_table_idx_value = 0;
LoRaMacCrypto_stub::int_table[0] = 4;
LoRaMacCrypto_stub::int_table[1] = 4;
// LoRaPHY_stub::uint16_value = 0;
object->on_radio_rx_done(payload, 16, 0, 0);
object->post_process_mcps_req();
//process_mac_commands failure
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_BUSY;
LoRaMacCrypto_stub::int_table[0] = 0;
LoRaMacCrypto_stub::int_table[1] = 0;
payload[7] = 1;
object->on_radio_rx_done(payload, 16, 0, 0);
object->post_process_mcps_req();
//FOpts_len != 0
payload[5] = (1 << 5) + 1;
payload[7] = 0;
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
payload[0] = FRAME_TYPE_DATA_UNCONFIRMED_DOWN << 5;
object->on_radio_rx_done(payload, 13, 0, 0);
//_mac_commands.process_mac_commands fails
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_DATARATE_INVALID;
object->on_radio_rx_done(payload, 13, 0, 0);
object->post_process_mcps_req();
payload[9] = 1;
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
payload[0] = FRAME_TYPE_PROPRIETARY << 5;
object->on_radio_rx_done(payload, 16, 0, 0);
object->post_process_mcps_req();
payload[9] = 0;
payload[5] = 1 << 5;
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
object->on_radio_rx_done(payload, 16, 0, 0);
object->post_process_mcps_req();
LoRaPHY_stub::bool_counter = 0;
object->prepare_ongoing_tx(1, data, 15, 0x04, 2);
object->send_ongoing_tx();
object->post_process_mcps_req();
LoRaPHY_stub::bool_counter = 0;
object->prepare_ongoing_tx(1, data, 15, 0x08, 2);
object->send_ongoing_tx();
object->post_process_mcps_req();
}
TEST_F(Test_LoRaMac, handle_join_accept_frame)
{
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
my_phy phy;
object->bind_phy(phy);
uint8_t payload[16] = {};
LoRaPHY_stub::uint16_value = 5;
payload[0] = FRAME_TYPE_JOIN_ACCEPT << 5;
payload[5] = 1 << 5;
LoRaMacCrypto_stub::int_table_idx_value = 0;
LoRaMacCrypto_stub::int_table[0] = 4;
LoRaMacCrypto_stub::int_table[1] = 4;
LoRaMacCrypto_stub::int_table[2] = 4;
LoRaMacCrypto_stub::int_table[3] = 4;
object->on_radio_rx_done(payload, 16, 0, 0);
LoRaMacCrypto_stub::int_table_idx_value = 0;
LoRaMacCrypto_stub::int_table[0] = 0;
object->on_radio_rx_done(payload, 16, 0, 0);
LoRaMacCrypto_stub::int_table_idx_value = 0;
LoRaMacCrypto_stub::int_table[1] = 0;
object->on_radio_rx_done(payload, 16, 0, 0);
//mic failure case
payload[13] = 17;
LoRaMacCrypto_stub::int_table_idx_value = 0;
object->on_radio_rx_done(payload, 16, 0, 0);
payload[13] = 0;
LoRaMacCrypto_stub::int_table_idx_value = 0;
LoRaMacCrypto_stub::int_table[2] = 0;
object->on_radio_rx_done(payload, 16, 0, 0);
}
TEST_F(Test_LoRaMac, post_process_mcps_ind)
{
object->post_process_mcps_ind();
}
TEST_F(Test_LoRaMac, post_process_mlme_request)
{
object->post_process_mlme_request();
}
TEST_F(Test_LoRaMac, post_process_mlme_ind)
{
object->post_process_mlme_ind();
}
uint8_t batt_cb()
{
}
TEST_F(Test_LoRaMac, set_batterylevel_callback)
{
object->set_batterylevel_callback(batt_cb);
}
TEST_F(Test_LoRaMac, get_backoff_timer_event_id)
{
object->get_backoff_timer_event_id();
}
TEST_F(Test_LoRaMac, clear_tx_pipe)
{
EXPECT_EQ(LORAWAN_STATUS_OK, object->clear_tx_pipe()); //timer id == 0
my_phy phy;
object->bind_phy(phy);
lorawan_connect_t conn;
uint8_t key[16];
conn.connection_u.otaa.app_key = key;
conn.connection_u.otaa.app_eui = key;
conn.connection_u.otaa.dev_eui = key;
conn.connection_u.otaa.nb_trials = 2;
object->prepare_join(&conn, true);
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb));
EventQueue_stub::int_value = 0;
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->clear_tx_pipe());
EventQueue_stub::int_value = 1;
EXPECT_EQ(LORAWAN_STATUS_OK, object->clear_tx_pipe());
}
TEST_F(Test_LoRaMac, get_current_time)
{
object->get_current_time();
}
TEST_F(Test_LoRaMac, get_current_slot)
{
object->get_current_slot();
}

View File

@ -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\"")

View File

@ -0,0 +1,168 @@
/*
* 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 "LoRaMacChannelPlan.h"
#include "LoRaPHY_stub.h"
#include "LoRaPHY.h"
class my_LoRaPHY : public LoRaPHY
{
public:
my_LoRaPHY(){};
virtual ~my_LoRaPHY(){};
};
class Test_LoRaMacChannelPlan : public testing::Test {
protected:
LoRaMacChannelPlan *object;
my_LoRaPHY phy;
virtual void SetUp()
{
object = new LoRaMacChannelPlan();
object->activate_channelplan_subsystem(&phy);
LoRaPHY_stub::uint8_value = 0;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
LoRaPHY_stub::uint16_value = 0;
memcpy(LoRaPHY_stub::bool_table, "0", 20);
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaMacChannelPlan, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaMacChannelPlan, set_plan)
{
lorawan_channelplan_t plan;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = false;
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_SERVICE_UNKNOWN);
plan.nb_channels = 1;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::uint8_value = 0;
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::uint8_value = 10;
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_PARAMETER_INVALID;
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
plan.nb_channels = 2;
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_OK);
}
TEST_F(Test_LoRaMacChannelPlan, get_plan)
{
lorawan_channelplan_t plan;
channel_params_t params;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = false;
EXPECT_TRUE(object->get_plan(plan, &params) == LORAWAN_STATUS_SERVICE_UNKNOWN);
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = false;
LoRaPHY_stub::uint8_value = 1;
LoRaPHY_stub::uint16_value = 0xABCD;
EXPECT_TRUE(object->get_plan(plan, &params) == LORAWAN_STATUS_OK);
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = true;
LoRaPHY_stub::bool_table[2] = false;
loramac_channel_t ch;
plan.channels = &ch;
EXPECT_TRUE(object->get_plan(plan, &params) == LORAWAN_STATUS_OK);
}
TEST_F(Test_LoRaMacChannelPlan, remove_plan)
{
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = false;
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_SERVICE_UNKNOWN);
LoRaPHY_stub::uint8_value = 4;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = true; //first continue
LoRaPHY_stub::bool_table[2] = false;
LoRaPHY_stub::bool_table[3] = false;//second continue
LoRaPHY_stub::bool_table[4] = false;
LoRaPHY_stub::bool_table[5] = true;
LoRaPHY_stub::bool_table[6] = false;//false for remove_single_channel(i)
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_SERVICE_UNKNOWN);
LoRaPHY_stub::uint8_value = 3;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = false;
LoRaPHY_stub::bool_table[2] = true;
LoRaPHY_stub::bool_table[3] = true;
LoRaPHY_stub::bool_table[4] = true;
LoRaPHY_stub::bool_table[5] = true;
LoRaPHY_stub::bool_table[7] = true;
LoRaPHY_stub::bool_table[8] = true;
LoRaPHY_stub::bool_table[9] = true;
LoRaPHY_stub::bool_table[10] = true;
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_OK);
}
TEST_F(Test_LoRaMacChannelPlan, remove_single_channel)
{
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = false;
EXPECT_TRUE(object->remove_single_channel(4) == LORAWAN_STATUS_SERVICE_UNKNOWN);
LoRaPHY_stub::uint8_value = 2;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
EXPECT_TRUE(object->remove_single_channel(4) == LORAWAN_STATUS_PARAMETER_INVALID);
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = false;
EXPECT_TRUE(object->remove_single_channel(1) == LORAWAN_STATUS_PARAMETER_INVALID);
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = true;
EXPECT_TRUE(object->remove_single_channel(1) == LORAWAN_STATUS_OK);
}

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.
]]
# Unit test suite name
set(TEST_SUITE_NAME "lorawan_LoRaMacChannelPlan")
# Source files
set(unittest-sources
../features/lorawan/lorastack/mac/LoRaMacChannelPlan.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/loramacchannelplan/Test_LoRaMacChannelPlan.cpp
stubs/LoRaPHY_stub.cpp
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_TX_MAX_SIZE=255")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_TX_MAX_SIZE=255")

View File

@ -0,0 +1,353 @@
/*
* 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 "LoRaMacCommand.h"
#include "LoRaPHY_stub.h"
class my_LoRaPHY : public LoRaPHY
{
public:
my_LoRaPHY(){};
virtual ~my_LoRaPHY(){};
};
uint8_t my_cb()
{
return 1;
}
class Test_LoRaMacCommand : public testing::Test {
protected:
LoRaMacCommand *object;
virtual void SetUp()
{
object = new LoRaMacCommand();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaMacCommand, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaMacCommand, get_mac_cmd_length)
{
object->add_link_check_req();
EXPECT_TRUE(object->get_mac_cmd_length() == 1);
object->clear_command_buffer();
EXPECT_TRUE(object->get_mac_cmd_length() == 0);
}
TEST_F(Test_LoRaMacCommand, parse_mac_commands_to_repeat)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
object->parse_mac_commands_to_repeat();
buf[0] = 2;
buf[1] = 16;
buf[2] = 32;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 3, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 3;
LoRaPHY_stub::uint8_value = 7;
LoRaPHY_stub::linkAdrNbBytesParsed = 5;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 4;
buf[1] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 5;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 6;
object->set_batterylevel_callback(my_cb);
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 7;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 8;
buf[1] = 0;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 9;
buf[1] = 48;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 10;
buf[1] = 2;
buf[1] = 3;
buf[1] = 4;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
object->parse_mac_commands_to_repeat();
}
TEST_F(Test_LoRaMacCommand, clear_repeat_buffer)
{
object->clear_repeat_buffer();
}
TEST_F(Test_LoRaMacCommand, copy_repeat_commands_to_buffer)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
object->clear_command_buffer();
buf[0] = 5;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
object->parse_mac_commands_to_repeat();
object->clear_command_buffer();
EXPECT_TRUE(object->get_mac_cmd_length() == 0);
object->copy_repeat_commands_to_buffer();
EXPECT_TRUE(object->get_mac_cmd_length() != 0);
}
TEST_F(Test_LoRaMacCommand, get_repeat_commands_length)
{
EXPECT_TRUE(object->get_repeat_commands_length() == 0 );
}
TEST_F(Test_LoRaMacCommand, clear_sticky_mac_cmd)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
EXPECT_TRUE(object->has_sticky_mac_cmd() == false);
object->clear_command_buffer();
buf[0] = 5;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
EXPECT_TRUE(object->has_sticky_mac_cmd() == true);
object->clear_sticky_mac_cmd();
EXPECT_TRUE(object->has_sticky_mac_cmd() == false);
}
TEST_F(Test_LoRaMacCommand, has_sticky_mac_cmd)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
EXPECT_TRUE(object->has_sticky_mac_cmd() == false);
object->clear_command_buffer();
buf[0] = 5;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
EXPECT_TRUE(object->has_sticky_mac_cmd() == true);
}
TEST_F(Test_LoRaMacCommand, process_mac_commands)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
EXPECT_TRUE(object->process_mac_commands(NULL, 0, 0, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 2;
buf[1] = 16;
buf[2] = 32;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 3, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
buf[0] = 3;
LoRaPHY_stub::uint8_value = 7;
LoRaPHY_stub::linkAdrNbBytesParsed = 5;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_link_adr_ans function here
object->clear_command_buffer();
buf[0] = 3;
for (int i=0; i < 64; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 4;
buf[1] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_duty_cycle_ans()
object->clear_command_buffer();
for (int i=0; i < 128; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 5;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_rx_param_setup_ans
object->clear_command_buffer();
LoRaPHY_stub::uint8_value = 7;
for (int i=0; i < 64; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 6;
object->set_batterylevel_callback(my_cb);
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//overflow add_dev_status_ans
object->clear_command_buffer();
for (int i=0; i < 42; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 7;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_new_channel_ans
object->clear_command_buffer();
LoRaPHY_stub::uint8_value = 7;
for (int i=0; i < 64; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 8;
buf[1] = 0;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_rx_timing_setup_ans
object->clear_command_buffer();
LoRaPHY_stub::uint8_value = 7;
for (int i=0; i < 128; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 9;
buf[1] = 48;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_tx_param_setup_ans
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
object->clear_command_buffer();
LoRaPHY_stub::uint8_value = 7;
for (int i=0; i < 128; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
LoRaPHY_stub::bool_counter = 0;
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 10;
buf[1] = 2;
buf[1] = 3;
buf[1] = 4;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
//Overflow add_tx_param_setup_ans
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
object->clear_command_buffer();
LoRaPHY_stub::uint8_value = 7;
for (int i=0; i < 64; i++) {
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
LoRaPHY_stub::bool_counter = 0;
}
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
object->clear_command_buffer();
buf[0] = 80;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_UNSUPPORTED);
}
TEST_F(Test_LoRaMacCommand, add_link_check_req)
{
object->add_link_check_req();
EXPECT_TRUE(object->get_mac_commands_buffer()[0] == 2);
EXPECT_TRUE(object->get_mac_cmd_length() == 1);
object->clear_command_buffer();
EXPECT_TRUE(object->get_mac_cmd_length() == 0);
}
TEST_F(Test_LoRaMacCommand, set_batterylevel_callback)
{
object->set_batterylevel_callback(my_cb);
}

View File

@ -0,0 +1,38 @@
#[[
* 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_LoRaMacCommand")
# Source files
set(unittest-sources
../features/lorawan/lorastack/mac/LoRaMacCommand.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/loramaccommand/Test_LoRaMacCommand.cpp
stubs/mbed_assert_stub.c
stubs/LoRaPHY_stub.cpp
)

View File

@ -0,0 +1,178 @@
/*
* 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"
#include "cipher_stub.h"
#include "cmac_stub.h"
#include "aes_stub.h"
class Test_LoRaMacCrypto : public testing::Test {
protected:
LoRaMacCrypto *object;
virtual void SetUp()
{
cipher_stub.info_value = NULL;
cipher_stub.int_zero_counter = 0;
cipher_stub.int_value = 0;
cmac_stub.int_zero_counter = 0;
cmac_stub.int_value = 0;
aes_stub.int_zero_counter = 0;
aes_stub.int_value = 0;
object = new LoRaMacCrypto();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaMacCrypto, constructor)
{
EXPECT_TRUE(object);
LoRaMacCrypto obj;
}
TEST_F(Test_LoRaMacCrypto, compute_mic)
{
EXPECT_TRUE(MBEDTLS_ERR_CIPHER_ALLOC_FAILED == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
mbedtls_cipher_info_t info;
cipher_stub.info_value = &info;
cipher_stub.int_zero_counter = 0;
cipher_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
cipher_stub.int_value = 0;
cmac_stub.int_zero_counter = 0;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
cmac_stub.int_zero_counter = 1;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
cmac_stub.int_zero_counter = 2;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
cmac_stub.int_zero_counter = 3;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
uint32_t mic[16];
cmac_stub.int_zero_counter = 3;
cmac_stub.int_value = 0;
EXPECT_TRUE(0 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, mic));
}
TEST_F(Test_LoRaMacCrypto, encrypt_payload)
{
aes_stub.int_zero_counter = 0;
aes_stub.int_value = -1;
EXPECT_TRUE(-1 == object->encrypt_payload(NULL, 0, NULL, 0, 0, 0, 0, NULL));
aes_stub.int_zero_counter = 1;
aes_stub.int_value = -2;
uint8_t buf[60];
uint8_t enc[60];
EXPECT_TRUE(-2 == object->encrypt_payload(buf, 20, NULL, 0, 0, 0, 0, enc));
aes_stub.int_zero_counter = 2;
aes_stub.int_value = -3;
EXPECT_TRUE(-3 == object->encrypt_payload(buf, 20, NULL, 0, 0, 0, 0, enc));
aes_stub.int_value = 0;
EXPECT_TRUE(0 == object->encrypt_payload(buf, 20, NULL, 0, 0, 0, 0, enc));
EXPECT_TRUE(0 == object->encrypt_payload(buf, 60, NULL, 0, 0, 0, 0, enc));
aes_stub.int_zero_counter = 0;
EXPECT_TRUE(0 == object->encrypt_payload(NULL, 0, NULL, 0, 0, 0, 0, NULL));
}
TEST_F(Test_LoRaMacCrypto, decrypt_payload)
{
EXPECT_TRUE(0 == object->decrypt_payload(NULL, 0, NULL, 0, 0, 0, 0, NULL));
}
TEST_F(Test_LoRaMacCrypto, compute_join_frame_mic)
{
uint32_t mic[16];
EXPECT_TRUE(MBEDTLS_ERR_CIPHER_ALLOC_FAILED == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
mbedtls_cipher_info_t info;
cipher_stub.info_value = &info;
cipher_stub.int_zero_counter = 0;
cipher_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
cipher_stub.int_value = 0;
cmac_stub.int_zero_counter = 0;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
cmac_stub.int_zero_counter = 1;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
cmac_stub.int_zero_counter = 2;
cmac_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
cmac_stub.int_zero_counter = 3;
cmac_stub.int_value = 0;
EXPECT_TRUE(0 == object->compute_join_frame_mic(NULL, 0, NULL, 0, mic));
}
TEST_F(Test_LoRaMacCrypto, decrypt_join_frame)
{
aes_stub.int_zero_counter = 0;
aes_stub.int_value = -1;
EXPECT_TRUE(-1 == object->decrypt_join_frame(NULL, 0, NULL, 0, NULL));
aes_stub.int_zero_counter = 1;
aes_stub.int_value = -1;
EXPECT_TRUE(-1 == object->decrypt_join_frame(NULL, 0, NULL, 0, NULL));
aes_stub.int_value = 0;
uint8_t buf[60];
uint8_t enc[60];
EXPECT_TRUE(0 == object->decrypt_join_frame(buf, 60, NULL, 0, enc));
}
TEST_F(Test_LoRaMacCrypto, compute_skeys_for_join_frame)
{
uint8_t nwk_key[16];
uint8_t app_key[16];
uint8_t nonce[16];
aes_stub.int_zero_counter = 0;
aes_stub.int_value = -1;
EXPECT_TRUE(-1 == object->compute_skeys_for_join_frame(NULL, 0, nonce, 0, nwk_key, app_key));
aes_stub.int_zero_counter = 1;
aes_stub.int_value = -2;
EXPECT_TRUE(-2 == object->compute_skeys_for_join_frame(NULL, 0, nonce, 0, nwk_key, app_key));
aes_stub.int_zero_counter = 0;
aes_stub.int_value = 0;
EXPECT_TRUE(0 == object->compute_skeys_for_join_frame(NULL, 0, nonce, 0, nwk_key, app_key));
}

View File

@ -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
)

View File

@ -0,0 +1,814 @@
/*
* 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 "LoRaPHY.h"
#include "LoRaWANTimer_stub.h"
class my_LoRaPHY : public LoRaPHY
{
public:
my_LoRaPHY(){phy_params.adr_ack_delay = 1;}
virtual ~my_LoRaPHY(){}
loraphy_params_t &get_phy_params() {
return phy_params;
}
};
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){return uint8_value;};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
uint8_t uint8_value;
};
class Test_LoRaPHY : public testing::Test {
protected:
my_LoRaPHY *object;
virtual void SetUp()
{
object = new my_LoRaPHY();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaPHY, initialize)
{
object->initialize(NULL);
}
TEST_F(Test_LoRaPHY, set_radio_instance)
{
my_radio radio;
object->set_radio_instance(radio);
}
TEST_F(Test_LoRaPHY, put_radio_to_sleep)
{
my_radio radio;
object->set_radio_instance(radio);
object->put_radio_to_sleep();
}
TEST_F(Test_LoRaPHY, put_radio_to_standby)
{
my_radio radio;
object->set_radio_instance(radio);
object->put_radio_to_standby();
}
TEST_F(Test_LoRaPHY, handle_receive)
{
my_radio radio;
object->set_radio_instance(radio);
object->handle_receive();
}
TEST_F(Test_LoRaPHY, handle_send)
{
my_radio radio;
object->set_radio_instance(radio);
object->handle_send(NULL, 0);
}
TEST_F(Test_LoRaPHY, setup_public_network_mode)
{
my_radio radio;
channel_params_t p;
object->get_phy_params().channels.channel_list = &p;
object->set_radio_instance(radio);
object->setup_public_network_mode(false);
}
TEST_F(Test_LoRaPHY, get_radio_rng)
{
my_radio radio;
object->set_radio_instance(radio);
EXPECT_TRUE(0 != object->get_radio_rng());
}
TEST_F(Test_LoRaPHY, calculate_backoff)
{
channel_params_t p[1];
p[0].band = 0;
object->get_phy_params().channels.channel_list = p;
band_t b[1];
object->get_phy_params().bands.table = b;
object->calculate_backoff(false, false, false, 0, 10, 12);
object->calculate_backoff(false, true, false, 0, 3600000 + 10, 12);
object->calculate_backoff(false, false, true, 0, 3600000 + 36000000 + 10, 12);
}
TEST_F(Test_LoRaPHY, mask_bit_test)
{
uint16_t buf;
EXPECT_TRUE(!object->mask_bit_test(&buf, 0));
}
TEST_F(Test_LoRaPHY, mask_bit_set)
{
uint16_t buf;
object->mask_bit_set(&buf, 3);
}
TEST_F(Test_LoRaPHY, mask_bit_clear)
{
uint16_t buf;
object->mask_bit_clear(&buf, 0);
}
TEST_F(Test_LoRaPHY, request_new_channel)
{
channel_params_t p;
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
p.frequency = 0;
object->get_phy_params().custom_channelplans_supported = true;
uint16_t list;
object->get_phy_params().channels.default_mask = &list;
channel_params_t pp;
object->get_phy_params().channels.channel_list = &pp;
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
//Default
p.frequency = 2;
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
//Freq & DR invalid
object->get_phy_params().max_channel_cnt = 2;
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
//Freq invalid
pp.frequency = 0;
object->get_phy_params().default_max_datarate = 1;
object->get_phy_params().max_tx_datarate = 8;
p.dr_range.fields.max = 2;
p.dr_range.fields.min = 0;
object->get_phy_params().default_channel_cnt = 3;
EXPECT_TRUE(2 == object->request_new_channel(0, &p));
//DR invalid
pp.frequency = 2;
p.band = 0;
object->get_phy_params().bands.size = 1;
band_t b;
object->get_phy_params().bands.table = &b;
b.higher_band_freq = 5;
b.lower_band_freq = 1;
p.dr_range.fields.max = 12;
p.dr_range.fields.min = 1;
EXPECT_TRUE(1 == object->request_new_channel(0, &p));
//STATUS_OK
p.dr_range.fields.max = 2;
uint16_t list2[16];
p.dr_range.fields.min = 0;
object->get_phy_params().channels.mask = list2;
EXPECT_TRUE(3 == object->request_new_channel(0, &p));
}
TEST_F(Test_LoRaPHY, set_last_tx_done)
{
channel_params_t p[1];
p[0].band = 0;
object->get_phy_params().channels.channel_list = p;
band_t b[1];
object->get_phy_params().bands.table = b;
object->set_last_tx_done(0, false, 0);
object->set_last_tx_done(0, true, 0);
}
TEST_F(Test_LoRaPHY, restore_default_channels)
{
channel_params_t p[1];
p[0].band = 0;
object->get_phy_params().channels.channel_list = p;
uint16_t m, dm;
object->get_phy_params().channels.mask_size = 1;
object->get_phy_params().channels.default_mask = &dm;
object->get_phy_params().channels.mask = &m;
object->restore_default_channels();
}
TEST_F(Test_LoRaPHY, apply_cf_list)
{
uint8_t list[16];
object->apply_cf_list(list, 0);
object->get_phy_params().cflist_supported = true;
object->apply_cf_list(list, 0);
object->get_phy_params().default_channel_cnt = 2;
object->get_phy_params().cflist_channel_cnt = 0;
object->get_phy_params().max_channel_cnt = 3;
uint16_t mask[8];
channel_params_t p[8];
object->get_phy_params().channels.default_mask = mask;
object->get_phy_params().channels.mask = mask;
object->get_phy_params().channels.channel_list = p;
object->apply_cf_list(list, 16);
list[1] = 15;
object->get_phy_params().cflist_channel_cnt = 1;
object->apply_cf_list(list, 16);
}
TEST_F(Test_LoRaPHY, get_next_ADR)
{
int8_t i = 0;
int8_t j = 0;
uint32_t ctr = 0;
object->get_phy_params().min_tx_datarate = 0;
EXPECT_TRUE(!object->get_next_ADR(false, i, j, ctr));
i = 1;
object->get_phy_params().adr_ack_limit = 3;
EXPECT_TRUE(!object->get_next_ADR(false, i, j, ctr));
object->get_phy_params().adr_ack_limit = 3;
ctr = 4;
object->get_phy_params().max_tx_power = 2;
object->get_phy_params().adr_ack_delay = 1;
EXPECT_TRUE(object->get_next_ADR(true, i, j, ctr));
ctr = 5;
object->get_phy_params().adr_ack_delay = 2;
EXPECT_TRUE(!object->get_next_ADR(true, i, j, ctr));
}
TEST_F(Test_LoRaPHY, rx_config)
{
my_radio radio;
object->set_radio_instance(radio);
uint8_t list;
object->get_phy_params().datarates.table = &list;
uint8_t list2;
object->get_phy_params().payloads_with_repeater.table = &list2;
rx_config_params_t p;
p.datarate = 0;
p.rx_slot = RX_SLOT_WIN_1;
channel_params_t pp[1];
object->get_phy_params().channels.channel_list = pp;
pp[0].rx1_frequency = 2;
p.channel = 0;
uint8_t tab[8];
object->get_phy_params().payloads.table = tab;
object->get_phy_params().payloads_with_repeater.table = tab;
EXPECT_TRUE(object->rx_config(&p));
p.datarate = DR_7;
p.is_repeater_supported = true;
object->get_phy_params().fsk_supported = true;
EXPECT_TRUE(object->rx_config(&p));
}
TEST_F(Test_LoRaPHY, compute_rx_win_params)
{
uint32_t list[1];
list[0] = 0;
object->get_phy_params().bandwidths.table = list;
uint8_t list2;
object->get_phy_params().datarates.table = &list2;
rx_config_params_t p;
object->compute_rx_win_params(0, 0, 0, &p);
p.datarate = 0;
list[0] = 125000;
object->compute_rx_win_params(0, 0, 0, &p);
list[0] = 250000;
object->compute_rx_win_params(0, 0, 0, &p);
list[0] = 500000;
object->get_phy_params().fsk_supported = true;
object->get_phy_params().max_rx_datarate = 0;
object->compute_rx_win_params(0, 0, 0, &p);
}
TEST_F(Test_LoRaPHY, tx_config)
{
band_t b;
object->get_phy_params().bands.table = &b;
channel_params_t pp;
pp.band=0;
object->get_phy_params().channels.channel_list = &pp;
uint32_t list = 0;
object->get_phy_params().bandwidths.table = &list;
uint8_t list2;
object->get_phy_params().datarates.table = &list2;
my_radio radio;
object->set_radio_instance(radio);
tx_config_params_t p;
p.channel=0;
int8_t i;
lorawan_time_t t;
object->tx_config(&p, &i, &t);
p.datarate = 8;
object->get_phy_params().max_tx_datarate = 8;
object->tx_config(&p, &i, &t);
}
TEST_F(Test_LoRaPHY, link_ADR_request)
{
adr_req_params_t p;
uint8_t b[100];
p.payload = b;
b[0] = 0x03;
b[1] = 1;
b[2] = 0;
b[3] = 0;
b[4] = 1 << 4;
b[5] = 0x03;
b[6] = 1;
b[7] = 1;
b[8] = 1;
b[9] = 6 << 4;
b[10] = 0x03;
b[11] = 1;
b[12] = 0xff;
b[13] = 0xff;
b[14] = 0;
b[15] = 0;
p.payload_size = 16;
int8_t i, j;
uint8_t k, l;
uint8_t t[5];
t[0] = 0;
object->get_phy_params().datarates.size = 1;
object->get_phy_params().datarates.table = t;
//Test without ADR payload does not make sense here.
object->get_phy_params().max_channel_cnt = 2;
channel_params_t li[4];
object->get_phy_params().channels.channel_list = li;
li[0].frequency = 0;
li[1].frequency = 5;
EXPECT_TRUE(4 == object->link_ADR_request(&p, &i, &j, &k, &l));
t[0] = 3;
//verify adr with p.adr_enabled = false
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
p.current_nb_rep = 0;
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
p.adr_enabled = true;
li[0].dr_range.value = 0xff;
object->get_phy_params().min_tx_datarate = DR_3;
object->get_phy_params().max_tx_datarate = DR_8;
//verify adr with status != 0
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
object->get_phy_params().max_tx_power = 2;
object->get_phy_params().min_tx_power = 6;
//verify adr with status != 0
EXPECT_TRUE(4 == object->link_ADR_request(&p, &i, &j, &k, &l));
object->get_phy_params().min_tx_datarate = DR_0;
li[0].dr_range.value = 0xf0;
EXPECT_TRUE(6 == object->link_ADR_request(&p, &i, &j, &k, &l));
li[1].dr_range.fields.min = DR_0;
li[1].dr_range.fields.max = DR_13;
b[4] = 6 << 4;
p.payload_size = 5;
EXPECT_TRUE(7 == object->link_ADR_request(&p, &i, &j, &k, &l));
uint16_t mask[2];
object->get_phy_params().channels.mask = mask;
object->get_phy_params().channels.mask_size = 2;
EXPECT_TRUE(7 == object->link_ADR_request(&p, &i, &j, &k, &l));
li[0].dr_range.value = 0xff;
object->get_phy_params().max_channel_cnt = 0;
EXPECT_TRUE(5 == object->link_ADR_request(&p, &i, &j, &k, &l));
b[0] = 0x03;
b[1] = 1;
b[2] = 0;
b[3] = 0;
b[4] = 0;
t[0] = 0;
object->get_phy_params().datarates.size = 1;
object->get_phy_params().datarates.table = t;
//Test without ADR payload does not make sense here.
object->get_phy_params().max_channel_cnt = 2;
li[0].frequency = 0;
li[1].frequency = 5;
EXPECT_TRUE(4 == object->link_ADR_request(&p, &i, &j, &k, &l));
}
TEST_F(Test_LoRaPHY, accept_rx_param_setup_req)
{
my_radio radio;
object->set_radio_instance(radio);
rx_param_setup_req_t req;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&req));
}
TEST_F(Test_LoRaPHY, accept_tx_param_setup_req)
{
my_radio radio;
object->set_radio_instance(radio);
object->get_phy_params().accept_tx_param_setup_req = true;
EXPECT_TRUE(object->accept_tx_param_setup_req(0, 0));
}
TEST_F(Test_LoRaPHY, dl_channel_request)
{
EXPECT_TRUE(0 == object->dl_channel_request(0, 0));
object->get_phy_params().dl_channel_req_supported = true;
object->get_phy_params().bands.size = 1;
band_t t[1];
object->get_phy_params().bands.table = t;
channel_params_t p[4];
object->get_phy_params().channels.channel_list = p;
p[0].frequency = 0;
EXPECT_TRUE(0 == object->dl_channel_request(0, 1));
t[0].higher_band_freq = 19;
t[0].lower_band_freq = 0;
p[0].frequency = 1;
EXPECT_TRUE(3 == object->dl_channel_request(0, 1));
}
TEST_F(Test_LoRaPHY, get_alternate_DR)
{
EXPECT_TRUE(0 == object->get_alternate_DR(0));
object->get_phy_params().default_max_datarate = 5;
object->get_phy_params().min_tx_datarate = 4;
EXPECT_TRUE(5 == object->get_alternate_DR(1));
object->get_phy_params().default_max_datarate = 6;
object->get_phy_params().min_tx_datarate = 4;
EXPECT_TRUE(5 == object->get_alternate_DR(2));
}
TEST_F(Test_LoRaPHY, set_next_channel)
{
channel_selection_params_t p;
uint8_t ch;
lorawan_time_t t1;
lorawan_time_t t2;
p.aggregate_timeoff = 10000;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
uint16_t list[16];
list[4] = 1;
memcpy(list, "\0", 16);
object->get_phy_params().channels.mask = list;
object->get_phy_params().channels.mask_size = 1;
p.aggregate_timeoff = 10000;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
LoRaWANTimer_stub::time_value = 20000;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&p, &ch, &t1, &t2));
p.joined = false;
p.dc_enabled = false;
band_t b[4];
object->get_phy_params().bands.size = 2;
object->get_phy_params().bands.table = &b;
b[0].off_time = 0;
b[1].off_time = 9999999;
list[4] = 0;
object->get_phy_params().channels.mask_size = 128;
p.current_datarate = DR_1;
object->get_phy_params().max_channel_cnt = 4;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&p, &ch, &t1, &t2));
p.dc_enabled = true;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&p, &ch, &t1, &t2));
list[4] = 1;
p.joined = true;
p.dc_enabled = false;
channel_params_t l[4];
l[0].dr_range.value = 0xff;
l[1].dr_range.value = 0xff;
l[2].dr_range.value = 0xf0;
l[3].dr_range.value = 0xf0;
l[2].band = 2;
l[3].band = 3;
object->get_phy_params().channels.channel_list = l;
list[0] = 0xFF;
b[2].off_time = 9999999;
b[3].off_time = 0;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&p, &ch, &t1, &t2));
b[0].off_time = 10000;
LoRaWANTimer_stub::time_value = 2000;
p.aggregate_timeoff = 1000;
p.dc_enabled = true;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&p, &ch, &t1, &t2));
}
TEST_F(Test_LoRaPHY, add_channel)
{
uint16_t list[16];
object->get_phy_params().channels.mask = list;
object->get_phy_params().channels.default_mask = list;
channel_params_t p;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->add_channel(&p, 0));
object->get_phy_params().custom_channelplans_supported = true;
object->get_phy_params().max_channel_cnt = 2;
object->get_phy_params().min_tx_datarate = 0;
object->get_phy_params().max_tx_datarate = 13;
p.dr_range.fields.min = 6;
p.dr_range.fields.max = 1;
EXPECT_TRUE(LORAWAN_STATUS_FREQ_AND_DR_INVALID == object->add_channel(&p, 0));
}
TEST_F(Test_LoRaPHY, remove_channel)
{
channel_params_t pp;
pp.band=0;
object->get_phy_params().channels.channel_list = &pp;
uint16_t list[16];
list[0] = 1;
object->get_phy_params().channels.mask = list;
object->get_phy_params().channels.default_mask = list;
EXPECT_TRUE(false == object->remove_channel(0));
list[0] = 0;
EXPECT_TRUE(false == object->remove_channel(0));
object->get_phy_params().channels.mask_size = 1;
object->get_phy_params().max_channel_cnt = 0;
EXPECT_TRUE(false == object->remove_channel(0));
object->get_phy_params().max_channel_cnt = 1;
EXPECT_TRUE(true == object->remove_channel(0));
}
TEST_F(Test_LoRaPHY, set_tx_cont_mode)
{
channel_params_t pp;
pp.band=0;
object->get_phy_params().channels.channel_list = &pp;
band_t b;
object->get_phy_params().bands.table = &b;
my_radio radio;
object->set_radio_instance(radio);
cw_mode_params_t p;
p.max_eirp = 0;
p.channel=0;
object->set_tx_cont_mode(&p);
p.max_eirp = 1;
p.antenna_gain = 1;
object->set_tx_cont_mode(&p, 1);
}
TEST_F(Test_LoRaPHY, apply_DR_offset)
{
EXPECT_TRUE(0 == object->apply_DR_offset(0, 0));
object->get_phy_params().min_tx_datarate = 1;
EXPECT_TRUE(1 == object->apply_DR_offset(0, 2));
}
TEST_F(Test_LoRaPHY, reset_to_default_values)
{
loramac_protocol_params p;
object->reset_to_default_values(&p);
object->reset_to_default_values(&p, true);
}
TEST_F(Test_LoRaPHY, get_next_lower_tx_datarate)
{
EXPECT_TRUE(DR_0 == object->get_next_lower_tx_datarate(DR_2));
object->get_phy_params().ul_dwell_time_setting = 1;
object->get_phy_params().dwell_limit_datarate = DR_1;
EXPECT_TRUE(DR_1 == object->get_next_lower_tx_datarate(DR_2));
}
TEST_F(Test_LoRaPHY, get_minimum_rx_datarate)
{
EXPECT_TRUE(DR_0 == object->get_minimum_rx_datarate());
object->get_phy_params().dl_dwell_time_setting = 1;
object->get_phy_params().dwell_limit_datarate = DR_1;
EXPECT_TRUE(DR_1 == object->get_minimum_rx_datarate());
}
TEST_F(Test_LoRaPHY, get_minimum_tx_datarate)
{
EXPECT_TRUE(DR_0 == object->get_minimum_tx_datarate());
object->get_phy_params().ul_dwell_time_setting = 1;
object->get_phy_params().dwell_limit_datarate = DR_1;
EXPECT_TRUE(DR_1 == object->get_minimum_tx_datarate());
}
TEST_F(Test_LoRaPHY, get_default_tx_datarate)
{
EXPECT_TRUE(0 == object->get_default_tx_datarate());
}
TEST_F(Test_LoRaPHY, get_default_max_tx_datarate)
{
EXPECT_TRUE(DR_0 == object->get_default_max_tx_datarate());
}
TEST_F(Test_LoRaPHY, get_default_tx_power)
{
EXPECT_TRUE(0 == object->get_default_tx_power());
}
TEST_F(Test_LoRaPHY, get_max_payload)
{
uint8_t list=8;
object->get_phy_params().payloads.table = &list;
object->get_phy_params().payloads_with_repeater.table = &list;
EXPECT_TRUE(8 == object->get_max_payload(0));
EXPECT_TRUE(8 == object->get_max_payload(0, true));
}
TEST_F(Test_LoRaPHY, get_maximum_frame_counter_gap)
{
EXPECT_TRUE(0 == object->get_maximum_frame_counter_gap());
}
TEST_F(Test_LoRaPHY, get_ack_timeout)
{
EXPECT_TRUE(0 == object->get_ack_timeout());
}
TEST_F(Test_LoRaPHY, get_default_rx2_frequency)
{
EXPECT_TRUE(0 == object->get_default_rx2_frequency());
}
TEST_F(Test_LoRaPHY, get_default_rx2_datarate)
{
EXPECT_TRUE(0 == object->get_default_rx2_datarate());
}
TEST_F(Test_LoRaPHY, get_channel_mask)
{
EXPECT_TRUE(0 == object->get_channel_mask());
EXPECT_TRUE(0 == object->get_channel_mask(true));
}
TEST_F(Test_LoRaPHY, get_max_nb_channels)
{
EXPECT_TRUE(0 == object->get_max_nb_channels());
}
TEST_F(Test_LoRaPHY, get_phy_channels)
{
EXPECT_TRUE(0 == object->get_phy_channels());
}
TEST_F(Test_LoRaPHY, is_custom_channel_plan_supported)
{
EXPECT_TRUE(false == object->is_custom_channel_plan_supported());
}
TEST_F(Test_LoRaPHY, verify_rx_datarate)
{
EXPECT_TRUE(false == object->verify_rx_datarate(0));
object->get_phy_params().datarates.size = 1;
uint8_t t[1];
t[0] = 2;
object->get_phy_params().datarates.table = t;
object->get_phy_params().dl_dwell_time_setting = 0;
EXPECT_TRUE(true == object->verify_rx_datarate(0));
object->get_phy_params().dl_dwell_time_setting = 1;
object->get_phy_params().min_rx_datarate = 0;
EXPECT_TRUE(true == object->verify_rx_datarate(0));
}
TEST_F(Test_LoRaPHY, verify_tx_datarate)
{
EXPECT_TRUE(false == object->verify_tx_datarate(0));
object->get_phy_params().datarates.size = 1;
uint8_t t[1];
t[0] = 2;
object->get_phy_params().datarates.table = t;
object->get_phy_params().ul_dwell_time_setting = 0;
EXPECT_TRUE(true == object->verify_tx_datarate(0));
object->get_phy_params().ul_dwell_time_setting = 1;
EXPECT_TRUE(true == object->verify_tx_datarate(0));
object->get_phy_params().ul_dwell_time_setting = 1;
EXPECT_TRUE(true == object->verify_tx_datarate(0, true));
}
TEST_F(Test_LoRaPHY, verify_tx_power)
{
EXPECT_TRUE(true == object->verify_tx_power(0));
}
TEST_F(Test_LoRaPHY, verify_duty_cycle)
{
EXPECT_TRUE(true == object->verify_duty_cycle(false));
EXPECT_TRUE(false == object->verify_duty_cycle(true));
}
TEST_F(Test_LoRaPHY, verify_nb_join_trials)
{
EXPECT_TRUE(false == object->verify_nb_join_trials(0));
EXPECT_TRUE(true == object->verify_nb_join_trials(100));
}

View File

@ -0,0 +1,41 @@
#[[
* 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_LoRaPHY")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHY.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphy/Test_LoRaPHY.cpp
stubs/LoRaWANTimer_stub.cpp
stubs/mbed_assert_stub.c
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 -DMBED_CONF_LORA_DUTY_CYCLE_ON_JOIN=true")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 -DMBED_CONF_LORA_DUTY_CYCLE_ON_JOIN=true")

View File

@ -0,0 +1,143 @@
/*
* 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 "LoRaPHYAS923.h"
#include "LoRaPHY_stub.h"
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){return uint8_value;};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
uint8_t uint8_value;
};
class Test_LoRaPHYAS923 : public testing::Test {
protected:
LoRaPHYAS923 *object;
my_radio radio;
virtual void SetUp()
{
LoRaPHY_stub::radio = &radio;
object = new LoRaPHYAS923();
}
virtual void TearDown()
{
LoRaPHY_stub::radio = NULL;
delete object;
}
};
TEST_F(Test_LoRaPHYAS923, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaPHYAS923, get_alternate_DR)
{
EXPECT_TRUE(2 == object->get_alternate_DR(1));
}
TEST_F(Test_LoRaPHYAS923, set_next_channel)
{
channel_selection_params_t next_channel;
lorawan_time_t backoff_time = 0;
lorawan_time_t time = 0;
uint8_t ch = 1;
next_channel.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
next_channel.aggregate_timeoff = 1;
radio.bool_value = false;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
next_channel.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 1;
EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
radio.bool_value = true;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
}
TEST_F(Test_LoRaPHYAS923, apply_DR_offset)
{
//0, 1, 2, 3, 4, 5, -1, -2
for (int i=0; i < 8; i++) {
uint8_t val = i>5?5:2;
EXPECT_TRUE(object->apply_DR_offset(0, i));
}
}

View File

@ -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_LoRaPHYAS923")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYAS923.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphyas923/Test_LoRaPHYAS923.cpp
stubs/LoRaPHY_stub.cpp
stubs/LoRaWANTimer_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -0,0 +1,231 @@
/*
* 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 "LoRaPHYAU915.h"
#include "LoRaPHY_stub.h"
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){return uint8_value;};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
uint8_t uint8_value;
};
class Test_LoRaPHYAU915 : public testing::Test {
protected:
LoRaPHYAU915 *object;
my_radio radio;
virtual void SetUp()
{
LoRaPHY_stub::radio = &radio;
object = new LoRaPHYAU915();
}
virtual void TearDown()
{
LoRaPHY_stub::radio = NULL;
delete object;
}
};
TEST_F(Test_LoRaPHYAU915, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaPHYAU915, rx_config)
{
rx_config_params_t p;
radio.uint8_value = 1;
EXPECT_TRUE(!object->rx_config(&p));
radio.uint8_value = 0;
p.is_repeater_supported = true;
EXPECT_TRUE(object->rx_config(&p));
p.is_repeater_supported = false;
EXPECT_TRUE(object->rx_config(&p));
}
TEST_F(Test_LoRaPHYAU915, tx_config)
{
tx_config_params_t p;
int8_t tx;
lorawan_time_t time;
p.tx_power = 9;
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
}
TEST_F(Test_LoRaPHYAU915, link_ADR_request)
{
adr_req_params_t params;
int8_t dr_out;
int8_t tx_power_out;
uint8_t nb_rep_out;
uint8_t nb_bytes_parsed;
LoRaPHY_stub::uint8_value = 1;
LoRaPHY_stub::ch_mask_value = 6;
LoRaPHY_stub::adr_parse_count = 2;
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 7;
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 5;
LoRaPHY_stub::uint8_value = 6;
EXPECT_TRUE(6 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 66;
LoRaPHY_stub::uint8_value = 7;
EXPECT_TRUE(7 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
}
TEST_F(Test_LoRaPHYAU915, accept_rx_param_setup_req)
{
rx_param_setup_req_t p;
radio.bool_value = false;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 923300000 - 1;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 927500000 + 1;
p.datarate = 6;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 923300000 + 600000;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
LoRaPHY_stub::bool_table[1] = true;
EXPECT_TRUE(7 == object->accept_rx_param_setup_req(&p));
}
TEST_F(Test_LoRaPHYAU915, get_alternate_DR)
{
EXPECT_TRUE(0 == object->get_alternate_DR(0));
EXPECT_TRUE(6 == object->get_alternate_DR(1));
}
TEST_F(Test_LoRaPHYAU915, set_next_channel)
{
channel_selection_params_t params;
uint8_t channel;
lorawan_time_t time;
lorawan_time_t timeoff;
params.current_datarate = 6;
params.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&params, &channel, &time, &timeoff));
radio.bool_value = false;
params.aggregate_timeoff = 1;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&params, &channel, &time, &timeoff));
params.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 1;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&params, &channel, &time, &timeoff));
}
TEST_F(Test_LoRaPHYAU915, apply_DR_offset)
{
// { DR_8, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_0
// { DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1
// { DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2
// { DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3
// { DR_12, DR_11, DR_10, DR_9, DR_8, DR_8 }, // DR_4
// { DR_13, DR_12, DR_11, DR_10, DR_9, DR_8 }, // DR_5
// { DR_13, DR_13, DR_12, DR_11, DR_10, DR_9 }, // DR_6
for (int i = 0; i < 7; i++) {
for (int j=0; j < 6; j++ ) {
uint8_t val = 8 + i;
val -= j;
if (val > 13) val = 13;
if (val < 8) val = 8;
EXPECT_TRUE(val == object->apply_DR_offset(i, j));
}
}
}

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.
]]
# Unit test suite name
set(TEST_SUITE_NAME "lorawan_LoRaPHYAU915")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYAU915.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphyau915/Test_LoRaPHYAU915.cpp
stubs/LoRaPHY_stub.cpp
stubs/LoRaWANTimer_stub.cpp
stubs/mbed_assert_stub.c
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_FSB_MASK=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_FSB_MASK=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")

View File

@ -0,0 +1,199 @@
/*
* 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 "LoRaPHYCN470.h"
#include "LoRaPHY_stub.h"
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){return uint8_value;};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
uint8_t uint8_value;
};
class Test_LoRaPHYCN470 : public testing::Test {
protected:
LoRaPHYCN470 *object;
my_radio radio;
virtual void SetUp()
{
LoRaPHY_stub::radio = &radio;
object = new LoRaPHYCN470();
}
virtual void TearDown()
{
LoRaPHY_stub::radio = NULL;
delete object;
}
};
TEST_F(Test_LoRaPHYCN470, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaPHYCN470, set_next_channel)
{
channel_selection_params_t params;
uint8_t channel;
lorawan_time_t time;
lorawan_time_t timeoff;
params.current_datarate = 4;
params.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&params, &channel, &time, &timeoff));
radio.bool_value = false;
params.aggregate_timeoff = 1;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&params, &channel, &time, &timeoff));
params.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 1;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&params, &channel, &time, &timeoff));
}
TEST_F(Test_LoRaPHYCN470, rx_config)
{
rx_config_params_t p;
radio.uint8_value = 1;
EXPECT_TRUE(!object->rx_config(&p));
radio.uint8_value = 0;
p.is_repeater_supported = true;
EXPECT_TRUE(object->rx_config(&p));
p.is_repeater_supported = false;
EXPECT_TRUE(object->rx_config(&p));
}
TEST_F(Test_LoRaPHYCN470, tx_config)
{
tx_config_params_t p;
int8_t tx;
lorawan_time_t time;
p.tx_power = 9;
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
}
TEST_F(Test_LoRaPHYCN470, link_ADR_request)
{
adr_req_params_t params;
int8_t dr_out;
int8_t tx_power_out;
uint8_t nb_rep_out;
uint8_t nb_bytes_parsed;
LoRaPHY_stub::uint8_value = 1;
LoRaPHY_stub::ch_mask_value = 6;
LoRaPHY_stub::adr_parse_count = 2;
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 7;
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 5;
LoRaPHY_stub::uint8_value = 6;
EXPECT_TRUE(6 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 66;
LoRaPHY_stub::uint8_value = 7;
EXPECT_TRUE(7 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
}
TEST_F(Test_LoRaPHYCN470, accept_rx_param_setup_req)
{
rx_param_setup_req_t p;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 923300000 - 1;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 927500000 + 1;
p.datarate = 6;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p));
}

View File

@ -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_LoRaPHYCN470")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYCN470.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphycn470/Test_LoRaPHYCN470.cpp
stubs/LoRaPHY_stub.cpp
stubs/LoRaWANTimer_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -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 "LoRaPHYCN779.h"
class Test_LoRaPHYCN779 : public testing::Test {
protected:
LoRaPHYCN779 *object;
virtual void SetUp()
{
object = new LoRaPHYCN779();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaPHYCN779, constructor)
{
EXPECT_TRUE(object);
}

View File

@ -0,0 +1,42 @@
#[[
* 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_LoRaPHYCN779")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYCN779.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphycn779/Test_LoRaPHYCN779.cpp
stubs/LoRaPHY_stub.cpp
stubs/mbed_assert_stub.c
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_FSB_MASK_CHINA=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_FSB_MASK_CHINA=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")

View File

@ -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 "LoRaPHYEU433.h"
class Test_LoRaPHYEU433 : public testing::Test {
protected:
LoRaPHYEU433 *object;
virtual void SetUp()
{
object = new LoRaPHYEU433();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaPHYEU433, constructor)
{
EXPECT_TRUE(object);
}

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.
]]
# Unit test suite name
set(TEST_SUITE_NAME "lorawan_LoRaPHYEU433")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYEU433.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphyeu433/Test_LoRaPHYEU433.cpp
stubs/LoRaPHY_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -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 "LoRaPHYEU868.h"
class Test_LoRaPHYEU868 : public testing::Test {
protected:
LoRaPHYEU868 *object;
virtual void SetUp()
{
object = new LoRaPHYEU868();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaPHYEU868, constructor)
{
EXPECT_TRUE(object);
}

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.
]]
# Unit test suite name
set(TEST_SUITE_NAME "lorawan_LoRaPHYEU868")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYEU868.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphyeu868/Test_LoRaPHYEU868.cpp
stubs/LoRaPHY_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -0,0 +1,47 @@
/*
* 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 "LoRaPHYIN865.h"
class Test_LoRaPHYIN865 : public testing::Test {
protected:
LoRaPHYIN865 *object;
virtual void SetUp()
{
object = new LoRaPHYIN865();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaPHYIN865, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaPHYIN865, apply_DR_offset)
{
EXPECT_TRUE(0 == object->apply_DR_offset(0, 0));
}

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.
]]
# Unit test suite name
set(TEST_SUITE_NAME "lorawan_LoRaPHYIN865")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYIN865.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphyin865/Test_LoRaPHYIN865.cpp
stubs/LoRaPHY_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -0,0 +1,156 @@
/*
* 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 "LoRaPHYKR920.h"
#include "LoRaPHY_stub.h"
#include "LoRaRadio.h"
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
};
class Test_LoRaPHYKR920 : public testing::Test {
protected:
LoRaPHYKR920 *object;
my_radio radio;
virtual void SetUp()
{
LoRaPHY_stub::radio = &radio;
object = new LoRaPHYKR920();
}
virtual void TearDown()
{
LoRaPHY_stub::radio = NULL;
delete object;
}
};
TEST_F(Test_LoRaPHYKR920, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaPHYKR920, verify_frequency_for_band)
{
radio.bool_value = false;
EXPECT_TRUE(false == object->verify_frequency_for_band(0, 0));
radio.bool_value = true;
EXPECT_TRUE(false == object->verify_frequency_for_band(0, 0));
EXPECT_TRUE(true == object->verify_frequency_for_band(921100000, 0));
}
TEST_F(Test_LoRaPHYKR920, tx_config)
{
tx_config_params_t tx_config;
int8_t tx_power = 0;
lorawan_time_t time;
tx_config.tx_power = 9;
EXPECT_TRUE(true == object->tx_config(&tx_config, &tx_power, &time));
}
TEST_F(Test_LoRaPHYKR920, set_next_channel)
{
channel_selection_params_t next_channel;
lorawan_time_t backoff_time = 0;
lorawan_time_t time = 0;
uint8_t ch = 1;
next_channel.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
next_channel.aggregate_timeoff = 1;
radio.bool_value = false;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
next_channel.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 1;
EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
radio.bool_value = true;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
}
TEST_F(Test_LoRaPHYKR920, set_tx_cont_mode)
{
cw_mode_params_t params;
params.tx_power = 9;
object->set_tx_cont_mode(&params, 0);
}

View File

@ -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_LoRaPHYKR920")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYKR920.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphykr920/Test_LoRaPHYKR920.cpp
stubs/LoRaPHY_stub.cpp
stubs/LoRaWANTimer_stub.cpp
stubs/mbed_assert_stub.c
)

View File

@ -0,0 +1,235 @@
/*
* 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 "LoRaPHYUS915.h"
#include "LoRaPHY_stub.h"
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){return uint8_value;};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
uint8_t uint8_value;
};
class Test_LoRaPHYUS915 : public testing::Test {
protected:
LoRaPHYUS915 *object;
my_radio radio;
virtual void SetUp()
{
LoRaPHY_stub::radio = &radio;
object = new LoRaPHYUS915();
}
virtual void TearDown()
{
LoRaPHY_stub::radio = NULL;
delete object;
}
};
TEST_F(Test_LoRaPHYUS915, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaPHYUS915, restore_default_channels)
{
object->restore_default_channels();
}
TEST_F(Test_LoRaPHYUS915, rx_config)
{
rx_config_params_t p;
radio.uint8_value = 1;
EXPECT_TRUE(!object->rx_config(&p));
radio.uint8_value = 0;
p.is_repeater_supported = true;
EXPECT_TRUE(object->rx_config(&p));
p.is_repeater_supported = false;
EXPECT_TRUE(object->rx_config(&p));
}
TEST_F(Test_LoRaPHYUS915, tx_config)
{
tx_config_params_t p;
int8_t tx;
lorawan_time_t time;
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
}
TEST_F(Test_LoRaPHYUS915, link_ADR_request)
{
adr_req_params_t params;
int8_t dr_out;
int8_t tx_power_out;
uint8_t nb_rep_out;
uint8_t nb_bytes_parsed;
EXPECT_TRUE(0 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::uint8_value = 1;
LoRaPHY_stub::ch_mask_value = 6;
LoRaPHY_stub::adr_parse_count = 2;
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 7;
EXPECT_TRUE(1 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 5;
LoRaPHY_stub::uint8_value = 6;
EXPECT_TRUE(6 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
LoRaPHY_stub::adr_parse_count = 2;
LoRaPHY_stub::ch_mask_value = 66;
LoRaPHY_stub::uint8_value = 7;
EXPECT_TRUE(7 == object->link_ADR_request(&params, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
}
TEST_F(Test_LoRaPHYUS915, accept_rx_param_setup_req)
{
rx_param_setup_req_t p;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 923300000 - 1;
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
radio.bool_value = true;
p.frequency = 927500000 + 1;
p.datarate = 6;
LoRaPHY_stub::bool_counter = 0;
LoRaPHY_stub::bool_table[0] = true;
EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p));
}
TEST_F(Test_LoRaPHYUS915, get_alternate_DR)
{
EXPECT_TRUE(0 == object->get_alternate_DR(0));
EXPECT_TRUE(4 == object->get_alternate_DR(1));
}
TEST_F(Test_LoRaPHYUS915, set_next_channel)
{
channel_selection_params_t params;
uint8_t channel;
lorawan_time_t time;
lorawan_time_t timeoff;
params.current_datarate = 4;
params.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&params, &channel, &time, &timeoff));
radio.bool_value = false;
params.aggregate_timeoff = 1;
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&params, &channel, &time, &timeoff));
params.aggregate_timeoff = 0;
LoRaPHY_stub::uint8_value = 1;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&params, &channel, &time, &timeoff));
}
TEST_F(Test_LoRaPHYUS915, apply_DR_offset)
{
//10, 9, 8, 8
//11, 10, 9, 8
//12, 11, 10, 9
//13, 12, 11, 10
//13, 13, 12, 11
for (int i = 0; i < 5; i++) {
for (int j=0; j < 4; j++ ) {
uint8_t val = 10 + i;
val -= j;
if (val > 13) val = 13;
if (val < 8) val = 8;
EXPECT_TRUE(val == object->apply_DR_offset(i, j));
}
}
}
TEST_F(Test_LoRaPHYUS915, set_tx_cont_mode)
{
cw_mode_params_t p;
object->set_tx_cont_mode(&p, 0);
p.datarate = 4;
object->set_tx_cont_mode(&p, 0);
}

View File

@ -0,0 +1,42 @@
#[[
* 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_LoRaPHYUS915")
# Source files
set(unittest-sources
../features/lorawan/lorastack/phy/LoRaPHYUS915.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/lorastack/phy
)
# Test & stub files
set(unittest-test-sources
features/lorawan/loraphyus915/Test_LoRaPHYUS915.cpp
stubs/LoRaPHY_stub.cpp
stubs/LoRaWANTimer_stub.cpp
stubs/mbed_assert_stub.c
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_FSB_MASK=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_FSB_MASK=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")

View File

@ -0,0 +1,229 @@
/*
* 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 "LoRaWANInterface.h"
class my_radio : public LoRaRadio
{
public:
virtual void init_radio(radio_events_t *events){};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){};
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
};
class my_LoRaPHY : public LoRaPHY
{
public:
my_LoRaPHY(){};
virtual ~my_LoRaPHY(){};
};
class Test_LoRaWANInterface : public testing::Test {
protected:
LoRaWANInterface *object;
my_radio radio;
virtual void SetUp()
{
object = new LoRaWANInterface(radio);
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaWANInterface, constructor)
{
EXPECT_TRUE(object);
my_radio radio;
my_LoRaPHY phy;
LoRaWANInterface object(radio, phy);
}
TEST_F(Test_LoRaWANInterface, initialize)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL));
}
TEST_F(Test_LoRaWANInterface, connect)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect());
lorawan_connect_t conn;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
}
TEST_F(Test_LoRaWANInterface, disconnect)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->disconnect());
}
TEST_F(Test_LoRaWANInterface, add_link_check_request)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->add_link_check_request());
}
TEST_F(Test_LoRaWANInterface, remove_link_check_request)
{
object->remove_link_check_request();
}
TEST_F(Test_LoRaWANInterface, set_datarate)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_datarate(1));
}
TEST_F(Test_LoRaWANInterface, enable_adaptive_datarate)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->enable_adaptive_datarate());
}
TEST_F(Test_LoRaWANInterface, disable_adaptive_datarate)
{
object->disable_adaptive_datarate();
}
TEST_F(Test_LoRaWANInterface, set_confirmed_msg_retries)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_confirmed_msg_retries(1));
}
TEST_F(Test_LoRaWANInterface, set_channel_plan)
{
lorawan_channelplan_t plan;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_channel_plan(plan));
}
TEST_F(Test_LoRaWANInterface, get_channel_plan)
{
lorawan_channelplan_t plan;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_channel_plan(plan));
}
TEST_F(Test_LoRaWANInterface, remove_channel_plan)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->remove_channel_plan());
}
TEST_F(Test_LoRaWANInterface, remove_channel)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->remove_channel(1));
}
TEST_F(Test_LoRaWANInterface, send)
{
EXPECT_TRUE(0 == object->send(1, NULL, 0, 0));
}
TEST_F(Test_LoRaWANInterface, receive)
{
EXPECT_TRUE(0 == object->receive(1, NULL, 0, 0));
uint8_t port;
int flags;
EXPECT_TRUE(0 == object->receive(NULL, 0, port, flags));
}
TEST_F(Test_LoRaWANInterface, add_app_callbacks)
{
lorawan_app_callbacks_t cbs;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->add_app_callbacks(&cbs));
}
TEST_F(Test_LoRaWANInterface, set_device_class)
{
object->set_device_class(CLASS_A);
}
TEST_F(Test_LoRaWANInterface, get_tx_metadata)
{
lorawan_tx_metadata data;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_tx_metadata(data));
}
TEST_F(Test_LoRaWANInterface, get_rx_metadata)
{
lorawan_rx_metadata data;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_rx_metadata(data));
}
TEST_F(Test_LoRaWANInterface, get_backoff_metadata)
{
int i;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_backoff_metadata(i));
}
TEST_F(Test_LoRaWANInterface, cancel_sending)
{
EXPECT_TRUE(LORAWAN_STATUS_OK == object->cancel_sending());
}

View File

@ -0,0 +1,51 @@
#[[
* 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_LoRaWANInterface")
# Source files
set(unittest-sources
../features/lorawan/LoRaWANInterface.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan
)
# Test & stub files
set(unittest-test-sources
features/lorawan/lorawaninterface/Test_LoRaWANInterface.cpp
stubs/LoRaPHY_stub.cpp
stubs/LoRaWANStack_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/LoRaPHYEU868_stub.cpp
)
# defines
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_PHY=\"EU868\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_PHY=\"EU868\"")

View File

@ -0,0 +1,865 @@
/*
* 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"
#include "EventQueue.h"
#include "LoRaPHY_stub.h"
#include "LoRaMac_stub.h"
#include "equeue_stub.h"
#include "lorawan_data_structures.h"
static uint8_t batt_level = 0;
using namespace events;
class my_LoRaPHY : public LoRaPHY
{
public:
my_LoRaPHY(){};
virtual ~my_LoRaPHY(){};
};
uint8_t my_cb()
{
return 1;
}
class my_radio : public LoRaRadio
{
public:
radio_events_t *_ev;
virtual void init_radio(radio_events_t *events){_ev = events;};
virtual void radio_reset(){};
virtual void sleep(void){};
virtual void standby(void){};
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
uint32_t datarate, uint8_t coderate,
uint32_t bandwidth_afc, uint16_t preamble_len,
uint16_t symb_timeout, bool fix_len,
uint8_t payload_len,
bool crc_on, bool freq_hop_on, uint8_t hop_period,
bool iq_inverted, bool rx_continuous){};
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
uint32_t bandwidth, uint32_t datarate,
uint8_t coderate, uint16_t preamble_len,
bool fix_len, bool crc_on, bool freq_hop_on,
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
virtual void send(uint8_t *buffer, uint8_t size){};
virtual void receive(void){};
virtual void set_channel(uint32_t freq){};
virtual uint32_t random(void){};
virtual uint8_t get_status(void){return uint8_value;};
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
virtual void set_public_network(bool enable){};
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time){ return bool_value;};
virtual void start_cad(void){};
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
virtual void lock(void){};
virtual void unlock(void){};
bool bool_value;
uint8_t uint8_value;
};
class Test_LoRaWANStack : public testing::Test {
protected:
LoRaWANStack *object;
virtual void SetUp()
{
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
object = new LoRaWANStack();
}
virtual void TearDown()
{
delete object;
}
};
TEST_F(Test_LoRaWANStack, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaWANStack, bind_phy_and_radio_driver)
{
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
}
TEST_F(Test_LoRaWANStack, initialize_mac_layer)
{
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->initialize_mac_layer(NULL));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
//Visit callback
if (LoRaMac_stub::_scheduling_failure_handler) {
LoRaMac_stub::_scheduling_failure_handler.call();
}
}
void events_cb(lorawan_event_t ev)
{
}
void lc_resp(uint8_t a, uint8_t b)
{
}
uint8_t batt_lvl()
{
return batt_level;
}
TEST_F(Test_LoRaWANStack, set_lora_callbacks)
{
lorawan_app_callbacks_t cb;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_lora_callbacks(&cb));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_lora_callbacks(NULL));
cb.events = NULL;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_lora_callbacks(&cb));
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
}
TEST_F(Test_LoRaWANStack, connect)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->connect());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_BUSY;
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect());
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect());
//_ctrl_flags & CONN_IN_PROGRESS_FLAG
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect());
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
//_ctrl_flags & CONNECTED_FLAG
EXPECT_TRUE(LORAWAN_STATUS_ALREADY_CONNECTED == object->connect());
//Visit rx_interrupt_handler's first if
radio._ev->rx_done(NULL, 65535, 0, 0);
}
TEST_F(Test_LoRaWANStack, connect_args)
{
lorawan_connect_t conn;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->connect(conn));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
conn.connect_type = lorawan_connect_type_t(8);
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->connect(conn));
LoRaMac_stub::status_value = LORAWAN_STATUS_BUSY;
conn.connect_type = LORAWAN_CONNECTION_OTAA;
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect(conn));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
//_ctrl_flags & CONN_IN_PROGRESS_FLAG
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect(conn));
object->shutdown();
conn.connect_type = LORAWAN_CONNECTION_ABP;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
//_ctrl_flags & CONNECTED_FLAG
EXPECT_TRUE(LORAWAN_STATUS_ALREADY_CONNECTED == object->connect(conn));
}
TEST_F(Test_LoRaWANStack, add_channels)
{
lorawan_channelplan_t plan;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->add_channels(plan));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->add_channels(plan));
}
TEST_F(Test_LoRaWANStack, remove_a_channel)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->remove_a_channel(1));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->remove_a_channel(1));
}
TEST_F(Test_LoRaWANStack, drop_channel_list)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->drop_channel_list());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->drop_channel_list());
}
TEST_F(Test_LoRaWANStack, get_enabled_channels)
{
lorawan_channelplan_t plan;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->get_enabled_channels(plan));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_enabled_channels(plan));
}
TEST_F(Test_LoRaWANStack, set_confirmed_msg_retry)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_confirmed_msg_retry(1));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_confirmed_msg_retry(255));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_confirmed_msg_retry(1));
}
TEST_F(Test_LoRaWANStack, set_channel_data_rate)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_channel_data_rate(4));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_channel_data_rate(4));
}
TEST_F(Test_LoRaWANStack, enable_adaptive_datarate)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->enable_adaptive_datarate(false));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->enable_adaptive_datarate(false));
}
TEST_F(Test_LoRaWANStack, handle_tx)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->handle_tx(0, NULL, 0, 0, true, false));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_tx(0, NULL, 0, 0, false, false));
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_link_check_request());
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_NO_ACTIVE_SESSIONS == object->handle_tx(0, NULL, 0, 0, true, false));
lorawan_connect_t conn;
conn.connect_type = LORAWAN_CONNECTION_ABP;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
LoRaMac_stub::bool_value = false;
EXPECT_TRUE(LORAWAN_STATUS_NO_NETWORK_JOINED == object->handle_tx(0, NULL, 0, 0, true, false));
LoRaMac_stub::bool_value = true;
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_tx(0, NULL, 0, 0, true, false));
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::bool_value = true;
//set_application_port fails
EXPECT_TRUE(LORAWAN_STATUS_PORT_INVALID == object->handle_tx(0, NULL, 0, 0, true, false));
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::bool_value = true;
//Wrong flags -> LORAWAN_STATUS_PARAMETER_INVALID
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_tx(1, NULL, 0, 0x04, true, false));
LoRaMac_stub::bool_false_counter = 1;
//Actual sending
EXPECT_TRUE(LORAWAN_STATUS_OK == object->handle_tx(1, NULL, 0, 0x08, true, false));
}
TEST_F(Test_LoRaWANStack, handle_rx)
{
uint8_t port;
int flags;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->handle_rx(NULL, 0, port, flags, false));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_NO_ACTIVE_SESSIONS == object->handle_rx(NULL, 0, port, flags, false));
lorawan_connect_t conn;
conn.connect_type = LORAWAN_CONNECTION_ABP;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(NULL, 0, port, flags, false));
//Prepare ready for receive state
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = false;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = true;
conf.req_type = MCPS_PROPRIETARY;
ind.pending = true;
LoRaMac_stub::dev_class_value = CLASS_C;
loramac_mlme_indication_t mlme_ind;
mlme_ind.pending = false;
LoRaMac_stub::mlme_ind_ptr = &mlme_ind;
uint8_t ind_buf[150];
for (int i= 0; i < 110; i++) {
ind_buf[i] = i;
}
ind.buffer = ind_buf;
ind.buffer_size = 150;
ind.type = MCPS_UNCONFIRMED;
radio._ev->rx_done(NULL, 0, 0, 0);
//data == NULL || LENGTH == 0 (2 cases)
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_rx(NULL, 0, port, flags, false));
uint8_t data[50];
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_rx(data, 0, port, flags, false));
//validate_params returns Would block
port = 43;
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
ind.type = MCPS_CONFIRMED;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
//Call again to visit send_automatic_uplink_message error case
LoRaMac_stub::bool_true_counter = 1;
ind.type = MCPS_CONFIRMED;
ind.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
ind.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = true;
//convert_to_msg_flag cases
ind.fpending_status = true;
ind.type = MCPS_PROPRIETARY;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
ind.type = MCPS_MULTICAST;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
ind.type = MCPS_UNCONFIRMED;
radio._ev->rx_done(NULL, 0, 0, 0);
//read not complete
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(10, data[10]);
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(60, data[10]);
//read complete
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(100, data[0]);
//read can fit the buffer
for (int i= 0; i < 110; i++) {
ind_buf[i] = i;
}
ind.buffer = ind_buf;
ind.buffer_size = 50;
ind.type = mcps_type_t(66);
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(10, data[10]);
}
TEST_F(Test_LoRaWANStack, set_link_check_request)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_link_check_request());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_link_check_request());
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_link_check_request());
}
TEST_F(Test_LoRaWANStack, remove_link_check_request)
{
object->remove_link_check_request();
}
TEST_F(Test_LoRaWANStack, shutdown)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->shutdown());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_DEVICE_OFF == object->shutdown());
}
TEST_F(Test_LoRaWANStack, set_device_class)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_device_class(CLASS_A));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_UNSUPPORTED == object->set_device_class(CLASS_B));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_device_class(CLASS_A));
//Visit callback
if (LoRaMac_stub::_ack_expiry_handler_for_class_c) {
LoRaMac_stub::_ack_expiry_handler_for_class_c.call();
}
}
TEST_F(Test_LoRaWANStack, acquire_tx_metadata)
{
lorawan_tx_metadata data;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->acquire_tx_metadata(data));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
// stale = true;
EXPECT_TRUE(LORAWAN_STATUS_METADATA_NOT_AVAILABLE == object->acquire_tx_metadata(data));
// stale = false;
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_tx_metadata(data));
}
TEST_F(Test_LoRaWANStack, acquire_rx_metadata)
{
lorawan_rx_metadata data;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->acquire_rx_metadata(data));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
// stale = true;
EXPECT_TRUE(LORAWAN_STATUS_METADATA_NOT_AVAILABLE == object->acquire_rx_metadata(data));
// stale = false;
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
//Visit mlme_confirm_handler here also
mlme.status = LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
mlme.status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
radio._ev->rx_done(NULL, 0, 0, 0);
mlme.status = LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT;
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
radio._ev->rx_done(NULL, 0, 0, 0);
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
mlme.req_type = MLME_LINK_CHECK;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_rx_metadata(data));
}
TEST_F(Test_LoRaWANStack, acquire_backoff_metadata)
{
int b;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->acquire_backoff_metadata(b));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::int_value = 2;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_backoff_metadata(b));
LoRaMac_stub::int_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_METADATA_NOT_AVAILABLE == object->acquire_backoff_metadata(b));
}
TEST_F(Test_LoRaWANStack, stop_sending)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->stop_sending());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_DEVICE_OFF;
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->stop_sending());
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->stop_sending());
}
TEST_F(Test_LoRaWANStack, lock)
{
object->lock();
}
TEST_F(Test_LoRaWANStack, unlock)
{
object->unlock();
}
TEST_F(Test_LoRaWANStack, interrupt_functions)
{
lorawan_connect_t conn;
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
radio._ev->rx_done(NULL, 0, 0, 0);
radio._ev->rx_error();
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
radio._ev->rx_error();
conf.req_type = MCPS_UNCONFIRMED;
LoRaMac_stub::bool_value = true;
radio._ev->rx_error();
conf.req_type = MCPS_CONFIRMED;
radio._ev->rx_error();
LoRaMac_stub::bool_value = false;
LoRaMac_stub::slot_value = RX_SLOT_WIN_1;
radio._ev->rx_timeout();
radio._ev->tx_timeout();
object->shutdown();
conn.connect_type = LORAWAN_CONNECTION_OTAA;
object->connect(conn);
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
object->connect(conn);
radio._ev->tx_timeout();
}
TEST_F(Test_LoRaWANStack, process_transmission)
{
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
object->connect();
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
LoRaMac_stub::bool_value = true;
conf.req_type = MCPS_PROPRIETARY;
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::dev_class_value = CLASS_A;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::dev_class_value = CLASS_A;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::dev_class_value = CLASS_C;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
LoRaMac_stub::bool_false_counter = 1;
conf.req_type = MCPS_CONFIRMED;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
}
TEST_F(Test_LoRaWANStack, process_reception)
{
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
//Prepare ready for receive state
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = false;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = true;
conf.req_type = MCPS_PROPRIETARY;
ind.pending = true;
LoRaMac_stub::dev_class_value = CLASS_C;
loramac_mlme_indication_t mlme_ind;
mlme_ind.pending = false;
LoRaMac_stub::mlme_ind_ptr = &mlme_ind;
uint8_t ind_buf[150];
for (int i= 0; i < 110; i++) {
ind_buf[i] = i;
}
ind.buffer = ind_buf;
ind.buffer_size = 150;
//_loramac.get_mcps_confirmation()->req_type == MCPS_CONFIRMED
conf.req_type = MCPS_CONFIRMED;
conf.status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
radio._ev->rx_done(NULL, 0, 0, 0);
ind.is_ack_recvd = false;
LoRaMac_stub::bool_true_counter = 1;
LoRaMac_stub::bool_value = false;
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
conf.status = LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR;
radio._ev->rx_done(NULL, 0, 0, 0);
conf.req_type = MCPS_UNCONFIRMED;
LoRaMac_stub::dev_class_value = CLASS_A;
LoRaMac_stub::bool_value = true;
mlme_ind.pending = true;
mlme_ind.indication_type = MLME_SCHEDULE_UPLINK;
conf.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
radio._ev->rx_done(NULL, 0, 0, 0);
ind.is_ack_recvd = true;
conf.req_type = MCPS_CONFIRMED;
conf.status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
radio._ev->rx_done(NULL, 0, 0, 0);
}

View File

@ -0,0 +1,56 @@
#[[
* 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_AUTOMATIC_UPLINK_MESSAGE=true")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE=true")
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}\"")

View File

@ -0,0 +1,84 @@
/*
* 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 "LoRaWANTimer.h"
using namespace events;
class Test_LoRaWANTimer : public testing::Test {
protected:
LoRaWANTimeHandler *object;
EventQueue *queue;
virtual void SetUp()
{
queue = new EventQueue(3, NULL);
object = new LoRaWANTimeHandler();
object->activate_timer_subsystem(queue);
}
virtual void TearDown()
{
delete object;
delete queue;
}
};
TEST_F(Test_LoRaWANTimer, constructor)
{
EXPECT_TRUE(object);
}
TEST_F(Test_LoRaWANTimer, get_current_time)
{
lorawan_time_t tt = object->get_current_time();
EXPECT_TRUE(0 == tt);
}
TEST_F(Test_LoRaWANTimer, get_elapsed_time)
{
lorawan_time_t tt = object->get_elapsed_time(0);
EXPECT_TRUE(0 == tt);
}
void my_callback()
{
}
TEST_F(Test_LoRaWANTimer, init)
{
timer_event_t ev;
object->init(ev, my_callback);
}
TEST_F(Test_LoRaWANTimer, start)
{
timer_event_t ev;
object->start(ev, 10);
}
TEST_F(Test_LoRaWANTimer, stop)
{
timer_event_t ev;
ev.timer_id = 4;
object->stop(ev);
EXPECT_TRUE(ev.timer_id == 0);
}

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.
]]
# Unit test suite name
set(TEST_SUITE_NAME "lorawan_LoRaWANTimer")
# Source files
set(unittest-sources
../features/lorawan/system/LoRaWANTimer.cpp
)
# Add test specific include paths
set(unittest-includes ${unittest-includes}
target_h
../features/lorawan/system
)
# Test & stub files
set(unittest-test-sources
features/lorawan/lorawantimer/Test_LoRaWANTimer.cpp
stubs/EventQueue_stub.cpp
stubs/mbed_assert_stub.c
stubs/equeue_stub.c
)

View File

@ -21,6 +21,8 @@
#include "events/EventQueue.h"
#include <string>
#include "equeue_stub.h"
// Control nsapi stub return value. See stubs/nsapi_dns_stub.cpp
extern nsapi_error_t nsapi_stub_return_value;
@ -186,6 +188,9 @@ TEST_F(TestNetworkStack, gethostbyname_async_delay)
SocketAddress a;
stack->ip_address = std::string("127.0.0.1");
SetUpQueue();
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
EXPECT_EQ(stack->gethostbyname_async("localhost", mbed::callback(my_callback), NSAPI_UNSPEC), NSAPI_ERROR_DNS_FAILURE);
EXPECT_EQ(callin_callback(1, mbed::callback(noarg_callback)), NSAPI_ERROR_OK);
EXPECT_TRUE(noarg_callback_is_called);
@ -197,6 +202,9 @@ TEST_F(TestNetworkStack, gethostbyname_async)
SocketAddress a;
stack->ip_address = std::string("127.0.0.1");
SetUpQueue();
struct equeue_event ptr;
equeue_stub.void_ptr = &ptr;
equeue_stub.call_cb_immediately = true;
EXPECT_EQ(stack->gethostbyname_async("localhost", mbed::callback(my_callback), NSAPI_UNSPEC), NSAPI_ERROR_DNS_FAILURE);
EXPECT_EQ(callin_callback(0, mbed::callback(noarg_callback)), NSAPI_ERROR_OK);
EXPECT_TRUE(noarg_callback_is_called);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
/*
* 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.

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CellularUtil.h"
#include <string.h>
#include <stdlib.h>

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* 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.
@ -74,7 +75,7 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
bd_size_t ChainingBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
return 0;
}
int ChainingBlockDevice::get_erase_value() const

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -17,9 +17,13 @@
#include "EventQueue.h"
#include "Callback.h"
#include "EventQueue_stub.h"
using namespace mbed;
int EventQueue_stub::int_value = 0;
unsigned EventQueue_stub::unsigned_value = 0;
namespace events {
EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer)
@ -40,13 +44,18 @@ void EventQueue::break_dispatch()
unsigned EventQueue::tick()
{
return 0;
return EventQueue_stub::unsigned_value;
}
void EventQueue::cancel(int id)
{
}
int EventQueue::time_left(int id)
{
return EventQueue_stub::int_value;
}
void EventQueue::background(Callback<void(int)> update)
{
}

View File

@ -15,10 +15,11 @@
* limitations under the License.
*/
#include "mbed_assert.h"
#include <inttypes.h>
void mbed_assert_internal(const char *expr, const char *file, int line)
namespace EventQueue_stub
{
extern int int_value;
extern unsigned unsigned_value;
}

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* 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.

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __FILE_HANDLE_STUB_H__
#define __FILE_HANDLE_STUB_H__

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
/*
* 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.

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* 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.

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Kernel.h"
namespace rtos {

View File

@ -0,0 +1,52 @@
/*
* 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 "LoRaMacChannelPlan.h"
LoRaMacChannelPlan::LoRaMacChannelPlan() : _lora_phy(NULL)
{
}
LoRaMacChannelPlan::~LoRaMacChannelPlan()
{
}
void LoRaMacChannelPlan::activate_channelplan_subsystem(LoRaPHY *phy)
{
}
lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
const channel_params_t* channel_list)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaMacChannelPlan::remove_plan()
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
{
return LORAWAN_STATUS_OK;
}

View File

@ -0,0 +1,134 @@
/*
* 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 "LoRaMacCommand.h"
#include "LoRaMac.h"
#include "LoRaMacCommand_stub.h"
lorawan_status_t LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
bool LoRaMacCommand_stub::bool_value = false;
uint8_t LoRaMacCommand_stub::uint8_value = 0;
int32_t LoRaMacCommand_stub::int32_value = 0;
LoRaMacCommand::LoRaMacCommand()
{
}
void LoRaMacCommand::clear_command_buffer()
{
}
uint8_t LoRaMacCommand::get_mac_cmd_length() const
{
return LoRaMacCommand_stub::uint8_value;
}
uint8_t *LoRaMacCommand::get_mac_commands_buffer()
{
return &LoRaMacCommand_stub::uint8_value;
}
void LoRaMacCommand::parse_mac_commands_to_repeat()
{
}
void LoRaMacCommand::clear_repeat_buffer()
{
}
void LoRaMacCommand::copy_repeat_commands_to_buffer()
{
}
uint8_t LoRaMacCommand::get_repeat_commands_length() const
{
return LoRaMacCommand_stub::uint8_value;
}
void LoRaMacCommand::clear_sticky_mac_cmd()
{
}
bool LoRaMacCommand::has_sticky_mac_cmd() const
{
return LoRaMacCommand_stub::bool_value;
}
lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, uint8_t mac_index,
uint8_t commands_size, uint8_t snr,
loramac_mlme_confirm_t& mlme_conf,
lora_mac_system_params_t &mac_sys_params,
LoRaPHY &lora_phy)
{
return LoRaMacCommand_stub::status_value;
}
int32_t LoRaMacCommand::cmd_buffer_remaining() const
{
return LoRaMacCommand_stub::int32_value;
}
void LoRaMacCommand::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level)
{
}
lorawan_status_t LoRaMacCommand::add_link_check_req()
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_link_adr_ans(uint8_t status)
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_duty_cycle_ans()
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_rx_param_setup_ans(uint8_t status)
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_dev_status_ans(uint8_t battery, uint8_t margin)
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_new_channel_ans(uint8_t status)
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_rx_timing_setup_ans()
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_tx_param_setup_ans()
{
return LoRaMacCommand_stub::status_value;
}
lorawan_status_t LoRaMacCommand::add_dl_channel_ans(uint8_t status)
{
return LoRaMacCommand_stub::status_value;
}

View File

@ -0,0 +1,28 @@
/*
* 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 <inttypes.h>
#include "lorawan_types.h"
namespace LoRaMacCommand_stub
{
extern lorawan_status_t status_value;
extern bool bool_value;
extern uint8_t uint8_value;
extern int32_t int32_value;
}

View File

@ -0,0 +1,66 @@
/*
* 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 <stdint.h>
#include "LoRaMacCrypto.h"
#include "system/lorawan_data_structures.h"
#include "LoRaMacCrypto_stub.h"
int LoRaMacCrypto_stub::int_table_idx_value = 0;
int LoRaMacCrypto_stub::int_table[20] = {};
LoRaMacCrypto::LoRaMacCrypto()
{
}
int LoRaMacCrypto::compute_mic(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
uint8_t dir, uint32_t, uint32_t *)
{
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
}
int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
uint8_t , uint32_t , uint8_t *)
{
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
}
int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
uint8_t , uint32_t , uint8_t *)
{
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
}
int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t *)
{
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
}
int LoRaMacCrypto::decrypt_join_frame(const uint8_t *in, uint16_t size, const uint8_t *, uint32_t, uint8_t *out)
{
memcpy(out, in, size);
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
}
int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *, uint32_t, const uint8_t *, uint16_t ,
uint8_t *, uint8_t *)
{
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
}

View File

@ -0,0 +1,25 @@
/*
* 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 <inttypes.h>
namespace LoRaMacCrypto_stub
{
extern int int_table_idx_value;
extern int int_table[20];
}

View File

@ -0,0 +1,458 @@
/*
* 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 "LoRaMac.h"
#include "LoRaMac_stub.h"
using namespace events;
using namespace mbed;
int LoRaMac_stub::bool_false_counter = 0;
int LoRaMac_stub::bool_true_counter = 0;
bool LoRaMac_stub::bool_value = false;
int LoRaMac_stub::int_value = 0;
rx_slot_t LoRaMac_stub::slot_value = RX_SLOT_WIN_1;
lorawan_status_t LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
loramac_mcps_confirm_t *LoRaMac_stub::mcps_conf_ptr = NULL;
loramac_mcps_indication_t *LoRaMac_stub::mcps_ind_ptr = NULL;
loramac_mlme_confirm_t *LoRaMac_stub::mlme_conf_ptr = NULL;
loramac_mlme_indication_t *LoRaMac_stub::mlme_ind_ptr = NULL;
device_class_t LoRaMac_stub::dev_class_value = CLASS_A;
mbed::Callback<void(void)> LoRaMac_stub::_ack_expiry_handler_for_class_c = NULL;
mbed::Callback<void(void)> LoRaMac_stub::_scheduling_failure_handler = NULL;
LoRaMac::LoRaMac()
: _lora_time(),
_lora_phy(NULL),
_mac_commands(),
_channel_plan(),
_lora_crypto(),
_ev_queue(NULL),
_mcps_indication(),
_mcps_confirmation(),
_mlme_indication(),
_mlme_confirmation(),
_is_nwk_joined(false),
_continuous_rx2_window_open(false),
_device_class(CLASS_A)
{}
LoRaMac::~LoRaMac()
{
}
const loramac_mcps_confirm_t *LoRaMac::get_mcps_confirmation() const
{
return LoRaMac_stub::mcps_conf_ptr;
}
const loramac_mcps_indication_t *LoRaMac::get_mcps_indication() const
{
return LoRaMac_stub::mcps_ind_ptr;
}
const loramac_mlme_confirm_t *LoRaMac::get_mlme_confirmation() const
{
return LoRaMac_stub::mlme_conf_ptr;
}
const loramac_mlme_indication_t *LoRaMac::get_mlme_indication() const
{
return LoRaMac_stub::mlme_ind_ptr;
}
void LoRaMac::post_process_mlme_request()
{
}
void LoRaMac::post_process_mcps_req()
{
}
void LoRaMac::post_process_mcps_ind()
{
}
void LoRaMac::post_process_mlme_ind()
{
}
lorawan_time_t LoRaMac::get_current_time(void)
{
}
rx_slot_t LoRaMac::get_current_slot(void)
{
return LoRaMac_stub::slot_value;
}
void LoRaMac::handle_join_accept_frame(const uint8_t *payload, uint16_t size)
{
}
void LoRaMac::check_frame_size(uint16_t size)
{
}
bool LoRaMac::message_integrity_check(const uint8_t *const payload,
const uint16_t size,
uint8_t *const ptr_pos,
uint32_t address,
uint32_t *downlink_counter,
const uint8_t *nwk_skey)
{
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
uint16_t size,
uint8_t fopts_len,
uint8_t *nwk_skey,
uint8_t *app_skey,
uint32_t address,
uint32_t downlink_counter,
int16_t rssi,
int8_t snr)
{
}
void LoRaMac::extract_mac_commands_only(const uint8_t *payload,
int8_t snr,
uint8_t fopts_len)
{
}
void LoRaMac::handle_data_frame(const uint8_t *const payload,
const uint16_t size,
uint8_t ptr_pos,
uint8_t msg_type,
int16_t rssi,
int8_t snr)
{
}
void LoRaMac::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level)
{
}
void LoRaMac::on_radio_tx_done(lorawan_time_t timestamp)
{
}
void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr)
{
}
void LoRaMac::on_radio_tx_timeout(void)
{
}
void LoRaMac::on_radio_rx_timeout(bool is_timeout)
{
}
bool LoRaMac::continue_joining_process()
{
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
bool LoRaMac::continue_sending_process()
{
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
lorawan_status_t LoRaMac::send_join_request()
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::handle_retransmission()
{
return LoRaMac_stub::status_value;
}
void LoRaMac::on_backoff_timer_expiry(void)
{
}
void LoRaMac::open_rx1_window(void)
{
}
void LoRaMac::open_rx2_window()
{
}
void LoRaMac::on_ack_timeout_timer_event(void)
{
}
bool LoRaMac::validate_payload_length(uint16_t length,
int8_t datarate,
uint8_t fopts_len)
{
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::set_mlme_schedule_ul_indication(void)
{
}
// This is not actual transmission. It just schedules a message in response
// to MCPS request
lorawan_status_t LoRaMac::send(loramac_mhdr_t *machdr, const uint8_t fport,
const void *fbuffer, uint16_t fbuffer_size)
{
return LoRaMac_stub::status_value;
}
int LoRaMac::get_backoff_timer_event_id(void)
{
return LoRaMac_stub::int_value;
}
lorawan_status_t LoRaMac::clear_tx_pipe(void)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::schedule_tx()
{
return LoRaMac_stub::status_value;
}
void LoRaMac::calculate_backOff(uint8_t channel)
{
}
void LoRaMac::reset_mac_parameters(void)
{
}
uint8_t LoRaMac::get_default_tx_datarate()
{
return 0;
}
void LoRaMac::enable_adaptive_datarate(bool adr_enabled)
{
}
lorawan_status_t LoRaMac::set_channel_data_rate(uint8_t data_rate)
{
return LoRaMac_stub::status_value;
}
bool LoRaMac::tx_ongoing()
{
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::set_tx_ongoing(bool ongoing)
{
}
void LoRaMac::reset_ongoing_tx(bool reset_pending)
{
}
int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
const uint8_t *const data,
uint16_t length,
uint8_t flags,
uint8_t num_retries)
{
return 0;
}
lorawan_status_t LoRaMac::send_ongoing_tx()
{
return LoRaMac_stub::status_value;
}
device_class_t LoRaMac::get_device_class() const
{
return LoRaMac_stub::dev_class_value;
}
void LoRaMac::set_device_class(const device_class_t &device_class,
mbed::Callback<void(void)>ack_expiry_handler)
{
LoRaMac_stub::_ack_expiry_handler_for_class_c = ack_expiry_handler;
}
void LoRaMac::setup_link_check_request()
{
}
lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_otaa)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::join(bool is_otaa)
{
return LoRaMac_stub::status_value;
}
static void memcpy_convert_endianess(uint8_t *dst,
const uint8_t *src,
uint16_t size)
{
}
lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
loramac_frame_ctrl_t *fctrl,
const uint8_t fport,
const void *fbuffer,
uint16_t fbuffer_size)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::send_frame_on_channel(uint8_t channel)
{
return LoRaMac_stub::status_value;
}
void LoRaMac::reset_mcps_confirmation()
{
}
void LoRaMac::reset_mlme_confirmation()
{
}
void LoRaMac::reset_mcps_indication()
{
}
void LoRaMac::set_tx_continuous_wave(uint8_t channel, int8_t datarate, int8_t tx_power,
float max_eirp, float antenna_gain, uint16_t timeout)
{
}
lorawan_status_t LoRaMac::initialize(EventQueue *queue,
mbed::Callback<void(void)>scheduling_failure_handler)
{
LoRaMac_stub::_scheduling_failure_handler = scheduling_failure_handler;
return LoRaMac_stub::status_value;
}
void LoRaMac::disconnect()
{
}
uint8_t LoRaMac::get_max_possible_tx_size(uint8_t fopts_len)
{
return 0;
}
bool LoRaMac::nwk_joined()
{
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::set_nwk_joined(bool joined)
{
}
lorawan_status_t LoRaMac::add_channel_plan(const lorawan_channelplan_t &plan)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::remove_channel_plan()
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::get_channel_plan(lorawan_channelplan_t &plan)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::remove_single_channel(uint8_t id)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::multicast_channel_link(multicast_params_t *channel_param)
{
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::multicast_channel_unlink(multicast_params_t *channel_param)
{
return LoRaMac_stub::status_value;
}
void LoRaMac::bind_phy(LoRaPHY &phy)
{
}

View File

@ -0,0 +1,40 @@
/*
* 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 "stdint.h"
#include "stdbool.h"
#include <cstddef>
#include "lorawan_types.h"
#include "lorawan_data_structures.h"
namespace LoRaMac_stub
{
extern bool bool_value;
extern int bool_false_counter;
extern int bool_true_counter;
extern int int_value;
extern rx_slot_t slot_value;
extern lorawan_status_t status_value;
extern loramac_mcps_confirm_t *mcps_conf_ptr;
extern loramac_mcps_indication_t *mcps_ind_ptr;
extern loramac_mlme_confirm_t *mlme_conf_ptr;
extern loramac_mlme_indication_t *mlme_ind_ptr;
extern device_class_t dev_class_value;
extern mbed::Callback<void(void)> _ack_expiry_handler_for_class_c;
extern mbed::Callback<void(void)> _scheduling_failure_handler;
}

View File

@ -0,0 +1,28 @@
/*
* 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 "LoRaPHYEU868.h"
#include "lora_phy_ds.h"
LoRaPHYEU868::LoRaPHYEU868()
{
}
LoRaPHYEU868::~LoRaPHYEU868()
{
}

View File

@ -0,0 +1,413 @@
/*
* 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 <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "LoRaPHY.h"
#include "LoRaPHY_stub.h"
LoRaRadio *LoRaPHY_stub::radio = NULL;
uint32_t LoRaPHY_stub::uint32_value = 0;
uint16_t LoRaPHY_stub::uint16_value = 0;
uint8_t LoRaPHY_stub::uint8_value = 0;
int8_t LoRaPHY_stub::int8_value = 0;
int LoRaPHY_stub::int_value = 0;
double LoRaPHY_stub::double_value = 0;
lorawan_status_t LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
channel_params_t *LoRaPHY_stub::channel_params_ptr = NULL;
uint8_t LoRaPHY_stub::bool_counter = 0;
bool LoRaPHY_stub::bool_table[20] = {};
uint8_t LoRaPHY_stub::linkAdrNbBytesParsed = 0;
uint8_t LoRaPHY_stub::ch_mask_value = 0;
uint8_t LoRaPHY_stub::adr_parse_count = 0;
LoRaPHY::LoRaPHY()
: _radio(LoRaPHY_stub::radio)
{
}
LoRaPHY::~LoRaPHY()
{
}
void LoRaPHY::initialize(LoRaWANTimeHandler *lora_time)
{
}
bool LoRaPHY::mask_bit_test(const uint16_t *mask, unsigned bit)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
void LoRaPHY::mask_bit_set(uint16_t *mask, unsigned bit)
{
}
void LoRaPHY::mask_bit_clear(uint16_t *mask, unsigned bit)
{
}
void LoRaPHY::set_radio_instance(LoRaRadio &radio)
{
}
void LoRaPHY::put_radio_to_sleep()
{
}
void LoRaPHY::put_radio_to_standby()
{
}
void LoRaPHY::setup_public_network_mode(bool set)
{
}
void LoRaPHY::handle_receive(void)
{
}
uint32_t LoRaPHY::get_radio_rng()
{
return LoRaPHY_stub::uint32_value;
}
void LoRaPHY::handle_send(uint8_t *buf, uint8_t size)
{
}
uint8_t LoRaPHY::request_new_channel(int8_t channel_id, channel_params_t *new_channel)
{
return LoRaPHY_stub::uint8_value;
}
int32_t LoRaPHY::get_random(int32_t min, int32_t max)
{
return LoRaPHY_stub::uint32_value;
}
bool LoRaPHY::verify_channel_DR(uint16_t *channel_mask, int8_t dr)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::val_in_range(int8_t value, int8_t min, int8_t max)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::disable_channel(uint16_t *channel_mask, uint8_t id,
uint8_t max_channels_num)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
uint8_t LoRaPHY::count_bits(uint16_t mask, uint8_t nbBits)
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::num_active_channels(uint16_t *channel_mask, uint8_t start_idx,
uint8_t stop_idx)
{
return LoRaPHY_stub::uint8_value;
}
void LoRaPHY::copy_channel_mask(uint16_t *dest_mask, uint16_t *src_mask, uint8_t len)
{
if ((dest_mask != NULL) && (src_mask != NULL)) {
for (uint8_t i = 0; i < len; i++) {
dest_mask[i] = src_mask[i];
}
}
}
void LoRaPHY::set_last_tx_done(uint8_t channel, bool joined, lorawan_time_t last_tx_done_time)
{
}
lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
band_t *bands, uint8_t nb_bands)
{
return LoRaPHY_stub::uint32_value;
}
uint8_t LoRaPHY::parse_link_ADR_req(const uint8_t *payload,
link_adr_params_t *params)
{
params->ch_mask_ctrl = LoRaPHY_stub::ch_mask_value;
if (LoRaPHY_stub::adr_parse_count) {
return --LoRaPHY_stub::adr_parse_count;
}
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::verify_link_ADR_req(verify_adr_params_t *verify_params,
int8_t *dr, int8_t *tx_pow, uint8_t *nb_rep)
{
return LoRaPHY_stub::uint8_value;
}
void LoRaPHY::get_rx_window_params(double t_symb, uint8_t min_rx_symb,
uint32_t rx_error, uint32_t wakeup_time,
uint32_t *window_timeout, int32_t *window_offset)
{
}
int8_t LoRaPHY::compute_tx_power(int8_t tx_power_idx, float max_eirp,
float antenna_gain)
{
return LoRaPHY_stub::int8_value;
}
int8_t LoRaPHY::get_next_lower_dr(int8_t dr, int8_t min_dr)
{
return LoRaPHY_stub::int8_value;
}
uint8_t LoRaPHY::get_bandwidth(uint8_t dr)
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::enabled_channel_count(uint8_t datarate,
const uint16_t *channel_mask,
uint8_t *channel_indices,
uint8_t *delayTx)
{
return LoRaPHY_stub::uint8_value;
}
bool LoRaPHY::is_datarate_supported(const int8_t datarate) const
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
void LoRaPHY::reset_to_default_values(loramac_protocol_params *params, bool init)
{
}
int8_t LoRaPHY::get_next_lower_tx_datarate(int8_t datarate)
{
return LoRaPHY_stub::int8_value;
}
uint8_t LoRaPHY::get_minimum_rx_datarate()
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::get_minimum_tx_datarate()
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::get_default_tx_datarate()
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::get_default_max_tx_datarate()
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::get_default_tx_power()
{
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::get_max_payload(uint8_t datarate, bool use_repeater)
{
return LoRaPHY_stub::uint8_value;
}
uint16_t LoRaPHY::get_maximum_frame_counter_gap()
{
return LoRaPHY_stub::uint16_value;
}
uint32_t LoRaPHY::get_ack_timeout()
{
return LoRaPHY_stub::uint32_value;
}
uint32_t LoRaPHY::get_default_rx2_frequency()
{
return LoRaPHY_stub::uint32_value;
}
uint8_t LoRaPHY::get_default_rx2_datarate()
{
return phy_params.rx_window2_datarate;
}
uint16_t *LoRaPHY::get_channel_mask(bool get_default)
{
return &LoRaPHY_stub::uint16_value;
}
uint8_t LoRaPHY::get_max_nb_channels()
{
return LoRaPHY_stub::uint8_value;
}
channel_params_t *LoRaPHY::get_phy_channels()
{
return LoRaPHY_stub::channel_params_ptr;
}
bool LoRaPHY::is_custom_channel_plan_supported()
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
void LoRaPHY::restore_default_channels()
{
}
bool LoRaPHY::verify_rx_datarate(uint8_t datarate)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::verify_tx_datarate(uint8_t datarate, bool use_default)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::verify_tx_power(uint8_t tx_power)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::verify_duty_cycle(bool cycle)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::verify_nb_join_trials(uint8_t nb_join_trials)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
void LoRaPHY::apply_cf_list(const uint8_t *payload, uint8_t size)
{
}
bool LoRaPHY::get_next_ADR(bool restore_channel_mask, int8_t &dr_out,
int8_t &tx_power_out, uint32_t &adr_ack_cnt)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
void LoRaPHY::compute_rx_win_params(int8_t datarate, uint8_t min_rx_symbols,
uint32_t rx_error,
rx_config_params_t *rx_conf_params)
{
}
bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
bool LoRaPHY::tx_config(tx_config_params_t *tx_conf, int8_t *tx_power,
lorawan_time_t *tx_toa)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
uint8_t LoRaPHY::link_ADR_request(adr_req_params_t *link_adr_req,
int8_t *dr_out, int8_t *tx_power_out,
uint8_t *nb_rep_out, uint8_t *nb_bytes_processed)
{
*nb_bytes_processed = LoRaPHY_stub::linkAdrNbBytesParsed;
return LoRaPHY_stub::uint8_value;
}
uint8_t LoRaPHY::accept_rx_param_setup_req(rx_param_setup_req_t *params)
{
return LoRaPHY_stub::uint8_value;
}
bool LoRaPHY::accept_tx_param_setup_req(uint8_t ul_dwell_time, uint8_t dl_dwell_time)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
int LoRaPHY::lookup_band_for_frequency(uint32_t freq) const
{
return LoRaPHY_stub::int_value;
}
bool LoRaPHY::verify_frequency_for_band(uint32_t freq, uint8_t band) const
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
uint8_t LoRaPHY::dl_channel_request(uint8_t channel_id, uint32_t rx1_frequency)
{
return LoRaPHY_stub::uint8_value;
}
int8_t LoRaPHY::get_alternate_DR(uint8_t nb_trials)
{
return LoRaPHY_stub::int8_value;
}
void LoRaPHY::calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_enabled, uint8_t channel,
lorawan_time_t elapsed_time, lorawan_time_t tx_toa)
{
}
lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t *params,
uint8_t *channel, lorawan_time_t *time,
lorawan_time_t *aggregate_timeoff)
{
return LoRaPHY_stub::lorawan_status_value;
}
lorawan_status_t LoRaPHY::add_channel(const channel_params_t *new_channel,
uint8_t id)
{
return LoRaPHY_stub::lorawan_status_value;
}
bool LoRaPHY::remove_channel(uint8_t channel_id)
{
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
}
void LoRaPHY::set_tx_cont_mode(cw_mode_params_t *params, uint32_t given_frequency)
{
}
uint8_t LoRaPHY::apply_DR_offset(int8_t dr, int8_t dr_offset)
{
return LoRaPHY_stub::uint8_value;
}

View File

@ -0,0 +1,40 @@
/*
* 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 "stdint.h"
#include "stdbool.h"
#include <cstddef>
#include "lorawan_types.h"
namespace LoRaPHY_stub
{
extern LoRaRadio *radio;
extern uint8_t bool_counter;
extern bool bool_table[20];
extern uint32_t uint32_value;
extern uint8_t uint8_value;
extern int8_t int8_value;
extern int int_value;
extern double double_value;
extern uint16_t uint16_value;
extern lorawan_status_t lorawan_status_value;
extern channel_params_t* channel_params_ptr;
extern uint8_t linkAdrNbBytesParsed;
extern uint8_t ch_mask_value;
extern uint8_t adr_parse_count;
}

View File

@ -0,0 +1,298 @@
/*
* 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 <string.h>
#include <stdlib.h>
#include "LoRaWANStack.h"
using namespace mbed;
using namespace events;
/*****************************************************************************
* Constructor *
****************************************************************************/
LoRaWANStack::LoRaWANStack()
: _loramac(),
_device_current_state(DEVICE_STATE_NOT_INITIALIZED),
_lw_session(),
_tx_msg(),
_rx_msg(),
_tx_metadata(),
_rx_metadata(),
_num_retry(1),
_ctrl_flags(0),
_app_port(12),
_link_check_requested(false),
_automatic_uplink_ongoing(false),
_ready_for_rx(true),
_queue(NULL)
{
}
void LoRaWANStack::bind_phy_and_radio_driver(LoRaRadio &radio, LoRaPHY &phy)
{
}
lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t *callbacks)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::connect()
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel_plan)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::drop_channel_list()
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t &channel_plan)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::stop_sending(void)
{
return LORAWAN_STATUS_OK;
}
int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
uint16_t length, uint8_t flags,
bool null_allowed, bool allow_port_0)
{
return 0;
}
int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params)
{
return 0;
}
lorawan_status_t LoRaWANStack::set_link_check_request()
{
return LORAWAN_STATUS_OK;
}
void LoRaWANStack::remove_link_check_request()
{
}
lorawan_status_t LoRaWANStack::shutdown()
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t &device_class)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::acquire_tx_metadata(lorawan_tx_metadata &tx_metadata)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::acquire_rx_metadata(lorawan_rx_metadata &metadata)
{
return LORAWAN_STATUS_OK;
}
lorawan_status_t LoRaWANStack::acquire_backoff_metadata(int &backoff)
{
return LORAWAN_STATUS_OK;
}
/*****************************************************************************
* Interrupt handlers *
****************************************************************************/
void LoRaWANStack::tx_interrupt_handler(void)
{
}
void LoRaWANStack::rx_interrupt_handler(const uint8_t *payload, uint16_t size,
int16_t rssi, int8_t snr)
{
}
void LoRaWANStack::rx_error_interrupt_handler(void)
{
}
void LoRaWANStack::tx_timeout_interrupt_handler(void)
{
}
void LoRaWANStack::rx_timeout_interrupt_handler(void)
{
}
void LoRaWANStack::process_transmission_timeout()
{
}
void LoRaWANStack::process_transmission(void)
{
}
void LoRaWANStack::handle_ack_expiry_for_class_c(void)
{
}
void LoRaWANStack::handle_scheduling_failure(void)
{
}
void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size,
int16_t rssi, int8_t snr)
{
}
void LoRaWANStack::process_reception_timeout(bool is_timeout)
{
}
void LoRaWANStack::make_tx_metadata_available(void)
{
}
void LoRaWANStack::make_rx_metadata_available(void)
{
}
bool LoRaWANStack::is_port_valid(const uint8_t port, bool allow_port_0)
{
return true;
}
lorawan_status_t LoRaWANStack::set_application_port(const uint8_t port, bool allow_port_0)
{
return LORAWAN_STATUS_OK;
}
void LoRaWANStack::state_machine_run_to_completion()
{
}
void LoRaWANStack::send_event_to_application(const lorawan_event_t event) const
{
}
void LoRaWANStack::send_automatic_uplink_message(const uint8_t port)
{
}
int LoRaWANStack::convert_to_msg_flag(const mcps_type_t type)
{
return 0;
}
lorawan_status_t LoRaWANStack::handle_connect(bool is_otaa)
{
return LORAWAN_STATUS_OK;
}
void LoRaWANStack::mlme_indication_handler()
{
}
void LoRaWANStack::mlme_confirm_handler()
{
}
void LoRaWANStack::mcps_confirm_handler()
{
}
void LoRaWANStack::mcps_indication_handler()
{
}
lorawan_status_t LoRaWANStack::state_controller(device_states_t new_state)
{
return LORAWAN_STATUS_OK;
}
void LoRaWANStack::process_shutdown_state(lorawan_status_t &op_status)
{
}
void LoRaWANStack::process_status_check_state()
{
}
void LoRaWANStack::process_scheduling_state(lorawan_status_t &op_status)
{
}
void LoRaWANStack::process_joining_state(lorawan_status_t &op_status)
{
}
void LoRaWANStack::process_connected_state()
{
}
void LoRaWANStack::process_connecting_state(lorawan_status_t &op_status)
{
}
void LoRaWANStack::process_idle_state(lorawan_status_t &op_status)
{
}
void LoRaWANStack::process_uninitialized_state(lorawan_status_t &op_status)
{
}

View File

@ -0,0 +1,64 @@
/*
* 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"
#include "LoRaWANTimer.h"
#include "LoRaWANTimer_stub.h"
lorawan_time_t LoRaWANTimer_stub::time_value = 0;
bool LoRaWANTimer_stub::call_cb_immediately = false;
LoRaWANTimeHandler::LoRaWANTimeHandler()
: _queue(NULL)
{
}
LoRaWANTimeHandler::~LoRaWANTimeHandler()
{
}
void LoRaWANTimeHandler::activate_timer_subsystem(events::EventQueue *queue)
{
}
lorawan_time_t LoRaWANTimeHandler::get_current_time( void )
{
return LoRaWANTimer_stub::time_value;
}
lorawan_time_t LoRaWANTimeHandler::get_elapsed_time(lorawan_time_t saved_time)
{
return LoRaWANTimer_stub::time_value;
}
void LoRaWANTimeHandler::init(timer_event_t &obj, mbed::Callback<void()> callback)
{
if (callback && LoRaWANTimer_stub::call_cb_immediately) {
callback();
}
obj.timer_id = 1;
}
void LoRaWANTimeHandler::start(timer_event_t &obj, const uint32_t timeout)
{
}
void LoRaWANTimeHandler::stop(timer_event_t &obj)
{
obj.timer_id = 0;
}

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 "LoRaWANTimer.h"
namespace LoRaWANTimer_stub
{
extern lorawan_time_t time_value;
extern bool call_cb_immediately;
}

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Arm Limited and affiliates.
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Arm Limited and affiliates.
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,23 +1,18 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2017 ARM Limited
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 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
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* http://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* 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 "ObservingBlockDevice.h"

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* 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.

View File

@ -1,23 +1,18 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2017 ARM Limited
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 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
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* http://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* 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 "ReadOnlyBlockDevice.h"

View File

@ -1,5 +1,6 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
/*
* 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.
@ -19,7 +20,7 @@
SlicingBlockDevice::SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr_t stop)
{
}
int SlicingBlockDevice::init()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TIMER_STUB_H
#define TIMER_STUB_H

232
UNITTESTS/stubs/aes_stub.c Normal file
View File

@ -0,0 +1,232 @@
/*
* 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.
*/
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include <string.h>
#include "mbedtls/aes.h"
#include "aes_stub.h"
aes_stub_def aes_stub;
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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
#endif
#if !defined(MBEDTLS_AES_SETKEY_DEC_ALT)
int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
unsigned int keybits )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
#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)
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
const unsigned char *key,
unsigned int keybits)
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
#endif
int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
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] )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
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] )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
#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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
#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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}
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 )
{
if (aes_stub.int_zero_counter) {
aes_stub.int_zero_counter--;
return 0;
}
return aes_stub.int_value;
}

View File

@ -0,0 +1,26 @@
/*
* 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 <inttypes.h>
typedef struct {
int int_value;
uint8_t int_zero_counter;
} aes_stub_def;
extern aes_stub_def aes_stub;

View File

@ -0,0 +1,213 @@
/*
* 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.
*/
#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 <stdlib.h>
#include <string.h>
#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
#include "cipher_stub.h"
cipher_stub_def cipher_stub;
const int *mbedtls_cipher_list( void )
{
return cipher_stub.int_ptr;
}
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type )
{
return cipher_stub.info_value;
}
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name )
{
return cipher_stub.info_value;
}
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 cipher_stub.info_value;
}
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 )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key,
int key_bitlen, const mbedtls_operation_t operation )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
const unsigned char *iv, size_t iv_len )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
const unsigned char *ad, size_t ad_len )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input,
size_t ilen, unsigned char *output, size_t *olen )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
unsigned char *output, size_t *olen )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
unsigned char *tag, size_t tag_len )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
const unsigned char *tag, size_t tag_len )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
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 )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
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 )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}
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 )
{
if (cipher_stub.int_zero_counter) {
cipher_stub.int_zero_counter--;
return 0;
}
return cipher_stub.int_value;
}

View File

@ -0,0 +1,28 @@
/*
* 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 <inttypes.h>
#include "mbedtls/cipher.h"
typedef struct {
mbedtls_cipher_info_t *info_value;
int int_value;
int *int_ptr;
uint8_t int_zero_counter;
} cipher_stub_def;
extern cipher_stub_def cipher_stub;

View File

@ -0,0 +1,94 @@
/*
* 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.
*/
#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 <string.h>
#include "cmac_stub.h"
cmac_stub_def cmac_stub;
int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
const unsigned char *key, size_t keybits )
{
if (cmac_stub.int_zero_counter) {
cmac_stub.int_zero_counter--;
return 0;
}
return cmac_stub.int_value;
}
int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
const unsigned char *input, size_t ilen )
{
if (cmac_stub.int_zero_counter) {
cmac_stub.int_zero_counter--;
return 0;
}
return cmac_stub.int_value;
}
int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
unsigned char *output )
{
if (cmac_stub.int_zero_counter) {
cmac_stub.int_zero_counter--;
return 0;
}
return cmac_stub.int_value;
}
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx )
{
if (cmac_stub.int_zero_counter) {
cmac_stub.int_zero_counter--;
return 0;
}
return cmac_stub.int_value;
}
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 )
{
if (cmac_stub.int_zero_counter) {
cmac_stub.int_zero_counter--;
return 0;
}
return cmac_stub.int_value;
}
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 )
{
if (cmac_stub.int_zero_counter) {
cmac_stub.int_zero_counter--;
return 0;
}
return cmac_stub.int_value;
}

View File

@ -0,0 +1,26 @@
/*
* 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 <inttypes.h>
typedef struct {
int int_value;
uint8_t int_zero_counter;
} cmac_stub_def;
extern cmac_stub_def cmac_stub;

View File

@ -18,6 +18,10 @@
#include "equeue.h"
#include <stdlib.h>
#include "equeue_stub.h"
equeue_stub_def equeue_stub;
int equeue_create(equeue_t *queue, size_t size)
{
return 0;
@ -55,7 +59,7 @@ int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data)
void *equeue_alloc(equeue_t *queue, size_t size)
{
return malloc(size);
return equeue_stub.void_ptr;
}
void equeue_dealloc(equeue_t *queue, void *event)
@ -80,11 +84,10 @@ void equeue_event_dtor(void *event, void (*dtor)(void *))
int equeue_post(equeue_t *queue, void (*cb)(void *), void *event)
{
if (cb)
{
cb(event);
free(event);
return 1; //Fake ID for calling cancel
struct equeue_event *e = (struct equeue_event*)event - 1;
if (cb && equeue_stub.call_cb_immediately) {
cb(e + 1);
return 1;
}
return 0;
}

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