Skip to content

Commit 6b6e509

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
MPX header module unit test.
1 parent 55309e8 commit 6b6e509

File tree

7 files changed

+458
-0
lines changed

7 files changed

+458
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = ws_mpx_header_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/6LoWPAN/ws/ws_mpx_header.c
8+
9+
TEST_SRC_FILES = \
10+
main.cpp \
11+
ws_mpx_headertest.cpp \
12+
test_ws_mpx_header.c \
13+
../../stub/common_functions_stub.c \
14+
../../stub/nsdynmemLIB_stub.c \
15+
../../stub/mbed_trace_stub.c \
16+
../../stub/platform_stub.c \
17+
../../stub/address_stub.c \
18+
../../stub/etx_stub.c \
19+
../../stub/protocol_stats_stub.c \
20+
../../stub/randLIB_stub.c \
21+
../../stub/mesh_stub.c \
22+
../../stub/nsdynmemLIB_stub.c \
23+
../../stub/mbed_trace_stub.c \
24+
../../stub/buffer_dyn_stub.c \
25+
../../stub/protocol_core_stub.c \
26+
../../stub/socket_stub.c \
27+
../../stub/iphc_decompress_stub.c \
28+
29+
30+
include ../../MakefileWorker.mk
31+
32+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
33+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2016, 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_mpx_header);
28+
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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 "common_functions.h"
24+
#include "mac_common_defines.h"
25+
#include "6LoWPAN/ws/ws_mpx_header.h"
26+
#include "common_functions_stub.h"
27+
28+
bool test_ws_llc_mpx_header_frame_parse()
29+
{
30+
mpx_msg_t mpx_msg;
31+
uint8_t temp_buffer[10];
32+
33+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 0, &mpx_msg) ) {
34+
return false;
35+
}
36+
37+
temp_buffer[0] = MPX_FT_FULL_FRAME;
38+
temp_buffer[0] |= (15 << 3);
39+
40+
common_functions_stub.readuint16_from_queue = 0;
41+
common_functions_stub.uint16_value = 4;
42+
43+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 2, &mpx_msg) ) {
44+
return false;
45+
}
46+
47+
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) {
48+
return false;
49+
}
50+
51+
if (mpx_msg.frame_length != 2 || mpx_msg.frame_ptr != &temp_buffer[3] || mpx_msg.transfer_type != MPX_FT_FULL_FRAME || mpx_msg.transaction_id != 15 || mpx_msg.multiplex_id != 4) {
52+
return false;
53+
}
54+
55+
temp_buffer[0] = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID;
56+
temp_buffer[0] |= (16 << 3);
57+
58+
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) {
59+
return false;
60+
}
61+
62+
if (mpx_msg.frame_length != 4 || mpx_msg.frame_ptr != &temp_buffer[1] || mpx_msg.transfer_type != MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID || mpx_msg.transaction_id != 16) {
63+
return false;
64+
}
65+
66+
temp_buffer[0] = MPX_FT_FIRST_OR_SUB_FRAGMENT;
67+
temp_buffer[0] |= (17 << 3);
68+
temp_buffer[1] = 0;
69+
70+
common_functions_stub.readuint16_from_queue = 2;
71+
//common_functions_stub.uint16_value = 100;
72+
common_functions_stub.uint16_value_queue[1] = 40;
73+
common_functions_stub.uint16_value_queue[0] = 20;
74+
75+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 2, &mpx_msg) ) {
76+
return false;
77+
}
78+
common_functions_stub.readuint16_from_queue = 2;
79+
common_functions_stub.uint16_value_queue[1] = 40;
80+
common_functions_stub.uint16_value_queue[0] = 20;
81+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) {
82+
return false;
83+
}
84+
common_functions_stub.readuint16_from_queue = 2;
85+
common_functions_stub.uint16_value_queue[1] = 40;
86+
common_functions_stub.uint16_value_queue[0] = 20;
87+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) {
88+
return false;
89+
}
90+
common_functions_stub.readuint16_from_queue = 2;
91+
common_functions_stub.uint16_value_queue[1] = 40;
92+
common_functions_stub.uint16_value_queue[0] = 20;
93+
94+
95+
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) {
96+
return false;
97+
}
98+
99+
if (mpx_msg.frame_length != 4 || mpx_msg.frame_ptr != &temp_buffer[6] || mpx_msg.transfer_type != MPX_FT_FIRST_OR_SUB_FRAGMENT
100+
|| mpx_msg.transaction_id != 17 || mpx_msg.multiplex_id != 20 || mpx_msg.total_upper_layer_size != 40) {
101+
return false;
102+
}
103+
104+
temp_buffer[0] = MPX_FT_FIRST_OR_SUB_FRAGMENT;
105+
temp_buffer[0] |= (18 << 3);
106+
temp_buffer[1] = 1;
107+
108+
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) {
109+
return false;
110+
}
111+
112+
if (mpx_msg.frame_length != 8 || mpx_msg.frame_ptr != &temp_buffer[2] || mpx_msg.transfer_type != MPX_FT_FIRST_OR_SUB_FRAGMENT
113+
|| mpx_msg.transaction_id != 18 ) {
114+
return false;
115+
}
116+
temp_buffer[0] = MPX_FT_ABORT;
117+
temp_buffer[0] |= (19 << 3);
118+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) {
119+
return false;
120+
}
121+
122+
123+
124+
common_functions_stub.readuint16_from_queue = 0;
125+
common_functions_stub.uint16_value = 400;
126+
127+
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) {
128+
return false;
129+
}
130+
131+
if (mpx_msg.frame_length || mpx_msg.transfer_type != MPX_FT_ABORT
132+
|| mpx_msg.transaction_id != 19 || mpx_msg.total_upper_layer_size != 400) {
133+
return false;
134+
}
135+
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 1, &mpx_msg) ) {
136+
return false;
137+
}
138+
139+
if (mpx_msg.frame_length || mpx_msg.transfer_type != MPX_FT_ABORT
140+
|| mpx_msg.transaction_id != 19 || mpx_msg.total_upper_layer_size) {
141+
return false;
142+
}
143+
144+
temp_buffer[0] = 7;
145+
temp_buffer[0] |= (19 << 3);
146+
if (ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) {
147+
return false;
148+
}
149+
150+
151+
return true;
152+
}
153+
154+
bool test_ws_llc_mpx_header_write()
155+
{
156+
mpx_msg_t mpx_msg;
157+
uint8_t temp_buffer[10];
158+
159+
mpx_msg.transfer_type = MPX_FT_FULL_FRAME;
160+
mpx_msg.transaction_id = 15;
161+
162+
uint8_t *ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
163+
if (ptr != &temp_buffer[3]) {
164+
return false;
165+
}
166+
167+
mpx_msg.transfer_type = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID;
168+
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
169+
if (ptr != &temp_buffer[1]) {
170+
return false;
171+
}
172+
173+
mpx_msg.transfer_type = MPX_FT_FIRST_OR_SUB_FRAGMENT;
174+
mpx_msg.fragment_number = 0;
175+
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
176+
if (ptr != &temp_buffer[6]) {
177+
return false;
178+
}
179+
180+
mpx_msg.transfer_type = MPX_FT_FIRST_OR_SUB_FRAGMENT;
181+
mpx_msg.fragment_number = 1;
182+
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
183+
if (ptr != &temp_buffer[2]) {
184+
return false;
185+
}
186+
187+
mpx_msg.transfer_type = MPX_FT_ABORT;
188+
mpx_msg.total_upper_layer_size = 0;
189+
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
190+
if (ptr != &temp_buffer[1]) {
191+
return false;
192+
}
193+
194+
mpx_msg.transfer_type = MPX_FT_ABORT;
195+
mpx_msg.total_upper_layer_size = 400;
196+
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
197+
if (ptr != &temp_buffer[3]) {
198+
return false;
199+
}
200+
201+
mpx_msg.transfer_type = 7;
202+
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
203+
if (ptr != &temp_buffer[1]) {
204+
return false;
205+
}
206+
207+
return true;
208+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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_MPX_HEADER_H_
19+
#define TEST_WS_MPX_HEADER_H_
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
#include <stdbool.h>
26+
27+
bool test_ws_llc_mpx_header_frame_parse();
28+
29+
bool test_ws_llc_mpx_header_write();
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif /* TEST_WS_MPX_HEADER_H_ */
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
/*
19+
* Copyright (c) 2016, Arm Limited and affiliates.
20+
* SPDX-License-Identifier: Apache-2.0
21+
*
22+
* Licensed under the Apache License, Version 2.0 (the "License");
23+
* you may not use this file except in compliance with the License.
24+
* You may obtain a copy of the License at
25+
*
26+
* http://www.apache.org/licenses/LICENSE-2.0
27+
*
28+
* Unless required by applicable law or agreed to in writing, software
29+
* distributed under the License is distributed on an "AS IS" BASIS,
30+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31+
* See the License for the specific language governing permissions and
32+
* limitations under the License.
33+
*/
34+
#include "CppUTest/TestHarness.h"
35+
#include "test_ws_mpx_header.h"
36+
37+
TEST_GROUP(ws_mpx_header)
38+
{
39+
void setup()
40+
{
41+
}
42+
43+
void teardown()
44+
{
45+
}
46+
};
47+
48+
TEST(ws_mpx_header, test_ws_llc_mpx_header_frame_parse)
49+
{
50+
CHECK(test_ws_llc_mpx_header_frame_parse());
51+
}
52+
53+
TEST(ws_mpx_header, test_ws_llc_mpx_header_write)
54+
{
55+
CHECK(test_ws_llc_mpx_header_write());
56+
}
57+
58+
59+
60+
61+

0 commit comments

Comments
 (0)