Lorawan unittests

pull/8233/head
Antti Kauppila 2018-09-09 14:07:21 +03:00
parent 45f59f88c3
commit b6465340b5
5 changed files with 655 additions and 0 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

@ -0,0 +1,153 @@
/*
* 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);
}
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,420 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "LoRaPHY.h"
#include "LoRaPHY_stub.h"
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] = {};
LoRaPHY::LoRaPHY()
: _radio(NULL)
{
}
LoRaPHY::~LoRaPHY()
{
}
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++];
}
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(uint8_t nb_channels, uint16_t *channel_mask,
int8_t dr, int8_t min_dr, int8_t max_dr,
channel_params_t *channels)
{
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::intersect_channel_mask(const uint16_t *source,
uint16_t *destination, uint8_t size)
{
}
void LoRaPHY::fill_channel_mask_with_fsb(const uint16_t *expectation,
const uint16_t *fsb_mask,
uint16_t *destination,
uint8_t size)
{
}
void LoRaPHY::fill_channel_mask_with_value(uint16_t *channel_mask,
uint16_t value, uint8_t size)
{
}
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)
{
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;
}
double LoRaPHY::compute_symb_timeout_lora(uint8_t phy_dr, uint32_t bandwidth)
{
return LoRaPHY_stub::double_value;
}
double LoRaPHY::compute_symb_timeout_fsk(uint8_t phy_dr)
{
return LoRaPHY_stub::double_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)
{
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,36 @@
/*
* 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 "stdint.h"
#include "stdbool.h"
#include <cstddef>
#include "lorawan_types.h"
namespace LoRaPHY_stub
{
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;
}