Skip to content

Commit 4686668

Browse files
author
Tero Heinonen
authored
ws_management_api unit tests (ARMmbed#1591)
Created unit tests for ws_management_api
1 parent 8147217 commit 4686668

File tree

8 files changed

+461
-0
lines changed

8 files changed

+461
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = ws_management_api_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/6LoWPAN/ws/ws_management_api.c
8+
9+
TEST_SRC_FILES = \
10+
main.cpp \
11+
ws_management_api_test.cpp \
12+
test_ws_management_api.c \
13+
../../stub/protocol_core_stub.c \
14+
../../stub/ws_common_stub.c \
15+
16+
include ../../MakefileWorker.mk
17+
18+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
19+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 "CppUTest/CommandLineTestRunner.h"
19+
#include "CppUTest/TestPlugin.h"
20+
#include "CppUTest/TestRegistry.h"
21+
#include "CppUTestExt/MockSupportPlugin.h"
22+
int main(int ac, char** av)
23+
{
24+
return CommandLineTestRunner::RunAllTests(ac, av);
25+
}
26+
27+
IMPORT_TEST_GROUP(ws_management_api);
28+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
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+
echo
18+
echo Build ws_management_api unit tests
19+
echo
20+
21+
# Remember to add new test folder to Makefile
22+
make clean
23+
make all
24+
25+
echo
26+
echo Create results
27+
echo
28+
rm -rf results
29+
mkdir results
30+
find ./ -name '*.xml' | xargs cp -t ./results/
31+
32+
echo
33+
echo Create coverage document
34+
echo
35+
rm -rf coverages
36+
mkdir coverages
37+
cd coverages
38+
39+
lcov -q -d ../. -c -o app.info
40+
lcov -q -r app.info "/test*" -o app.info
41+
lcov -q -r app.info "/usr*" -o app.info
42+
lcov -q -r app.info "/libService*" -o app.info
43+
lcov -q -r app.info "/yotta_modules*" -o app.info
44+
genhtml -q --no-branch-coverage app.info
45+
cd ..
46+
echo
47+
echo
48+
echo
49+
echo Have a nice bug hunt!
50+
echo
51+
echo
52+
echo
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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+
#include "nsconfig.h"
18+
#include <string.h>
19+
#include "ns_types.h"
20+
#include "ns_list.h"
21+
#include "ns_trace.h"
22+
#include "nsdynmemLIB.h"
23+
#include "NWK_INTERFACE/Include/protocol.h"
24+
#include "6LoWPAN/ws/ws_common.h"
25+
26+
/* Stubs */
27+
#include "protocol_core_stub.h"
28+
#include "ws_common_stub.h"
29+
30+
bool test_ws_management_node_init()
31+
{
32+
protocol_interface_info_entry_t entry;
33+
ws_info_t ws_info_entry;
34+
char nw_name[] = "NW-NAME";
35+
fhss_timer_t fhss_timer_entry;
36+
37+
memset(&entry, 0, sizeof(protocol_interface_info_entry_t));
38+
memset(&ws_info_entry, 0, sizeof(ws_info_t));
39+
memset(&fhss_timer_entry, 0, sizeof(fhss_timer_t));
40+
41+
/* No interface info entry found */
42+
if (-1 != ws_management_node_init(1, NULL, NULL)) {
43+
return false;
44+
}
45+
46+
protocol_core_stub.entry_ptr = &entry;
47+
48+
/* No ws_info found */
49+
if (-1 != ws_management_node_init(1, NULL, NULL)) {
50+
return false;
51+
}
52+
53+
entry.ws_info = &ws_info_entry;
54+
55+
/* NULL pointers as a parameters */
56+
if (-2 != ws_management_node_init(1, NULL, NULL)) {
57+
return false;
58+
}
59+
60+
/* NULL pointers as a FHSS info */
61+
if (-2 != ws_management_node_init(1, nw_name, NULL)) {
62+
return false;
63+
}
64+
65+
/* NULL pointers as a network name */
66+
if (-2 != ws_management_node_init(1, NULL, fhss_timer_entry)) {
67+
return false;
68+
}
69+
70+
/* OK case */
71+
if (0 != ws_management_node_init(1, nw_name, fhss_timer_entry)) {
72+
return false;
73+
}
74+
75+
return true;
76+
}
77+
78+
bool test_ws_management_regulatory_domain_set()
79+
{
80+
protocol_interface_info_entry_t entry;
81+
ws_info_t ws_info_entry;
82+
83+
memset(&entry, 0, sizeof(protocol_interface_info_entry_t));
84+
memset(&ws_info_entry, 0, sizeof(ws_info_t));
85+
86+
protocol_core_stub.entry_ptr = NULL;
87+
88+
/* No protocol info entry */
89+
if (-1 != ws_management_regulatory_domain_set(1,0,0,0)) {
90+
return false;
91+
}
92+
93+
protocol_core_stub.entry_ptr = &entry;
94+
95+
/* No ws_info found */
96+
if (-1 != ws_management_regulatory_domain_set(1,0,0,0)) {
97+
return false;
98+
}
99+
100+
entry.ws_info = &ws_info_entry;
101+
102+
ws_common_stub.int8_value = -1;
103+
104+
/* ws_common_regulatory_domain_config() fails */
105+
if (-1 != ws_management_regulatory_domain_set(1,0,0,0)) {
106+
return false;
107+
}
108+
109+
ws_common_stub.int8_value = 0;
110+
111+
/* OK case */
112+
if (0 != ws_management_regulatory_domain_set(1,0,0,0)) {
113+
return false;
114+
}
115+
116+
return true;
117+
}
118+
119+
bool test_ws_management_channel_mask_set()
120+
{
121+
protocol_interface_info_entry_t entry;
122+
ws_info_t ws_info_entry;
123+
uint32_t channel_mask[8] = {0};
124+
125+
memset(&entry, 0, sizeof(protocol_interface_info_entry_t));
126+
memset(&ws_info_entry, 0, sizeof(ws_info_t));
127+
128+
protocol_core_stub.entry_ptr = NULL;
129+
130+
/* No protocol info entry */
131+
if (-1 != ws_management_channel_mask_set(1, channel_mask)) {
132+
return false;
133+
}
134+
135+
protocol_core_stub.entry_ptr = &entry;
136+
137+
/* No ws_info found */
138+
if (-1 != ws_management_channel_mask_set(1, channel_mask)) {
139+
return false;
140+
}
141+
142+
entry.ws_info = &ws_info_entry;
143+
144+
/* OK case */
145+
if (0 != ws_management_channel_mask_set(1, channel_mask)) {
146+
return false;
147+
}
148+
return true;
149+
}
150+
151+
bool test_ws_management_channel_plan_set()
152+
{
153+
protocol_interface_info_entry_t entry;
154+
ws_info_t ws_info_entry;
155+
156+
memset(&entry, 0, sizeof(protocol_interface_info_entry_t));
157+
memset(&ws_info_entry, 0, sizeof(ws_info_t));
158+
159+
protocol_core_stub.entry_ptr = NULL;
160+
161+
/* No protocol info entry */
162+
if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0)) {
163+
return false;
164+
}
165+
166+
protocol_core_stub.entry_ptr = &entry;
167+
168+
/* No ws_info found */
169+
if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0)) {
170+
return false;
171+
}
172+
173+
entry.ws_info = &ws_info_entry;
174+
175+
/* OK case */
176+
if (0 != ws_management_channel_plan_set(1,0,0,0,0,0)) {
177+
return false;
178+
}
179+
180+
return true;
181+
}
182+
183+
bool test_ws_management_fhss_timing_configure()
184+
{
185+
protocol_interface_info_entry_t entry;
186+
ws_info_t ws_info_entry;
187+
188+
memset(&entry, 0, sizeof(protocol_interface_info_entry_t));
189+
memset(&ws_info_entry, 0, sizeof(ws_info_t));
190+
191+
protocol_core_stub.entry_ptr = NULL;
192+
193+
/* No protocol info entry */
194+
if (-1 != ws_management_fhss_timing_configure(1,0,0,0))
195+
{
196+
return false;
197+
}
198+
199+
protocol_core_stub.entry_ptr = &entry;
200+
201+
/* No ws_info found */
202+
if (-1 != ws_management_fhss_timing_configure(1,0,0,0))
203+
{
204+
return false;
205+
}
206+
207+
entry.ws_info = &ws_info_entry;
208+
209+
/* OK case */
210+
if (0 != ws_management_fhss_timing_configure(1,0,0,0))
211+
{
212+
return false;
213+
}
214+
215+
return true;
216+
}
217+
218+
219+
220+
221+
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+
#ifndef TEST_WS_IE_LIB_H_
19+
#define TEST_WS_IE_LIB_H_
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
#include <stdbool.h>
26+
27+
bool test_ws_management_node_init();
28+
bool test_ws_management_regulatory_domain_set();
29+
bool test_ws_management_channel_mask_set();
30+
bool test_ws_management_channel_plan_set();
31+
bool test_ws_management_fhss_timing_configure();
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
38+
39+
#endif /* TEST_WS_IE_LIB_H_ */

0 commit comments

Comments
 (0)