Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit ed45fda

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Mac neighbor table unit test's.
Change-Id: If1de9f64133f361398249d72e519b2c29a3f5fd2
1 parent 0f85841 commit ed45fda

File tree

5 files changed

+326
-0
lines changed

5 files changed

+326
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = mac_neighbor_table_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/Service_Libs/mac_neighbor_table/mac_neighbor_table.c \
8+
9+
TEST_SRC_FILES = \
10+
main.cpp \
11+
mac_neighbor_table_test.cpp \
12+
test_mac_neighbor_table.c \
13+
../../stub/nsdynmemLIB_stub.c \
14+
../../stub/mbed_trace_stub.c \
15+
../../stub/protocol_core_stub.c \
16+
../../stub/ns_list_stub.c \
17+
../../stub/common_functions_stub.c \
18+
19+
include ../../MakefileWorker.mk
20+
21+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
22+
23+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 "CppUTest/TestHarness.h"
18+
#include "test_mac_neighbor_table.h"
19+
20+
21+
TEST_GROUP(mac_neighbor_table)
22+
{
23+
void setup()
24+
{
25+
26+
}
27+
28+
void teardown()
29+
{
30+
}
31+
};
32+
33+
TEST(mac_neighbor_table, test_mac_neighbor_table_create)
34+
{
35+
CHECK(test_mac_neighbor_table_create());
36+
}
37+
38+
TEST(mac_neighbor_table, test_mac_neighbor_table_use)
39+
{
40+
CHECK(test_mac_neighbor_table_use());
41+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 "CppUTest/CommandLineTestRunner.h"
18+
#include "CppUTest/TestPlugin.h"
19+
#include "CppUTest/TestRegistry.h"
20+
#include "CppUTestExt/MockSupportPlugin.h"
21+
int main(int ac, char** av)
22+
{
23+
return CommandLineTestRunner::RunAllTests(ac, av);
24+
}
25+
26+
IMPORT_TEST_GROUP(mac_neighbor_table);
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
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 "nsconfig.h"
19+
#include "string.h"
20+
#include "ns_types.h"
21+
#include "ns_trace.h"
22+
#include "common_functions.h"
23+
#include "nsdynmemLIB.h"
24+
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
25+
#include "nsdynmemLIB_stub.h"
26+
#include "common_functions_stub.h"
27+
#include "test_mac_neighbor_table.h"
28+
29+
/**
30+
* Remove entry notify
31+
*
32+
* \param entry_ptr Pointer to removed entry
33+
* \param user_data pointer for user to detect interface
34+
*/
35+
static void test_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
36+
{
37+
38+
}
39+
40+
static bool test_bool = true;
41+
/**
42+
* NUD entry notify
43+
*
44+
* \param entry_ptr Pointer to neighbor entry
45+
* \param user_data pointer for user to detect interface
46+
*
47+
* \return true NUD message generated
48+
* \return false When NUD is not generated
49+
*/
50+
static bool test_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
51+
{
52+
return test_bool;
53+
}
54+
55+
56+
bool test_mac_neighbor_table_create()
57+
{
58+
nsdynmemlib_stub.returnCounter = 0;
59+
mac_neighbor_table_t *entry = mac_neighbor_table_create(10, test_neighbor_entry_remove_notify, test_neighbor_entry_nud_notify, NULL, 200);
60+
61+
if (entry) {
62+
return false;
63+
}
64+
nsdynmemlib_stub.returnCounter = 1;
65+
entry = mac_neighbor_table_create(10, test_neighbor_entry_remove_notify, test_neighbor_entry_nud_notify, NULL, 200);
66+
67+
if (!entry) {
68+
return false;
69+
}
70+
71+
mac_neighbor_table_delete(entry);
72+
return true;
73+
}
74+
75+
bool test_mac_neighbor_table_use()
76+
{
77+
nsdynmemlib_stub.returnCounter = 1;
78+
mac_neighbor_table_t *entry = mac_neighbor_table_create(10, test_neighbor_entry_remove_notify, test_neighbor_entry_nud_notify, NULL, 200);
79+
80+
if (!entry) {
81+
return false;
82+
}
83+
uint8_t mac1[8];
84+
uint8_t mac2[8];
85+
uint8_t mac3[8];
86+
uint8_t mac4[8];
87+
memset(mac1, 0, 8);
88+
memset(mac2, 1, 8);
89+
memset(mac3, 2, 8);
90+
memset(mac4, 5, 8);
91+
92+
mac_neighbor_table_entry_t * mac_entry1 = mac_neighbor_table_entry_allocate(entry, mac1);
93+
if (!mac_entry1 || mac_entry1->index != 0) {
94+
return false;
95+
}
96+
97+
mac_neighbor_table_entry_t * mac_entry2 = mac_neighbor_table_entry_allocate(entry, mac2);
98+
if (!mac_entry2 || mac_entry2->index != 1) {
99+
return false;
100+
}
101+
102+
mac_neighbor_table_entry_t *mac_entry3 = mac_neighbor_table_entry_allocate(entry, mac3);
103+
104+
if (!mac_entry3 || mac_entry3->index != 2) {
105+
return false;
106+
}
107+
108+
for (unsigned char i=0; i< 7; i++) {
109+
mac_neighbor_table_entry_t *test = mac_neighbor_table_entry_allocate(entry, mac4);
110+
if (!test || test->index != 3+i) {
111+
return false;
112+
}
113+
mac4[0] += 1;
114+
}
115+
116+
mac_neighbor_table_entry_t *test2 = mac_neighbor_table_entry_allocate(entry, mac4);
117+
if (test2) {
118+
return false;
119+
}
120+
121+
122+
mac_neighbor_table_neighbor_timeout_update(entry, 10);
123+
124+
if (mac_entry3->lifetime != 230 || mac_entry2->lifetime != 230 || mac_entry1->lifetime != 230) {
125+
return false;
126+
}
127+
128+
mac_neighbor_table_neighbor_connected(entry, mac_entry3);
129+
130+
if (!mac_entry3->connected_device) {
131+
return false;
132+
}
133+
134+
mac_neighbor_table_trusted_neighbor(entry, mac_entry3, true);
135+
136+
if (!mac_entry3->trusted_device) {
137+
return false;
138+
}
139+
140+
mac_neighbor_table_neighbor_timeout_update(entry, 31);
141+
142+
if (mac_entry3->lifetime != 199 || mac_entry2->lifetime != 199 || mac_entry1->lifetime != 199) {
143+
return false;
144+
}
145+
146+
mac_neighbor_table_neighbor_timeout_update(entry, 170);
147+
148+
if (mac_entry3->lifetime != 29 || mac_entry2->lifetime != 29 || mac_entry1->lifetime != 29) {
149+
return false;
150+
}
151+
152+
if (!mac_entry3->nud_active || !mac_entry2->nud_active || !mac_entry1->nud_active) {
153+
return false;
154+
}
155+
156+
mac_neighbor_table_neighbor_timeout_update(entry, 1);
157+
158+
mac_neighbor_table_neighbor_refresh(entry, mac_entry2, 79);
159+
mac_neighbor_table_neighbor_refresh(entry, mac_entry1, 600);
160+
161+
mac_neighbor_table_neighbor_timeout_update(entry, 40);
162+
163+
if (!mac_entry2->nud_active) {
164+
return false;
165+
}
166+
167+
if (mac_neighbor_table_attribute_discover(entry, mac_entry3->index)) {
168+
return false;
169+
}
170+
171+
if (!mac_neighbor_table_attribute_discover(entry, mac_entry2->index)) {
172+
return false;
173+
}
174+
175+
176+
177+
if (!mac_neighbor_table_address_discover(entry, mac_entry1, 3) ) {
178+
return false;
179+
}
180+
181+
if (mac_neighbor_table_address_discover(entry, mac_entry1, 2) ) {
182+
return false;
183+
}
184+
mac_entry2->mac16 = 1;
185+
common_functions_stub.uint16_value = 1;
186+
187+
if (!mac_neighbor_table_address_discover(entry, mac_entry1, 2) ) {
188+
return false;
189+
}
190+
191+
if (mac_neighbor_table_address_discover(entry, mac_entry1, 4) ) {
192+
return false;
193+
}
194+
195+
mac_neighbor_table_neighbor_remove(entry, mac_entry2);
196+
197+
mac_neighbor_table_neighbor_remove(entry, mac_entry3);
198+
199+
mac_neighbor_table_neighbor_list_clean(entry);
200+
mac_neighbor_table_delete(entry);
201+
return true;
202+
}
203+
204+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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_MAC_NEIGHBOR_TABLE_H_
19+
#define TEST_MAC_NEIGHBOR_TABLE_H_
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
#include <stdbool.h>
25+
bool test_mac_neighbor_table_create();
26+
bool test_mac_neighbor_table_use();
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
#endif /* TEST_MAC_NEIGHBOR_TABLE_H_ */

0 commit comments

Comments
 (0)