Skip to content

Commit 00af7f1

Browse files
author
Jarkko Paso
committed
Unit tests: Created channel function unit tests
1 parent 44a85e5 commit 00af7f1

File tree

5 files changed

+277
-0
lines changed

5 files changed

+277
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = channel_functions_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/Service_Libs/fhss/channel_functions.c \
8+
9+
10+
TEST_SRC_FILES = \
11+
main.cpp \
12+
channelfunctest.cpp \
13+
test_channel_functions.c \
14+
15+
include ../../MakefileWorker.mk
16+
17+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
18+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
#include "CppUTest/TestHarness.h"
18+
#include "test_channel_functions.h"
19+
20+
21+
TEST_GROUP(channel_functions)
22+
{
23+
void setup()
24+
{
25+
}
26+
27+
void teardown()
28+
{
29+
}
30+
};
31+
32+
TEST(channel_functions, test_tr51_get_rand)
33+
{
34+
CHECK(test_tr51_get_rand());
35+
}
36+
37+
TEST(channel_functions, test_tr51_calculate_channel_table)
38+
{
39+
CHECK(test_tr51_calculate_channel_table());
40+
}
41+
42+
TEST(channel_functions, test_tr51_compute_cfd)
43+
{
44+
CHECK(test_tr51_compute_cfd());
45+
}
46+
47+
TEST(channel_functions, test_tr51_calculate_hopping_sequence)
48+
{
49+
CHECK(test_tr51_calculate_hopping_sequence());
50+
}
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(channel_functions);
28+
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright (c) 2016-2017, 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 "Service_Libs/fhss/channel_functions.h"
19+
#include "test_channel_functions.h"
20+
21+
const int32_t test_channel_table[131] = { 57,78,25,22,97,90,86,102,
22+
98,16,104,128,28,23,44,26,
23+
1,74,117,6,53,89,105,94,
24+
110,39,119,80,62,46,47,69,
25+
68,21,49,58,5,92,17,54,
26+
65,11,41,14,111,24,83,40,
27+
76,106,19,118,123,51,38,126,
28+
107,12,60,13,87,125,116,100,
29+
88,103,72,96,36,99,114,112,
30+
3,48,32,35,73,7,91,45,
31+
64,20,55,77,27,75,0,59,
32+
109,81,30,122,84,67,121,101,
33+
127,37,85,18,124,66,31,79,
34+
115,9,34,70,10,95,42,33,
35+
93,43,50,108,63,2,15,61,
36+
56,71,4,29,52,82,120,113,
37+
8,-1,-1 };
38+
39+
const int32_t test_HopSequenceTable [129] = { 4,93,31,84,55,3,116,123,
40+
41,68,105,28,25,71,33,66,
41+
122,20,112,125,118,11,69,89,
42+
128,78,56,42,124,30,64,114,
43+
87,19,65,47,53,104,57,61,
44+
95,18,81,45,99,13,106,54,
45+
46,6,16,8,15,10,85,109,
46+
91,36,60,76,17,62,117,98,
47+
113,2,70,37,59,7,96,12,
48+
40,92,80,74,102,120,63,34,
49+
127,0,73,72,107,83,5,119,
50+
1,86,82,108,9,101,75,35,
51+
103,126,24,58,39,26,90,52,
52+
50,115,121,27,32,88,38,111,
53+
49,110,44,97,29,43,79,67,
54+
77,48,100,51,14,21,94,23,
55+
22 };
56+
57+
bool test_tr51_get_rand()
58+
{
59+
tr51_seed_rand(1);
60+
// Test first few random values
61+
if (1103527590 != tr51_get_rand()) {
62+
return false;
63+
}
64+
if (377401575 != tr51_get_rand()) {
65+
return false;
66+
}
67+
if (662824084 != tr51_get_rand()) {
68+
return false;
69+
}
70+
if (1147902781 != tr51_get_rand()) {
71+
return false;
72+
}
73+
if (2035015474 != tr51_get_rand()) {
74+
return false;
75+
}
76+
return true;
77+
}
78+
79+
bool test_tr51_calculate_channel_table()
80+
{
81+
int32_t chantable[131];
82+
// Test generating channel table
83+
tr51_calculate_channel_table(129, 131, chantable);
84+
if (memcmp(chantable, test_channel_table, 131*4)) {
85+
return false;
86+
}
87+
88+
// Test that every channel exists once and only once.
89+
int k=0;
90+
for (int i=0; i<129; i++) {
91+
for (int j=0; j<131; j++) {
92+
if (chantable[j] == i) {
93+
k++;
94+
}
95+
}
96+
if (k != 1) {
97+
return false;
98+
}
99+
k=0;
100+
}
101+
return true;
102+
}
103+
104+
bool test_tr51_compute_cfd()
105+
{
106+
uint8_t first_element;
107+
uint8_t step_size;
108+
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
109+
// Test generating first element and step size
110+
tr51_compute_cfd(mac, &first_element, &step_size , 131);
111+
if (122 != first_element) {
112+
return false;
113+
}
114+
if (119 != step_size) {
115+
return false;
116+
}
117+
return true;
118+
}
119+
120+
bool test_tr51_calculate_hopping_sequence()
121+
{
122+
int32_t chantable[131];
123+
int32_t outtable[129];
124+
tr51_calculate_channel_table(129, 131, chantable);
125+
// Test generating hopping sequence table of specific peer
126+
tr51_calculate_hopping_sequence(chantable, 129, 122, 119, outtable, NULL, 0);
127+
if (memcmp(outtable, test_HopSequenceTable, 129*4)) {
128+
return false;
129+
}
130+
// Test that every channel exists once and only once.
131+
int k=0;
132+
for (int i=0; i<129; i++) {
133+
for (int j=0; j<129; j++) {
134+
if (outtable[j] == i) {
135+
k++;
136+
}
137+
}
138+
if (k != 1) {
139+
return false;
140+
}
141+
k=0;
142+
}
143+
144+
return true;
145+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#ifndef TEST_CHANNEL_FUNC_H
18+
#define TEST_CHANNEL_FUNC_H
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
#include <stdbool.h>
25+
26+
bool test_tr51_get_rand();
27+
bool test_tr51_calculate_channel_table();
28+
bool test_tr51_compute_cfd();
29+
bool test_tr51_calculate_hopping_sequence();
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif // TEST_CHANNEL_FUNC_H
36+

0 commit comments

Comments
 (0)