Import Mbed OS hard-float snapshot
This commit is contained in:
1
connectivity/lorawan/tests/.mbedignore
Normal file
1
connectivity/lorawan/tests/.mbedignore
Normal file
@@ -0,0 +1 @@
|
||||
UNITTESTS/*
|
||||
17
connectivity/lorawan/tests/TESTS/lorawan/loraradio/README.md
Normal file
17
connectivity/lorawan/tests/TESTS/lorawan/loraradio/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Description
|
||||
|
||||
This document describes how to run LoRaRadio API tests.
|
||||
|
||||
## Configuring target HW
|
||||
|
||||
Before starting to test, the target HW must be configured for the test. This can be done by either modifying the application configuration `json` file (if using currently supported Semtech SX1272 or SX1276 radios) or implementing driver construction into test source.
|
||||
|
||||
The default mbed_app.json file provides configuration for some already supported HWs.
|
||||
|
||||
## Running tests
|
||||
|
||||
You can use the following command to run tests:
|
||||
|
||||
`mbed test -n mbed-os-tests-lorawan-loraradio -m TARGET -t GCC_ARM --app-config mbed-os/TESTS/lorawan/loraradio/template_mbed_app.txt`
|
||||
|
||||
Replace TARGET with the target device.
|
||||
292
connectivity/lorawan/tests/TESTS/lorawan/loraradio/main.cpp
Normal file
292
connectivity/lorawan/tests/TESTS/lorawan/loraradio/main.cpp
Normal file
@@ -0,0 +1,292 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
* 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(MBED_CONF_RTOS_PRESENT)
|
||||
#error [NOT_SUPPORTED] LORADIO test cases require a RTOS to run.
|
||||
#else
|
||||
|
||||
#include "utest.h"
|
||||
#include "unity.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
|
||||
#include "Semaphore.h"
|
||||
#include "ThisThread.h"
|
||||
|
||||
#include "mbed_trace.h"
|
||||
#define TRACE_GROUP "RTST"
|
||||
|
||||
#include "LoRaRadio.h"
|
||||
|
||||
#define SX1272 0xFF
|
||||
#define SX1276 0xEE
|
||||
|
||||
#if (MBED_CONF_APP_LORA_RADIO == SX1272)
|
||||
#include "SX1272_LoRaRadio.h"
|
||||
#elif (MBED_CONF_APP_LORA_RADIO == SX1276)
|
||||
#include "SX1276_LoRaRadio.h"
|
||||
#else
|
||||
#error [NOT_SUPPORTED] Requires parameters from application config file.
|
||||
#endif
|
||||
|
||||
#if (MBED_CONF_APP_LORA_RADIO == SX1272) || (MBED_CONF_APP_LORA_RADIO == SX1276)
|
||||
|
||||
using namespace utest::v1;
|
||||
using namespace mbed;
|
||||
|
||||
static LoRaRadio *radio = NULL;
|
||||
rtos::Semaphore event_sem(0);
|
||||
|
||||
enum event_t {
|
||||
EV_NONE,
|
||||
EV_TX_DONE,
|
||||
EV_TX_TIMEOUT,
|
||||
EV_RX_DONE,
|
||||
EV_RX_TIMEOUT,
|
||||
EV_RX_ERROR,
|
||||
};
|
||||
static volatile event_t received_event;
|
||||
|
||||
|
||||
static void tx_done()
|
||||
{
|
||||
rtos::ThisThread::sleep_for(2);
|
||||
TEST_ASSERT_EQUAL(EV_NONE, received_event);
|
||||
received_event = EV_TX_DONE;
|
||||
TEST_ASSERT_EQUAL(osOK, event_sem.release());
|
||||
}
|
||||
|
||||
static void tx_timeout()
|
||||
{
|
||||
rtos::ThisThread::sleep_for(2);
|
||||
TEST_ASSERT_EQUAL(EV_NONE, received_event);
|
||||
received_event = EV_TX_TIMEOUT;
|
||||
TEST_ASSERT_EQUAL(osOK, event_sem.release());
|
||||
}
|
||||
|
||||
static void rx_done(const uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
|
||||
{
|
||||
rtos::ThisThread::sleep_for(2);
|
||||
TEST_ASSERT_EQUAL(EV_NONE, received_event);
|
||||
received_event = EV_RX_DONE;
|
||||
TEST_ASSERT_EQUAL(osOK, event_sem.release());
|
||||
}
|
||||
|
||||
static void rx_timeout()
|
||||
{
|
||||
rtos::ThisThread::sleep_for(2);
|
||||
TEST_ASSERT_EQUAL(EV_NONE, received_event);
|
||||
received_event = EV_RX_TIMEOUT;
|
||||
TEST_ASSERT_EQUAL(osOK, event_sem.release());
|
||||
}
|
||||
|
||||
static void rx_error()
|
||||
{
|
||||
rtos::ThisThread::sleep_for(2);
|
||||
TEST_ASSERT_EQUAL(EV_NONE, received_event);
|
||||
received_event = EV_RX_ERROR;
|
||||
TEST_ASSERT_EQUAL(osOK, event_sem.release());
|
||||
}
|
||||
|
||||
static radio_events radio_callbacks = {
|
||||
.tx_done = tx_done,
|
||||
.tx_timeout = tx_timeout,
|
||||
.rx_done = rx_done,
|
||||
.rx_timeout = rx_timeout,
|
||||
.rx_error = rx_error
|
||||
};
|
||||
|
||||
|
||||
void test_random()
|
||||
{
|
||||
const uint32_t rand1 = radio->random();
|
||||
const uint32_t rand2 = radio->random();
|
||||
TEST_ASSERT_NOT_EQUAL(rand1, rand2);
|
||||
}
|
||||
|
||||
void test_set_tx_config()
|
||||
{
|
||||
uint8_t buffer[] = {0};
|
||||
|
||||
TEST_ASSERT_EQUAL(RF_IDLE, radio->get_status());
|
||||
|
||||
radio->set_tx_config(MODEM_LORA, 13, 0,
|
||||
0, 7,
|
||||
1, 8,
|
||||
false, true, false,
|
||||
0, false, 100);
|
||||
radio->send(buffer, sizeof(buffer));
|
||||
|
||||
TEST_ASSERT_EQUAL(RF_TX_RUNNING, radio->get_status());
|
||||
|
||||
TEST_ASSERT_TRUE(event_sem.try_acquire_for(1000));
|
||||
TEST_ASSERT_EQUAL(EV_TX_DONE, received_event);
|
||||
received_event = EV_NONE;
|
||||
}
|
||||
|
||||
void test_set_rx_config()
|
||||
{
|
||||
TEST_ASSERT_EQUAL(RF_IDLE, radio->get_status());
|
||||
|
||||
radio->set_rx_config(MODEM_LORA, 0, // modem, bandwidth,
|
||||
7, 1, // datarate, coderate,
|
||||
0, 8, // bandwidth_afc, preamble_len,
|
||||
24, false, // symb_timeout, fix_len,
|
||||
0, // payload_len,
|
||||
false, false, 0, // crc_on, freq_hop_on, hop_period,
|
||||
true, false); // iq_inverted, rx_continuous
|
||||
radio->receive();
|
||||
|
||||
TEST_ASSERT_EQUAL(RF_RX_RUNNING, radio->get_status());
|
||||
|
||||
TEST_ASSERT_TRUE(event_sem.try_acquire_for(1000));
|
||||
|
||||
// Nobody was sending to us so timeout is expected.
|
||||
TEST_ASSERT_EQUAL(EV_RX_TIMEOUT, received_event);
|
||||
received_event = EV_NONE;
|
||||
}
|
||||
|
||||
void test_time_on_air()
|
||||
{
|
||||
radio->set_rx_config(MODEM_LORA, 0,
|
||||
7, 1,
|
||||
0, 8,
|
||||
24, false,
|
||||
0,
|
||||
false, false, 0,
|
||||
true, false);
|
||||
TEST_ASSERT_EQUAL(52, radio->time_on_air(MODEM_LORA, 20));
|
||||
|
||||
radio->set_tx_config(MODEM_LORA, 13, 0,
|
||||
0, 7,
|
||||
1, 8,
|
||||
false, true, false,
|
||||
0, false, 100);
|
||||
TEST_ASSERT_EQUAL(72, radio->time_on_air(MODEM_LORA, 32));
|
||||
|
||||
// TODO: Add FSK tests
|
||||
}
|
||||
|
||||
void test_perform_carrier_sense()
|
||||
{
|
||||
TEST_ASSERT_TRUE(radio->perform_carrier_sense(MODEM_FSK, 865000000, -20, 1));
|
||||
TEST_ASSERT_TRUE(radio->perform_carrier_sense(MODEM_LORA, 865000000, -20, 1));
|
||||
}
|
||||
|
||||
void test_check_rf_frequency()
|
||||
{
|
||||
// Test EU868 frequency
|
||||
TEST_ASSERT_TRUE(radio->check_rf_frequency(865000000));
|
||||
}
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(20, "default_auto");
|
||||
|
||||
mbed_trace_init();
|
||||
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
|
||||
{
|
||||
#if (MBED_CONF_APP_LORA_RADIO == SX1272)
|
||||
|
||||
radio = new SX1272_LoRaRadio(MBED_CONF_APP_LORA_SPI_MOSI,
|
||||
MBED_CONF_APP_LORA_SPI_MISO,
|
||||
MBED_CONF_APP_LORA_SPI_SCLK,
|
||||
MBED_CONF_APP_LORA_CS,
|
||||
MBED_CONF_APP_LORA_RESET,
|
||||
MBED_CONF_APP_LORA_DIO0,
|
||||
MBED_CONF_APP_LORA_DIO1,
|
||||
MBED_CONF_APP_LORA_DIO2,
|
||||
MBED_CONF_APP_LORA_DIO3,
|
||||
MBED_CONF_APP_LORA_DIO4,
|
||||
MBED_CONF_APP_LORA_DIO5,
|
||||
MBED_CONF_APP_LORA_RF_SWITCH_CTL1,
|
||||
MBED_CONF_APP_LORA_RF_SWITCH_CTL2,
|
||||
MBED_CONF_APP_LORA_TXCTL,
|
||||
MBED_CONF_APP_LORA_RXCTL,
|
||||
MBED_CONF_APP_LORA_ANT_SWITCH,
|
||||
MBED_CONF_APP_LORA_PWR_AMP_CTL,
|
||||
MBED_CONF_APP_LORA_TCXO);
|
||||
|
||||
#elif (MBED_CONF_APP_LORA_RADIO == SX1276)
|
||||
|
||||
radio = new SX1276_LoRaRadio(MBED_CONF_APP_LORA_SPI_MOSI,
|
||||
MBED_CONF_APP_LORA_SPI_MISO,
|
||||
MBED_CONF_APP_LORA_SPI_SCLK,
|
||||
MBED_CONF_APP_LORA_CS,
|
||||
MBED_CONF_APP_LORA_RESET,
|
||||
MBED_CONF_APP_LORA_DIO0,
|
||||
MBED_CONF_APP_LORA_DIO1,
|
||||
MBED_CONF_APP_LORA_DIO2,
|
||||
MBED_CONF_APP_LORA_DIO3,
|
||||
MBED_CONF_APP_LORA_DIO4,
|
||||
MBED_CONF_APP_LORA_DIO5,
|
||||
MBED_CONF_APP_LORA_RF_SWITCH_CTL1,
|
||||
MBED_CONF_APP_LORA_RF_SWITCH_CTL2,
|
||||
MBED_CONF_APP_LORA_TXCTL,
|
||||
MBED_CONF_APP_LORA_RXCTL,
|
||||
MBED_CONF_APP_LORA_ANT_SWITCH,
|
||||
MBED_CONF_APP_LORA_PWR_AMP_CTL,
|
||||
MBED_CONF_APP_LORA_TCXO);
|
||||
|
||||
#else
|
||||
#error [NOT_SUPPORTED] Unknown LoRa radio specified (SX1272,SX1276 are valid)
|
||||
#endif
|
||||
|
||||
TEST_ASSERT(radio);
|
||||
radio->init_radio(&radio_callbacks);
|
||||
radio->sleep();
|
||||
|
||||
return greentea_case_setup_handler(source, index_of_case);
|
||||
}
|
||||
|
||||
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
|
||||
{
|
||||
radio->sleep();
|
||||
|
||||
#if (MBED_CONF_APP_LORA_RADIO == SX1272)
|
||||
delete static_cast<SX1272_LoRaRadio *>(radio);
|
||||
#elif (MBED_CONF_APP_LORA_RADIO == SX1276)
|
||||
delete static_cast<SX1276_LoRaRadio *>(radio);
|
||||
#else
|
||||
#error [NOT_SUPPORTED] Unknown LoRa radio specified (SX1272,SX1276 are valid)
|
||||
#endif
|
||||
radio = NULL;
|
||||
|
||||
return greentea_case_teardown_handler(source, passed, failed, reason);
|
||||
}
|
||||
|
||||
const Case cases[] = {
|
||||
Case("Test random", case_setup_handler, test_random, case_teardown_handler),
|
||||
Case("Test set_tx_config", case_setup_handler, test_set_tx_config, case_teardown_handler),
|
||||
Case("Test set_rx_config", case_setup_handler, test_set_rx_config, case_teardown_handler),
|
||||
Case("Test time_on_air", case_setup_handler, test_time_on_air, case_teardown_handler),
|
||||
Case("Test perform_carrier_sense", case_setup_handler, test_perform_carrier_sense, case_teardown_handler),
|
||||
Case("Test check_rf_frequency", case_setup_handler, test_check_rf_frequency, case_teardown_handler),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // (MBED_CONF_APP_LORA_RADIO == SX1272) || (MBED_CONF_APP_LORA_RADIO == SX1276)
|
||||
#endif // !defined(MBED_CONF_RTOS_PRESENT)
|
||||
@@ -0,0 +1,160 @@
|
||||
{
|
||||
"config": {
|
||||
"lora-radio": {
|
||||
"help": "Which radio to use (options: SX1272,SX1276)",
|
||||
"value": "SX1276"
|
||||
},
|
||||
|
||||
"lora-spi-mosi": { "value": "NC" },
|
||||
"lora-spi-miso": { "value": "NC" },
|
||||
"lora-spi-sclk": { "value": "NC" },
|
||||
"lora-cs": { "value": "NC" },
|
||||
"lora-reset": { "value": "NC" },
|
||||
"lora-dio0": { "value": "NC" },
|
||||
"lora-dio1": { "value": "NC" },
|
||||
"lora-dio2": { "value": "NC" },
|
||||
"lora-dio3": { "value": "NC" },
|
||||
"lora-dio4": { "value": "NC" },
|
||||
"lora-dio5": { "value": "NC" },
|
||||
"lora-rf-switch-ctl1": { "value": "NC" },
|
||||
"lora-rf-switch-ctl2": { "value": "NC" },
|
||||
"lora-txctl": { "value": "NC" },
|
||||
"lora-rxctl": { "value": "NC" },
|
||||
"lora-ant-switch": { "value": "NC" },
|
||||
"lora-pwr-amp-ctl": { "value": "NC" },
|
||||
"lora-tcxo": { "value": "NC" }
|
||||
},
|
||||
"target_overrides": {
|
||||
|
||||
"K64F": {
|
||||
"lora-spi-mosi": "D11",
|
||||
"lora-spi-miso": "D12",
|
||||
"lora-spi-sclk": "D13",
|
||||
"lora-cs": "D10",
|
||||
"lora-reset": "A0",
|
||||
"lora-dio0": "D2",
|
||||
"lora-dio1": "D3",
|
||||
"lora-dio2": "D4",
|
||||
"lora-dio3": "D5",
|
||||
"lora-dio4": "D8",
|
||||
"lora-dio5": "D9",
|
||||
"lora-rf-switch-ctl1": "NC",
|
||||
"lora-rf-switch-ctl2": "NC",
|
||||
"lora-txctl": "NC",
|
||||
"lora-rxctl": "NC",
|
||||
"lora-ant-switch": "A4",
|
||||
"lora-pwr-amp-ctl": "NC",
|
||||
"lora-tcxo": "NC"
|
||||
},
|
||||
|
||||
"DISCO_L072CZ_LRWAN1": {
|
||||
"lora-radio": "SX1276",
|
||||
"lora-spi-mosi": "PA_7",
|
||||
"lora-spi-miso": "PA_6",
|
||||
"lora-spi-sclk": "PB_3",
|
||||
"lora-cs": "PA_15",
|
||||
"lora-reset": "PC_0",
|
||||
"lora-dio0": "PB_4",
|
||||
"lora-dio1": "PB_1",
|
||||
"lora-dio2": "PB_0",
|
||||
"lora-dio3": "PC_13",
|
||||
"lora-dio4": "NC",
|
||||
"lora-dio5": "NC",
|
||||
"lora-rf-switch-ctl1": "NC",
|
||||
"lora-rf-switch-ctl2": "NC",
|
||||
"lora-txctl": "PC_2",
|
||||
"lora-rxctl": "PA_1",
|
||||
"lora-ant-switch": "NC",
|
||||
"lora-pwr-amp-ctl": "PC_1",
|
||||
"lora-tcxo": "PA_12"
|
||||
},
|
||||
|
||||
"XDOT_L151CC": {
|
||||
"lora-radio": "SX1272",
|
||||
"lora-spi-mosi": "LORA_MOSI",
|
||||
"lora-spi-miso": "LORA_MISO",
|
||||
"lora-spi-sclk": "LORA_SCK",
|
||||
"lora-cs": "LORA_NSS",
|
||||
"lora-reset": "LORA_RESET",
|
||||
"lora-dio0": "LORA_DIO0",
|
||||
"lora-dio1": "LORA_DIO1",
|
||||
"lora-dio2": "LORA_DIO2",
|
||||
"lora-dio3": "LORA_DIO3",
|
||||
"lora-dio4": "LORA_DIO4",
|
||||
"lora-dio5": "NC",
|
||||
"lora-rf-switch-ctl1": "NC",
|
||||
"lora-rf-switch-ctl2": "NC",
|
||||
"lora-txctl": "NC",
|
||||
"lora-rxctl": "NC",
|
||||
"lora-ant-switch": "NC",
|
||||
"lora-pwr-amp-ctl": "NC",
|
||||
"lora-tcxo": "NC"
|
||||
},
|
||||
|
||||
"LTEK_FF1705": {
|
||||
"lora-radio": "SX1272",
|
||||
"lora-spi-mosi": "LORA_MOSI",
|
||||
"lora-spi-miso": "LORA_MISO",
|
||||
"lora-spi-sclk": "LORA_SCK",
|
||||
"lora-cs": "LORA_NSS",
|
||||
"lora-reset": "LORA_RESET",
|
||||
"lora-dio0": "LORA_DIO0",
|
||||
"lora-dio1": "LORA_DIO1",
|
||||
"lora-dio2": "LORA_DIO2",
|
||||
"lora-dio3": "LORA_DIO3",
|
||||
"lora-dio4": "LORA_DIO4",
|
||||
"lora-dio5": "NC",
|
||||
"lora-rf-switch-ctl1": "NC",
|
||||
"lora-rf-switch-ctl2": "NC",
|
||||
"lora-txctl": "NC",
|
||||
"lora-rxctl": "NC",
|
||||
"lora-ant-switch": "NC",
|
||||
"lora-pwr-amp-ctl": "NC",
|
||||
"lora-tcxo": "NC"
|
||||
},
|
||||
|
||||
"MTS_MDOT_F411RE": {
|
||||
"lora-radio": "SX1272",
|
||||
"lora-spi-mosi": "LORA_MOSI",
|
||||
"lora-spi-miso": "LORA_MISO",
|
||||
"lora-spi-sclk": "LORA_SCK",
|
||||
"lora-cs": "LORA_NSS",
|
||||
"lora-reset": "LORA_RESET",
|
||||
"lora-dio0": "LORA_DIO0",
|
||||
"lora-dio1": "LORA_DIO1",
|
||||
"lora-dio2": "LORA_DIO2",
|
||||
"lora-dio3": "LORA_DIO3",
|
||||
"lora-dio4": "LORA_DIO4",
|
||||
"lora-dio5": "LORA_DIO5",
|
||||
"lora-rf-switch-ctl1": "NC",
|
||||
"lora-rf-switch-ctl2": "NC",
|
||||
"lora-txctl": "LORA_TXCTL",
|
||||
"lora-rxctl": "LORA_RXCTL",
|
||||
"lora-ant-switch": "NC",
|
||||
"lora-pwr-amp-ctl": "NC",
|
||||
"lora-tcxo": "NC"
|
||||
},
|
||||
|
||||
"ADV_WISE_1510": {
|
||||
"lora-radio": "SX1276",
|
||||
"lora-spi-mosi": "SPI_RF_MOSI",
|
||||
"lora-spi-miso": "SPI_RF_MISO",
|
||||
"lora-spi-sclk": "SPI_RF_SCK",
|
||||
"lora-cs": "SPI_RF_CS",
|
||||
"lora-reset": "SPI_RF_RESET",
|
||||
"lora-dio0": "DIO0",
|
||||
"lora-dio1": "DIO1",
|
||||
"lora-dio2": "DIO2",
|
||||
"lora-dio3": "DIO3",
|
||||
"lora-dio4": "DIO4",
|
||||
"lora-dio5": "DIO5",
|
||||
"lora-rf-switch-ctl1": "NC",
|
||||
"lora-rf-switch-ctl2": "NC",
|
||||
"lora-txctl": "NC",
|
||||
"lora-rxctl": "NC",
|
||||
"lora-ant-switch": "ANT_SWITCH",
|
||||
"lora-pwr-amp-ctl": "NC",
|
||||
"lora-tcxo": "NC"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,605 @@
|
||||
/*
|
||||
* 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();
|
||||
LoRaWANTimer_stub::time_value = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
memset(&conn, 0, sizeof(conn));
|
||||
uint8_t key[16];
|
||||
memset(key, 0, sizeof(key));
|
||||
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);
|
||||
|
||||
channel_params_t params[] = {868300000, 0, { ((DR_5 << 4) | DR_0) }, 1};
|
||||
LoRaPHY_stub::channel_params_ptr = params;
|
||||
|
||||
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;
|
||||
memset(&p, 0, sizeof(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;
|
||||
memset(&p, 0, sizeof(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;
|
||||
memset(&mac_hdr, 0, sizeof(mac_hdr));
|
||||
uint8_t buf[15];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
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];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
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);
|
||||
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
object->set_device_class(CLASS_C, 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;
|
||||
memset(&conn, 0, sizeof(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;
|
||||
memset(&conn, 0, sizeof(conn));
|
||||
uint8_t key[16];
|
||||
memset(key, 0, sizeof(key));
|
||||
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];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
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;
|
||||
memset(&conn, 0, sizeof(conn));
|
||||
uint8_t key[16];
|
||||
memset(key, 0, sizeof(key));
|
||||
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];
|
||||
memset(data, 0, sizeof(data));
|
||||
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_NO_OP, object->clear_tx_pipe()); //timer id == 0
|
||||
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
|
||||
lorawan_connect_t conn;
|
||||
memset(&conn, 0, sizeof(conn));
|
||||
uint8_t key[16];
|
||||
memset(key, 0, sizeof(key));
|
||||
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);
|
||||
|
||||
channel_params_t params[] = {868300000, 0, { ((DR_5 << 4) | DR_0) }, 1};
|
||||
LoRaPHY_stub::channel_params_ptr = params;
|
||||
LoRaWANTimer_stub::call_cb_immediately = 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());
|
||||
loramac_mhdr_t machdr;
|
||||
machdr.bits.mtype = MCPS_UNCONFIRMED;
|
||||
uint8_t buf[1];
|
||||
buf[0] = 'T';
|
||||
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_DUTYCYCLE_RESTRICTED;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->send(&machdr, 15, buf, 1));
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_QOS_level)
|
||||
{
|
||||
EXPECT_EQ(0, object->get_QOS_level());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_prev_QOS_level)
|
||||
{
|
||||
EXPECT_EQ(1, object->get_prev_QOS_level());
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/mac/LoRaMac.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaMac.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANStack_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/LoRaMacCrypto_stub.cpp
|
||||
stubs/LoRaMacChannelPlan_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/LoRaMacCommand_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/Mutex_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-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
|
||||
-DMBED_CONF_LORA_DUTY_CYCLE_ON=true
|
||||
-DMBED_CONF_LORA_MAX_SYS_RX_ERROR=10
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DEVICE_ADDRESS=0x00000000
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -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_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}\"")
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* 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;
|
||||
memset(&plan, 0, sizeof(plan));
|
||||
memset(&LoRaPHY_stub::bool_table, 0, sizeof(LoRaPHY_stub::bool_table));
|
||||
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;
|
||||
loramac_channel_t chan;
|
||||
memset(&chan, 0, sizeof(chan));
|
||||
plan.channels = &chan;
|
||||
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, ¶ms) == 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, ¶ms) == 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, ¶ms) == 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);
|
||||
}
|
||||
|
||||
@@ -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_LoRaMacChannelPlan")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/lorawan/lorastack/mac/LoRaMacChannelPlan.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaMacChannelPlan.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
)
|
||||
@@ -0,0 +1,352 @@
|
||||
/*
|
||||
* 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] = 4;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
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] = 4;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_dl_channel_ans
|
||||
object->clear_command_buffer();
|
||||
for (int i = 0; i < 64; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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_LoRaMacCommand")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/lorawan/lorastack/mac/LoRaMacCommand.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaMacCommand.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
)
|
||||
@@ -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));
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/mac/LoRaMacCrypto.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaMacCrypto.cpp
|
||||
stubs/cipher_stub.c
|
||||
stubs/aes_stub.c
|
||||
stubs/cmac_stub.c
|
||||
stubs/mbed_assert_stub.cpp
|
||||
../connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
)
|
||||
@@ -0,0 +1,944 @@
|
||||
/*
|
||||
* 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();
|
||||
memset(&object->get_phy_params(), 0, sizeof(object->get_phy_params()));
|
||||
}
|
||||
|
||||
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;
|
||||
p[0].dr_range.fields.min = DR_0;
|
||||
p[0].dr_range.fields.max = DR_5;
|
||||
object->get_phy_params().channels.channel_list = p;
|
||||
band_t b[1];
|
||||
b[0].duty_cycle = 0;
|
||||
b[0].higher_band_freq = 8689000;
|
||||
b[0].lower_band_freq = 8687000;
|
||||
b[0].max_tx_pwr = 20;
|
||||
b[0].last_join_tx_time = 0;
|
||||
b[0].last_tx_time = 0;
|
||||
b[0].off_time = 0;
|
||||
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;
|
||||
buf = 0x08;
|
||||
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)
|
||||
{
|
||||
band_t b;
|
||||
object->get_phy_params().bands.size = 1;
|
||||
b.higher_band_freq = 8689000;
|
||||
b.lower_band_freq = 8678000;
|
||||
b.duty_cycle = 0;
|
||||
b.last_join_tx_time = 0;
|
||||
b.last_tx_time = 0;
|
||||
b.max_tx_pwr = 20;
|
||||
b.off_time = 0;
|
||||
object->get_phy_params().bands.table = &b;
|
||||
|
||||
channel_params_t p;
|
||||
//First 3 channels are set to be default
|
||||
p.band = 0;
|
||||
p.dr_range.fields.min = DR_0;
|
||||
p.dr_range.fields.max = DR_5;
|
||||
p.frequency = 8687000;
|
||||
p.rx1_frequency = 0;
|
||||
uint16_t dflt_msk = 0x07;
|
||||
object->get_phy_params().channels.default_mask = &dflt_msk;
|
||||
object->get_phy_params().channels.channel_list = &p;
|
||||
object->get_phy_params().custom_channelplans_supported = true;
|
||||
|
||||
//Default channel, PARAMETER invalid
|
||||
EXPECT_TRUE(0 == object->request_new_channel(0, &p));
|
||||
|
||||
//Freq & DR invalid
|
||||
p.frequency = 12345;
|
||||
p.dr_range.fields.max = 12;
|
||||
object->get_phy_params().max_channel_cnt = 16;
|
||||
object->get_phy_params().min_tx_datarate = DR_0;
|
||||
object->get_phy_params().max_tx_datarate = DR_5;
|
||||
// Frequency and DR are invalid - LORAWAN_STATUS_FREQ_AND_DR_INVALID
|
||||
EXPECT_TRUE(0 == object->request_new_channel(0, &p));
|
||||
|
||||
//Freq invalid
|
||||
p.frequency = 12345;
|
||||
p.dr_range.fields.max = DR_5;
|
||||
object->get_phy_params().default_channel_cnt = 3;
|
||||
EXPECT_TRUE(2 == object->request_new_channel(0, &p));
|
||||
|
||||
//DR invalid
|
||||
p.frequency = 8687000;
|
||||
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 = DR_5;
|
||||
p.dr_range.fields.min = DR_0;
|
||||
uint16_t ch_msk = 0x08;
|
||||
object->get_phy_params().channels.mask = &ch_msk;
|
||||
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];
|
||||
memset(list, 0, 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 = 1;
|
||||
object->get_phy_params().cflist_channel_cnt = 0;
|
||||
object->get_phy_params().max_channel_cnt = 3;
|
||||
|
||||
uint16_t def_mask = 0x01;
|
||||
channel_params_t p[16];
|
||||
memset(p, 0, 16);
|
||||
//one default channel
|
||||
p[0].band = 0;
|
||||
p[0].dr_range.fields.min = DR_0;
|
||||
p[0].dr_range.fields.min = DR_5;
|
||||
p[0].frequency = 8687000;
|
||||
|
||||
object->get_phy_params().channels.default_mask = &def_mask;
|
||||
object->get_phy_params().channels.mask = &def_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;
|
||||
memset(&p, 0, sizeof(rx_config_params_t));
|
||||
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] = 125000;
|
||||
object->get_phy_params().bandwidths.table = list;
|
||||
uint8_t list2[1];
|
||||
list2[0] = 12;
|
||||
object->get_phy_params().datarates.table = &list2;
|
||||
channel_params_t ch_lst[16];
|
||||
memset(ch_lst, 0, sizeof(channel_params_t) * 16);
|
||||
ch_lst[0].band = 0;
|
||||
ch_lst[0].dr_range.fields.min = DR_0;
|
||||
ch_lst[0].dr_range.fields.max = DR_5;
|
||||
ch_lst[0].frequency = 8687000;
|
||||
object->get_phy_params().channels.channel_list = ch_lst;
|
||||
object->get_phy_params().channels.channel_list_size = 16;
|
||||
rx_config_params_t p;
|
||||
memset(&p, 0, sizeof(rx_config_params_t));
|
||||
p.frequency = 8687000;
|
||||
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;
|
||||
memset(&b, 0, sizeof(band_t));
|
||||
object->get_phy_params().bands.table = &b;
|
||||
channel_params_t pp;
|
||||
memset(&pp, 0, sizeof(channel_params_t));
|
||||
pp.band = 0;
|
||||
object->get_phy_params().channels.channel_list = &pp;
|
||||
uint32_t list[1];
|
||||
list[0] = 125000;
|
||||
object->get_phy_params().bandwidths.table = &list;
|
||||
uint8_t list2[1];
|
||||
list2[0] = 12;
|
||||
object->get_phy_params().datarates.table = &list2;
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
tx_config_params_t p;
|
||||
memset(&p, 0, sizeof(tx_config_params_t));
|
||||
p.channel = 0;
|
||||
int8_t i = 20;
|
||||
lorawan_time_t t = 36;
|
||||
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;
|
||||
memset(&p, 0, sizeof(adr_req_params_t));
|
||||
uint8_t b[100];
|
||||
memset(b, 0, 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 = 0, j = 0;
|
||||
uint8_t k = 0, l = 0;
|
||||
uint8_t t[5] = {12, 11, 10, 9, 8};
|
||||
t[0] = 0;
|
||||
object->get_phy_params().datarates.size = 5;
|
||||
object->get_phy_params().datarates.table = t;
|
||||
//Test without ADR payload does not make sense here.
|
||||
|
||||
object->get_phy_params().max_channel_cnt = 16;
|
||||
channel_params_t li[16];
|
||||
memset(li, 0, sizeof(channel_params_t) * 16);
|
||||
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_trans = 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;
|
||||
radio.bool_value = true;
|
||||
object->set_radio_instance(radio);
|
||||
rx_param_setup_req_t req;
|
||||
req.datarate = DR_0;
|
||||
req.dr_offset = 0;
|
||||
req.frequency = 8678000;
|
||||
band_t band[1];
|
||||
memset(band, 0, sizeof(band_t));
|
||||
band[0].higher_band_freq = 8688000;
|
||||
band[0].lower_band_freq = 8666000;
|
||||
object->get_phy_params().bands.size = 1;
|
||||
object->get_phy_params().bands.table = band;
|
||||
EXPECT_TRUE(0x07 == 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];
|
||||
memset(t, 0, sizeof(band_t));
|
||||
t[0].higher_band_freq = 8688000;
|
||||
t[0].lower_band_freq = 8668000;
|
||||
object->get_phy_params().bands.size = 1;
|
||||
object->get_phy_params().bands.table = t;
|
||||
channel_params_t p[16];
|
||||
memset(p, 0, sizeof(channel_params_t) * 16);
|
||||
object->get_phy_params().channels.channel_list_size = 16;
|
||||
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;
|
||||
memset(&p, 0, sizeof(channel_selection_params_t));
|
||||
band_t band[1];
|
||||
memset(band, 0, sizeof(band_t));
|
||||
band[0].higher_band_freq = 8687000;
|
||||
object->get_phy_params().bands.size = 1;
|
||||
object->get_phy_params().bands.table = band;
|
||||
uint8_t ch = 5;
|
||||
lorawan_time_t t1 = 16;
|
||||
lorawan_time_t t2 = 32;
|
||||
p.aggregate_timeoff = 10000;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
uint16_t list[129];
|
||||
memset(list, 0, sizeof(list));
|
||||
list[4] = 1;
|
||||
list[128] = 1;
|
||||
object->get_phy_params().channels.mask = list;
|
||||
object->get_phy_params().channels.default_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];
|
||||
ch = 5;
|
||||
t1 = 16;
|
||||
t2 = 32;
|
||||
memset(b, 0, sizeof(band_t) * 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;
|
||||
memset(list, 0, 129);
|
||||
list[4] = 0;
|
||||
object->get_phy_params().channels.mask = list;
|
||||
object->get_phy_params().channels.default_mask = list;
|
||||
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;
|
||||
p.band = 0;
|
||||
p.frequency = 0;
|
||||
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;
|
||||
b.max_tx_pwr = 10;
|
||||
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;
|
||||
p.tx_power = -1;
|
||||
p.datarate = 0;
|
||||
p.antenna_gain = 1;
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHY.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHY.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_WAKEUP_TIME=5
|
||||
-DMBED_CONF_LORA_DUTY_CYCLE_ON_JOIN=true
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_NB_TRIALS=2
|
||||
)
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYAS923.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* 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;
|
||||
memset(&p, 0, sizeof(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;
|
||||
memset(&p, 0, sizeof(p));
|
||||
int8_t tx = 0;
|
||||
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;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
int8_t dr_out = 0;
|
||||
int8_t tx_power_out = 0;
|
||||
uint8_t nb_rep_out = 0;
|
||||
uint8_t nb_bytes_parsed = 0;
|
||||
|
||||
uint8_t payload [] = {SRV_MAC_LINK_ADR_REQ, 1, 2, 3, 4};
|
||||
params.payload = payload;
|
||||
params.payload_size = 5;
|
||||
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
LoRaPHY_stub::ch_mask_value = 6;
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &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(¶ms, &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(¶ms, &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(¶ms, &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;
|
||||
memset(&p, 0, sizeof(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(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
radio.bool_value = false;
|
||||
params.aggregate_timeoff = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYAU915.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYAU915.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
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}\"")
|
||||
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
uint8_t channel = 0;
|
||||
lorawan_time_t time = 0;
|
||||
lorawan_time_t timeoff = 0;
|
||||
|
||||
params.current_datarate = 4;
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
radio.bool_value = false;
|
||||
params.aggregate_timeoff = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, rx_config)
|
||||
{
|
||||
rx_config_params_t p;
|
||||
memset(&p, 0, sizeof(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;
|
||||
memset(&p, 0, sizeof(p));
|
||||
int8_t tx = 0;
|
||||
lorawan_time_t time = 0;
|
||||
p.tx_power = 9;
|
||||
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, link_ADR_request)
|
||||
{
|
||||
adr_req_params_t params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
int8_t dr_out = 0;
|
||||
int8_t tx_power_out = 0;
|
||||
uint8_t nb_rep_out = 0;
|
||||
uint8_t nb_bytes_parsed = 0;
|
||||
|
||||
uint8_t payload [] = {SRV_MAC_LINK_ADR_REQ, 1, 2, 3, 4};
|
||||
params.payload = payload;
|
||||
params.payload_size = 5;
|
||||
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
LoRaPHY_stub::ch_mask_value = 6;
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &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(¶ms, &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(¶ms, &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(¶ms, &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;
|
||||
memset(&p, 0, sizeof(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));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYCN470.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYCN470.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
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}\"")
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYCN779")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYCN779.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYCN779.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
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}\"")
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYEU433.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYEU433.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYEU868.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYEU868.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYIN865.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYIN865.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* 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;
|
||||
memset(&tx_config, 0, sizeof(tx_config));
|
||||
int8_t tx_power = 0;
|
||||
lorawan_time_t time = 0;
|
||||
|
||||
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;
|
||||
memset(&next_channel, 0, sizeof(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;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.tx_power = 9;
|
||||
object->set_tx_cont_mode(¶ms, 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYKR920.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYKR920.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* 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;
|
||||
memset(&p, 0, sizeof(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;
|
||||
memset(&p, 0, sizeof(p));
|
||||
int8_t tx = 0;
|
||||
lorawan_time_t time = 0;
|
||||
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYUS915, link_ADR_request)
|
||||
{
|
||||
uint8_t payload [] = {SRV_MAC_LINK_ADR_REQ, 1, 2, 3, 4};
|
||||
adr_req_params_t params;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
int8_t dr_out = 0;
|
||||
int8_t tx_power_out = 0;
|
||||
uint8_t nb_rep_out = 0;
|
||||
uint8_t nb_bytes_parsed = 0;
|
||||
|
||||
params.payload = payload;
|
||||
params.payload_size = 4;
|
||||
|
||||
uint8_t status = object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed);
|
||||
|
||||
EXPECT_TRUE(0 == nb_bytes_parsed);
|
||||
|
||||
params.payload_size = 5;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
LoRaPHY_stub::ch_mask_value = 6;
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &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(¶ms, &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(¶ms, &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(¶ms, &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;
|
||||
memset(&p, 0, sizeof(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));
|
||||
}
|
||||
|
||||
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;
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
uint8_t channel = 0;
|
||||
lorawan_time_t time = 0;
|
||||
lorawan_time_t timeoff = 0;
|
||||
|
||||
params.current_datarate = 4;
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
radio.bool_value = false;
|
||||
params.aggregate_timeoff = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &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;
|
||||
memset(&p, 0, sizeof(p));
|
||||
object->set_tx_cont_mode(&p, 0);
|
||||
|
||||
p.datarate = 4;
|
||||
object->set_tx_cont_mode(&p, 0);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#[[
|
||||
* 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
|
||||
../connectivity/lorawan/lorastack/phy/LoRaPHYUS915.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaPHYUS915.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
-DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5
|
||||
-DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8
|
||||
)
|
||||
|
||||
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}\"")
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == 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());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#[[
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaWANInterface")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/lorawan/source/LoRaWANInterface.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaWANInterface.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANStack_stub.cpp
|
||||
stubs/LoRaMac_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/LoRaMacCrypto_stub.cpp
|
||||
stubs/LoRaMacChannelPlan_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/LoRaMacCommand_stub.cpp
|
||||
stubs/LoRaPHYEU868_stub.cpp
|
||||
stubs/Mutex_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_PHY=EU868
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,931 @@
|
||||
/*
|
||||
* 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 "events/EventQueue.h"
|
||||
|
||||
#include "LoRaPHY_stub.h"
|
||||
#include "LoRaMac_stub.h"
|
||||
#include "equeue_stub.h"
|
||||
#include "system/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;
|
||||
struct equeue_event ptr;
|
||||
equeue_stub.void_ptr = &ptr;
|
||||
equeue_stub.call_cb_immediately = true;
|
||||
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));
|
||||
|
||||
struct equeue_event ptr;
|
||||
equeue_stub.void_ptr = &ptr;
|
||||
equeue_stub.call_cb_immediately = true;
|
||||
|
||||
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);
|
||||
|
||||
loramac_mcps_confirm_t conf;
|
||||
conf.status = LORAMAC_EVENT_INFO_STATUS_OK;
|
||||
LoRaMac_stub::mcps_conf_ptr = &conf;
|
||||
radio._ev->tx_done();
|
||||
|
||||
loramac_mcps_indication_t ind;
|
||||
ind.status = LORAMAC_EVENT_INFO_STATUS_OK;
|
||||
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_A;
|
||||
|
||||
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;
|
||||
ind.port = 15;
|
||||
ind.is_data_recvd = true;
|
||||
ind.fpending_status = false;
|
||||
LoRaMac_stub::dev_class_value = CLASS_A;
|
||||
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));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaWANStack, acquire_tx_metadata)
|
||||
{
|
||||
lorawan_tx_metadata data;
|
||||
memset(&data, 0, sizeof(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;
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
conf.status = LORAMAC_EVENT_INFO_STATUS_OK;
|
||||
LoRaMac_stub::mcps_conf_ptr = &conf;
|
||||
radio._ev->tx_done();
|
||||
|
||||
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
|
||||
radio._ev->rx_timeout();
|
||||
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_tx_metadata(data));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaWANStack, acquire_rx_metadata)
|
||||
{
|
||||
lorawan_rx_metadata data;
|
||||
memset(&data, 0, sizeof(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;
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
conf.status = LORAMAC_EVENT_INFO_STATUS_OK;
|
||||
LoRaMac_stub::mcps_conf_ptr = &conf;
|
||||
radio._ev->tx_done();
|
||||
|
||||
loramac_mcps_indication_t ind;
|
||||
memset(&ind, 0, sizeof(ind));
|
||||
ind.status = LORAMAC_EVENT_INFO_STATUS_OK;
|
||||
LoRaMac_stub::mcps_ind_ptr = &ind;
|
||||
|
||||
loramac_mlme_confirm_t mlme;
|
||||
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
|
||||
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;
|
||||
LoRaMac_stub::bool_true_counter = true;
|
||||
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_BUSY;
|
||||
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;
|
||||
memset(&conf, 0, sizeof(&conf));
|
||||
LoRaMac_stub::mcps_conf_ptr = &conf;
|
||||
radio._ev->tx_done();
|
||||
|
||||
loramac_mcps_indication_t ind;
|
||||
memset(&ind, 0, sizeof(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_true_counter++;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#[[
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaWANStack")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/lorawan/source/LoRaWANStack.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaWANStack.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaMac_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/mbed_atomic_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
|
||||
stubs/Mutex_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true
|
||||
-DMBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE=true
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
)
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#include "equeue_stub.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;
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
object->init(ev, my_callback);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaWANTimer, start)
|
||||
{
|
||||
equeue_stub.void_ptr = NULL;
|
||||
timer_event_t ev;
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
object->start(ev, 10);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaWANTimer, stop)
|
||||
{
|
||||
timer_event_t ev;
|
||||
memset(&ev, 0, sizeof(ev));
|
||||
ev.timer_id = 4;
|
||||
object->stop(ev);
|
||||
EXPECT_TRUE(ev.timer_id == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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_LoRaWANTimer")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/lorawan/system/LoRaWANTimer.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../connectivity/lorawan/system
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/Test_LoRaWANTimer.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/equeue_stub.c
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DNDEBUG=1
|
||||
-DMBED_CONF_LORA_TX_MAX_SIZE=255
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user