mirror of https://github.com/ARMmbed/mbed-os.git
More lorawan unit tests added
parent
b6465340b5
commit
0f83f08043
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -126,6 +126,21 @@ TEST_F(Test_LoRaMacChannelPlan, remove_plan)
|
|||
|
||||
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)
|
||||
|
|
|
@ -0,0 +1,412 @@
|
|||
/*
|
||||
* 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();
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
|
||||
|
||||
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();
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == true);
|
||||
}
|
||||
|
||||
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_mac_commands_in_next_tx)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
|
||||
|
||||
buf[0] = 4;
|
||||
buf[1] = 16;
|
||||
buf[2] = 32;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == true);
|
||||
object->clear_mac_commands_in_next_tx();
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, is_mac_command_in_next_tx)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
|
||||
|
||||
buf[0] = 4;
|
||||
buf[1] = 16;
|
||||
buf[2] = 32;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
EXPECT_TRUE(object->is_mac_command_in_next_tx() == true);
|
||||
}
|
||||
|
||||
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, is_sticky_mac_command_pending)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
EXPECT_TRUE(object->is_sticky_mac_command_pending() == 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);
|
||||
object->parse_mac_commands_to_repeat();
|
||||
EXPECT_TRUE(object->is_sticky_mac_command_pending() == true);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) , Arm Limited and affiliates.
|
||||
#[[
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -13,12 +13,26 @@
|
|||
* 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"
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaMacCommand")
|
||||
|
||||
void mbed_assert_internal(const char *expr, const char *file, int line)
|
||||
{
|
||||
# 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
|
||||
)
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -18,6 +18,7 @@ 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;
|
||||
|
||||
LoRaPHY::LoRaPHY()
|
||||
: _radio(NULL)
|
||||
|
@ -34,10 +35,6 @@ void LoRaPHY::initialize(LoRaWANTimeHandler *lora_time)
|
|||
|
||||
bool LoRaPHY::mask_bit_test(const uint16_t *mask, unsigned bit)
|
||||
{
|
||||
volatile bool ana = LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter];
|
||||
ana = true;
|
||||
volatile uint8_t cc = LoRaPHY_stub::bool_counter;
|
||||
cc = 2;
|
||||
return LoRaPHY_stub::bool_table[LoRaPHY_stub::bool_counter++];
|
||||
}
|
||||
|
||||
|
@ -352,6 +349,7 @@ 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "lorawan_types.h"
|
||||
|
||||
namespace LoRaPHY_stub
|
||||
namespace LoRaPHY_stub
|
||||
{
|
||||
extern uint8_t bool_counter;
|
||||
extern bool bool_table[20];
|
||||
|
@ -33,4 +33,5 @@ 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;
|
||||
}
|
||||
|
|
|
@ -93,8 +93,7 @@ void LoRaMacCommand::parse_mac_commands_to_repeat()
|
|||
case MOTE_MAC_LINK_CHECK_REQ: { // 0 byte payload
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
default: {}//Cannot happen
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,8 +189,7 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
|
|||
rx_param_setup_req_t rxParamSetupReq;
|
||||
|
||||
rxParamSetupReq.dr_offset = (payload[mac_index] >> 4) & 0x07;
|
||||
rxParamSetupReq.datarate = payload[mac_index] & 0x0F;
|
||||
mac_index++;
|
||||
rxParamSetupReq.datarate = payload[mac_index++] & 0x0F;
|
||||
|
||||
rxParamSetupReq.frequency = (uint32_t) payload[mac_index++];
|
||||
rxParamSetupReq.frequency |= (uint32_t) payload[mac_index++] << 8;
|
||||
|
@ -405,7 +403,7 @@ lorawan_status_t LoRaMacCommand::add_tx_param_setup_ans()
|
|||
lorawan_status_t LoRaMacCommand::add_dl_channel_ans(uint8_t status)
|
||||
{
|
||||
lorawan_status_t ret = LORAWAN_STATUS_LENGTH_ERROR;
|
||||
if (cmd_buffer_remaining() > 0) {
|
||||
if (cmd_buffer_remaining() > 1) {
|
||||
mac_cmd_buffer[mac_cmd_buf_idx++] = MOTE_MAC_DL_CHANNEL_ANS;
|
||||
// Status: Uplink frequency exists, Channel frequency OK
|
||||
mac_cmd_buffer[mac_cmd_buf_idx++] = status;
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
uint8_t *get_mac_commands_buffer();
|
||||
|
||||
/**
|
||||
* @brief Parses the MAC commands which must be resent.
|
||||
* @brief Parses the MAC commands which must be re-sent.
|
||||
*/
|
||||
void parse_mac_commands_to_repeat();
|
||||
|
||||
|
|
Loading…
Reference in New Issue