Skip to content

Commit ed8ebf3

Browse files
Antti Kauppilaadbridge
authored andcommitted
LorawanInterface unit test added
1 parent 474b652 commit ed8ebf3

File tree

9 files changed

+1362
-0
lines changed

9 files changed

+1362
-0
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "gtest/gtest.h"
19+
#include "LoRaWANInterface.h"
20+
21+
class my_radio : public LoRaRadio
22+
{
23+
public:
24+
25+
virtual void init_radio(radio_events_t *events){};
26+
27+
virtual void radio_reset(){};
28+
29+
virtual void sleep(void){};
30+
31+
virtual void standby(void){};
32+
33+
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
34+
uint32_t datarate, uint8_t coderate,
35+
uint32_t bandwidth_afc, uint16_t preamble_len,
36+
uint16_t symb_timeout, bool fix_len,
37+
uint8_t payload_len,
38+
bool crc_on, bool freq_hop_on, uint8_t hop_period,
39+
bool iq_inverted, bool rx_continuous){};
40+
41+
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
42+
uint32_t bandwidth, uint32_t datarate,
43+
uint8_t coderate, uint16_t preamble_len,
44+
bool fix_len, bool crc_on, bool freq_hop_on,
45+
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
46+
47+
virtual void send(uint8_t *buffer, uint8_t size){};
48+
49+
virtual void receive(void){};
50+
51+
virtual void set_channel(uint32_t freq){};
52+
53+
virtual uint32_t random(void){};
54+
55+
virtual uint8_t get_status(void){};
56+
57+
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
58+
59+
virtual void set_public_network(bool enable){};
60+
61+
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
62+
63+
virtual bool perform_carrier_sense(radio_modems_t modem,
64+
uint32_t freq,
65+
int16_t rssi_threshold,
66+
uint32_t max_carrier_sense_time){};
67+
68+
virtual void start_cad(void){};
69+
70+
virtual bool check_rf_frequency(uint32_t frequency){};
71+
72+
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
73+
74+
virtual void lock(void){};
75+
76+
virtual void unlock(void){};
77+
};
78+
79+
class my_LoRaPHY : public LoRaPHY
80+
{
81+
public:
82+
my_LoRaPHY(){};
83+
84+
virtual ~my_LoRaPHY(){};
85+
};
86+
87+
class Test_LoRaWANInterface : public testing::Test {
88+
protected:
89+
LoRaWANInterface *object;
90+
my_radio radio;
91+
92+
virtual void SetUp()
93+
{
94+
object = new LoRaWANInterface(radio);
95+
}
96+
97+
virtual void TearDown()
98+
{
99+
delete object;
100+
}
101+
};
102+
103+
TEST_F(Test_LoRaWANInterface, constructor)
104+
{
105+
EXPECT_TRUE(object);
106+
107+
my_radio radio;
108+
my_LoRaPHY phy;
109+
LoRaWANInterface object(radio, phy);
110+
}
111+
112+
TEST_F(Test_LoRaWANInterface, initialize)
113+
{
114+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL));
115+
}
116+
117+
TEST_F(Test_LoRaWANInterface, connect)
118+
{
119+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect());
120+
121+
lorawan_connect_t conn;
122+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
123+
}
124+
125+
TEST_F(Test_LoRaWANInterface, disconnect)
126+
{
127+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->disconnect());
128+
}
129+
130+
TEST_F(Test_LoRaWANInterface, add_link_check_request)
131+
{
132+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->add_link_check_request());
133+
}
134+
135+
TEST_F(Test_LoRaWANInterface, remove_link_check_request)
136+
{
137+
object->remove_link_check_request();
138+
}
139+
140+
TEST_F(Test_LoRaWANInterface, set_datarate)
141+
{
142+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_datarate(1));
143+
}
144+
145+
TEST_F(Test_LoRaWANInterface, enable_adaptive_datarate)
146+
{
147+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->enable_adaptive_datarate());
148+
}
149+
150+
TEST_F(Test_LoRaWANInterface, disable_adaptive_datarate)
151+
{
152+
object->disable_adaptive_datarate();
153+
}
154+
155+
TEST_F(Test_LoRaWANInterface, set_confirmed_msg_retries)
156+
{
157+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_confirmed_msg_retries(1));
158+
}
159+
160+
TEST_F(Test_LoRaWANInterface, set_channel_plan)
161+
{
162+
lorawan_channelplan_t plan;
163+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_channel_plan(plan));
164+
}
165+
166+
TEST_F(Test_LoRaWANInterface, get_channel_plan)
167+
{
168+
lorawan_channelplan_t plan;
169+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_channel_plan(plan));
170+
}
171+
172+
TEST_F(Test_LoRaWANInterface, remove_channel_plan)
173+
{
174+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->remove_channel_plan());
175+
}
176+
177+
TEST_F(Test_LoRaWANInterface, remove_channel)
178+
{
179+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->remove_channel(1));
180+
}
181+
182+
TEST_F(Test_LoRaWANInterface, send)
183+
{
184+
EXPECT_TRUE(0 == object->send(1, NULL, 0, 0));
185+
}
186+
187+
TEST_F(Test_LoRaWANInterface, receive)
188+
{
189+
EXPECT_TRUE(0 == object->receive(1, NULL, 0, 0));
190+
191+
uint8_t port;
192+
int flags;
193+
EXPECT_TRUE(0 == object->receive(NULL, 0, port, flags));
194+
}
195+
196+
TEST_F(Test_LoRaWANInterface, add_app_callbacks)
197+
{
198+
lorawan_app_callbacks_t cbs;
199+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->add_app_callbacks(&cbs));
200+
}
201+
202+
TEST_F(Test_LoRaWANInterface, set_device_class)
203+
{
204+
object->set_device_class(CLASS_A);
205+
}
206+
207+
TEST_F(Test_LoRaWANInterface, get_tx_metadata)
208+
{
209+
lorawan_tx_metadata data;
210+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_tx_metadata(data));
211+
}
212+
213+
TEST_F(Test_LoRaWANInterface, get_rx_metadata)
214+
{
215+
lorawan_rx_metadata data;
216+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_rx_metadata(data));
217+
}
218+
219+
TEST_F(Test_LoRaWANInterface, get_backoff_metadata)
220+
{
221+
int i;
222+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_backoff_metadata(i));
223+
}
224+
225+
TEST_F(Test_LoRaWANInterface, cancel_sending)
226+
{
227+
EXPECT_TRUE(LORAWAN_STATUS_OK == object->cancel_sending());
228+
}
229+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#[[
2+
* Copyright (c) 2018, Arm Limited and affiliates
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
]]
17+
18+
# Unit test suite name
19+
set(TEST_SUITE_NAME "lorawan_LoRaWANInterface")
20+
21+
# Source files
22+
set(unittest-sources
23+
../features/lorawan/LoRaWANInterface.cpp
24+
)
25+
26+
# Add test specific include paths
27+
set(unittest-includes ${unittest-includes}
28+
target_h
29+
../features/lorawan
30+
)
31+
32+
# Test & stub files
33+
set(unittest-test-sources
34+
../features/lorawan/lorawaninterface/Test_LoRaWANInterface.cpp
35+
stubs/LoRaPHY_stub.cpp
36+
stubs/LoRaWANStack_stub.cpp
37+
stubs/LoRaMac_stub.cpp
38+
stubs/mbed_assert_stub.c
39+
stubs/LoRaMacCrypto_stub.cpp
40+
stubs/LoRaMacChannelPlan_stub.cpp
41+
stubs/LoRaWANTimer_stub.cpp
42+
stubs/LoRaMacCommand_stub.cpp
43+
stubs/LoRaPHYEU868_stub.cpp
44+
)
45+
46+
# defines
47+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_PHY=\"EU868\"")
48+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_PHY=\"EU868\"")
49+
50+
51+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
/ _____) _ | |
3+
( (____ _____ ____ _| |_ _____ ____| |__
4+
\____ \| ___ | (_ _) ___ |/ ___) _ \
5+
_____) ) ____| | | || |_| ____( (___| | | |
6+
(______/|_____)_|_|_| \__)_____)\____)_| |_|
7+
(C)2013 Semtech
8+
___ _____ _ ___ _ _____ ___ ___ ___ ___
9+
/ __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
10+
\__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
11+
|___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
12+
embedded.connectivity.solutions===============
13+
14+
Description: LoRaWAN stack layer that controls both MAC and PHY underneath
15+
16+
License: Revised BSD License, see LICENSE.TXT file include in the project
17+
18+
Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE )
19+
20+
21+
Copyright (c) 2017, Arm Limited and affiliates.
22+
23+
SPDX-License-Identifier: BSD-3-Clause
24+
*/
25+
26+
#include "LoRaMacChannelPlan.h"
27+
28+
LoRaMacChannelPlan::LoRaMacChannelPlan() : _lora_phy(NULL)
29+
{
30+
}
31+
32+
LoRaMacChannelPlan::~LoRaMacChannelPlan()
33+
{
34+
}
35+
36+
void LoRaMacChannelPlan::activate_channelplan_subsystem(LoRaPHY *phy)
37+
{
38+
}
39+
40+
lorawan_status_t LoRaMacChannelPlan::set_plan(const lorawan_channelplan_t& plan)
41+
{
42+
return LORAWAN_STATUS_OK;
43+
}
44+
45+
lorawan_status_t LoRaMacChannelPlan::get_plan(lorawan_channelplan_t& plan,
46+
const channel_params_t* channel_list)
47+
{
48+
return LORAWAN_STATUS_OK;
49+
}
50+
51+
lorawan_status_t LoRaMacChannelPlan::remove_plan()
52+
{
53+
return LORAWAN_STATUS_OK;
54+
}
55+
56+
lorawan_status_t LoRaMacChannelPlan::remove_single_channel(uint8_t channel_id)
57+
{
58+
return LORAWAN_STATUS_OK;
59+
}
60+

0 commit comments

Comments
 (0)