Skip to content

Commit b70d23a

Browse files
Antti Kauppilaadbridge
authored andcommitted
Lorawan unittests
1 parent 0afe053 commit b70d23a

File tree

5 files changed

+655
-0
lines changed

5 files changed

+655
-0
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ set(unittest-includes-base
119119
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
120120
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
121121
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
122+
"${PROJECT_SOURCE_DIR}/../features/lorawan"
123+
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack"
124+
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/mac"
125+
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/phy"
126+
"${PROJECT_SOURCE_DIR}/../features/lorawan/system"
127+
"${PROJECT_SOURCE_DIR}/../features/mbedtls"
128+
"${PROJECT_SOURCE_DIR}/../features/mbedtls/inc"
122129
)
123130

124131
# Create a list for test suites.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 "LoRaMacChannelPlan.h"
20+
#include "LoRaPHY_stub.h"
21+
#include "LoRaPHY.h"
22+
23+
class my_LoRaPHY : public LoRaPHY
24+
{
25+
public:
26+
my_LoRaPHY(){};
27+
28+
virtual ~my_LoRaPHY(){};
29+
};
30+
31+
32+
class Test_LoRaMacChannelPlan : public testing::Test {
33+
protected:
34+
LoRaMacChannelPlan *object;
35+
my_LoRaPHY phy;
36+
37+
virtual void SetUp()
38+
{
39+
object = new LoRaMacChannelPlan();
40+
object->activate_channelplan_subsystem(&phy);
41+
42+
LoRaPHY_stub::uint8_value = 0;
43+
LoRaPHY_stub::bool_counter = 0;
44+
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
45+
LoRaPHY_stub::uint16_value = 0;
46+
memcpy(LoRaPHY_stub::bool_table, "0", 20);
47+
}
48+
49+
virtual void TearDown()
50+
{
51+
delete object;
52+
}
53+
};
54+
55+
TEST_F(Test_LoRaMacChannelPlan, constructor)
56+
{
57+
EXPECT_TRUE(object);
58+
}
59+
60+
TEST_F(Test_LoRaMacChannelPlan, set_plan)
61+
{
62+
lorawan_channelplan_t plan;
63+
LoRaPHY_stub::bool_counter = 0;
64+
LoRaPHY_stub::bool_table[0] = false;
65+
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_SERVICE_UNKNOWN);
66+
67+
plan.nb_channels = 1;
68+
LoRaPHY_stub::bool_counter = 0;
69+
LoRaPHY_stub::bool_table[0] = true;
70+
LoRaPHY_stub::uint8_value = 0;
71+
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
72+
73+
LoRaPHY_stub::bool_counter = 0;
74+
LoRaPHY_stub::bool_table[0] = true;
75+
LoRaPHY_stub::uint8_value = 10;
76+
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_PARAMETER_INVALID;
77+
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
78+
79+
LoRaPHY_stub::bool_counter = 0;
80+
LoRaPHY_stub::bool_table[0] = true;
81+
plan.nb_channels = 2;
82+
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
83+
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_OK);
84+
}
85+
86+
TEST_F(Test_LoRaMacChannelPlan, get_plan)
87+
{
88+
lorawan_channelplan_t plan;
89+
channel_params_t params;
90+
LoRaPHY_stub::bool_counter = 0;
91+
LoRaPHY_stub::bool_table[0] = false;
92+
EXPECT_TRUE(object->get_plan(plan, &params) == LORAWAN_STATUS_SERVICE_UNKNOWN);
93+
94+
LoRaPHY_stub::bool_counter = 0;
95+
LoRaPHY_stub::bool_table[0] = true;
96+
LoRaPHY_stub::bool_table[1] = false;
97+
98+
LoRaPHY_stub::uint8_value = 1;
99+
LoRaPHY_stub::uint16_value = 0xABCD;
100+
EXPECT_TRUE(object->get_plan(plan, &params) == LORAWAN_STATUS_OK);
101+
102+
LoRaPHY_stub::bool_counter = 0;
103+
LoRaPHY_stub::bool_table[0] = true;
104+
LoRaPHY_stub::bool_table[1] = true;
105+
LoRaPHY_stub::bool_table[2] = false;
106+
loramac_channel_t ch;
107+
plan.channels = &ch;
108+
EXPECT_TRUE(object->get_plan(plan, &params) == LORAWAN_STATUS_OK);
109+
}
110+
111+
TEST_F(Test_LoRaMacChannelPlan, remove_plan)
112+
{
113+
LoRaPHY_stub::bool_counter = 0;
114+
LoRaPHY_stub::bool_table[0] = false;
115+
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_SERVICE_UNKNOWN);
116+
117+
LoRaPHY_stub::uint8_value = 4;
118+
LoRaPHY_stub::bool_counter = 0;
119+
LoRaPHY_stub::bool_table[0] = true;
120+
LoRaPHY_stub::bool_table[1] = true; //first continue
121+
LoRaPHY_stub::bool_table[2] = false;
122+
LoRaPHY_stub::bool_table[3] = false;//second continue
123+
LoRaPHY_stub::bool_table[4] = false;
124+
LoRaPHY_stub::bool_table[5] = true;
125+
LoRaPHY_stub::bool_table[6] = false;//false for remove_single_channel(i)
126+
127+
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_SERVICE_UNKNOWN);
128+
129+
}
130+
131+
TEST_F(Test_LoRaMacChannelPlan, remove_single_channel)
132+
{
133+
LoRaPHY_stub::bool_counter = 0;
134+
LoRaPHY_stub::bool_table[0] = false;
135+
EXPECT_TRUE(object->remove_single_channel(4) == LORAWAN_STATUS_SERVICE_UNKNOWN);
136+
137+
LoRaPHY_stub::uint8_value = 2;
138+
LoRaPHY_stub::bool_counter = 0;
139+
LoRaPHY_stub::bool_table[0] = true;
140+
141+
EXPECT_TRUE(object->remove_single_channel(4) == LORAWAN_STATUS_PARAMETER_INVALID);
142+
143+
LoRaPHY_stub::bool_counter = 0;
144+
LoRaPHY_stub::bool_table[0] = true;
145+
LoRaPHY_stub::bool_table[1] = false;
146+
EXPECT_TRUE(object->remove_single_channel(1) == LORAWAN_STATUS_PARAMETER_INVALID);
147+
148+
LoRaPHY_stub::bool_counter = 0;
149+
LoRaPHY_stub::bool_table[0] = true;
150+
LoRaPHY_stub::bool_table[1] = true;
151+
EXPECT_TRUE(object->remove_single_channel(1) == LORAWAN_STATUS_OK);
152+
}
153+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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_LoRaMacChannelPlan")
20+
21+
# Source files
22+
set(unittest-sources
23+
../features/lorawan/lorastack/mac/LoRaMacChannelPlan.cpp
24+
)
25+
26+
# Add test specific include paths
27+
set(unittest-includes ${unittest-includes}
28+
target_h
29+
../features/lorawan/lorastack/mac
30+
)
31+
32+
# Test & stub files
33+
set(unittest-test-sources
34+
../features/lorawan/loramacchannelplan/Test_LoRaMacChannelPlan.cpp
35+
stubs/LoRaPHY_stub.cpp
36+
)
37+
38+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_TX_MAX_SIZE=255")
39+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_TX_MAX_SIZE=255")

0 commit comments

Comments
 (0)