Skip to content

Commit 3c9356a

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Updated channel function tests
1 parent 3a562d3 commit 3c9356a

File tree

3 files changed

+40
-160
lines changed

3 files changed

+40
-160
lines changed

test/nanostack/unittest/service_libs/channel_functions/channelfunctest.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ TEST_GROUP(channel_functions)
2929
}
3030
};
3131

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-
}
51-
5232
TEST(channel_functions, test_dh1cf_get_uc_channel_index)
5333
{
5434
CHECK(test_dh1cf_get_uc_channel_index());
@@ -59,12 +39,12 @@ TEST(channel_functions, test_dh1cf_get_bc_channel_index)
5939
CHECK(test_dh1cf_get_bc_channel_index());
6040
}
6141

62-
TEST(channel_functions, test_tr51_calc_nearest_prime_number)
42+
TEST(channel_functions, test_tr51_get_uc_channel_index)
6343
{
64-
CHECK(test_tr51_calc_nearest_prime_number());
44+
CHECK(test_tr51_get_uc_channel_index());
6545
}
6646

67-
TEST(channel_functions, test_tr51_get_uc_channel_index)
47+
TEST(channel_functions, test_tr51_get_bc_channel_index)
6848
{
69-
CHECK(test_tr51_get_uc_channel_index());
49+
CHECK(test_tr51_get_bc_channel_index());
7050
}

test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c

Lines changed: 35 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@
1818
#include "Service_Libs/fhss/channel_functions.h"
1919
#include "test_channel_functions.h"
2020

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-
3921
const int32_t test_HopSequenceTable[129] = { 4,93,31,84,55,3,116,123,
4022
41,68,105,28,25,71,33,66,
4123
122,20,112,125,118,11,69,89,
@@ -71,102 +53,44 @@ const int32_t test_HopSequenceTable2[129] = { 4, 42, 85, 0, 32, 116, 19, 17,
7153
18, 59, 35, 100, 118, 54, 80, 26,
7254
22 };
7355

74-
const uint16_t prime_number_table[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
75-
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
76-
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
77-
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
78-
179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
79-
233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
80-
283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
81-
353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
82-
419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
83-
467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
84-
547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
85-
607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
86-
661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
87-
739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
88-
811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
89-
877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
90-
947, 953, 967, 971, 977, 983, 991, 997, 1009 };
56+
const int32_t test_HopSequenceTable3[129] = { 124, 114, 65, 104, 33, 20, 118, 89,
57+
4, 84, 116, 68, 25, 79, 48, 14,
58+
23, 50, 27, 38, 110, 82, 101, 103,
59+
58, 90, 34, 73, 83, 1, 2, 59,
60+
12, 80, 8, 85, 36, 17, 98, 95,
61+
45, 106, 6, 56, 30, 87, 47, 57,
62+
66, 112, 11, 128, 93, 55, 123, 105,
63+
29, 67, 100, 21, 22, 115, 32, 111,
64+
44, 108, 75, 126, 39, 120, 127, 72,
65+
5, 86, 70, 7, 40, 74, 15, 109,
66+
60, 62, 18, 99, 54, 16, 42, 64,
67+
19, 53, 71, 122, 125, 69, 78, 31,
68+
3, 41, 28, 43, 77, 51, 94, 52,
69+
121, 88, 49, 97, 9, 35, 24, 26,
70+
63, 0, 107, 119, 113, 37, 96, 92,
71+
102, 10, 91, 76, 117, 61, 81, 13,
72+
46 };
9173

92-
bool test_tr51_get_rand()
93-
{
94-
tr51_seed_rand(1);
95-
// Test first few random values
96-
if (1103527590 != tr51_get_rand()) {
97-
return false;
98-
}
99-
if (377401575 != tr51_get_rand()) {
100-
return false;
101-
}
102-
if (662824084 != tr51_get_rand()) {
103-
return false;
104-
}
105-
if (1147902781 != tr51_get_rand()) {
106-
return false;
107-
}
108-
if (2035015474 != tr51_get_rand()) {
109-
return false;
110-
}
111-
return true;
112-
}
113-
114-
bool test_tr51_calculate_channel_table()
74+
bool test_tr51_get_uc_channel_index()
11575
{
116-
int32_t chantable[131];
117-
// Test generating channel table
118-
tr51_calculate_channel_table(129, 131, chantable);
119-
if (memcmp(chantable, test_channel_table, 131*4)) {
120-
return false;
121-
}
122-
123-
// Test that every channel exists once and only once.
124-
int k=0;
125-
for (int i=0; i<129; i++) {
126-
for (int j=0; j<131; j++) {
127-
if (chantable[j] == i) {
128-
k++;
129-
}
130-
}
131-
if (k != 1) {
76+
int i;
77+
uint16_t number_of_channels = 129;
78+
int32_t channel;
79+
int32_t test_table[number_of_channels];
80+
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
81+
for (i=0; i<number_of_channels; i++) {
82+
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, NULL, 0);
83+
// Not sure yet which one is correct since there might be bug in spec
84+
// if (channel != test_HopSequenceTable[i]) {
85+
if (channel != test_HopSequenceTable2[i]) {
13286
return false;
13387
}
134-
k=0;
135-
}
136-
return true;
137-
}
138-
139-
bool test_tr51_compute_cfd()
140-
{
141-
uint8_t first_element;
142-
uint8_t step_size;
143-
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
144-
// Test generating first element and step size
145-
tr51_compute_cfd(mac, &first_element, &step_size , 131);
146-
if (122 != first_element) {
147-
return false;
148-
}
149-
if (119 != step_size) {
150-
return false;
151-
}
152-
return true;
153-
}
154-
155-
bool test_tr51_calculate_hopping_sequence()
156-
{
157-
int32_t chantable[131];
158-
int32_t outtable[129];
159-
tr51_calculate_channel_table(129, 131, chantable);
160-
// Test generating hopping sequence table of specific peer
161-
tr51_calculate_hopping_sequence(chantable, 131, 122, 119, outtable, NULL, 0);
162-
if (memcmp(outtable, test_HopSequenceTable2, 129*4)) {
163-
return false;
16488
}
16589
// Test that every channel exists once and only once.
16690
int k=0;
167-
for (int i=0; i<129; i++) {
168-
for (int j=0; j<129; j++) {
169-
if (outtable[j] == i) {
91+
for (int h=0; h<number_of_channels; h++) {
92+
for (int j=0; j<number_of_channels; j++) {
93+
if (test_table[j] == h) {
17094
k++;
17195
}
17296
}
@@ -179,17 +103,15 @@ bool test_tr51_calculate_hopping_sequence()
179103
return true;
180104
}
181105

182-
bool test_tr51_get_uc_channel_index()
106+
bool test_tr51_get_bc_channel_index()
183107
{
184108
uint16_t number_of_channels = 129;
185109
int32_t channel;
110+
uint16_t bsi = 100;
186111
int32_t test_table[number_of_channels];
187-
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
188112
for (int i=0; i<number_of_channels; i++) {
189-
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels);
190-
// Not sure yet which one is correct since there might be bug in spec
191-
// if (channel != test_HopSequenceTable[i]) {
192-
if (channel != test_HopSequenceTable2[i]) {
113+
test_table[i] = channel = tr51_get_bc_channel_index(i, bsi, number_of_channels, NULL, 0);
114+
if (channel != test_HopSequenceTable3[i]) {
193115
return false;
194116
}
195117
}
@@ -258,21 +180,3 @@ bool test_dh1cf_get_bc_channel_index()
258180
}
259181
return true;
260182
}
261-
262-
bool test_tr51_calc_nearest_prime_number()
263-
{
264-
uint16_t prime_number;
265-
int j;
266-
for (int i=2; i<1000; i++) {
267-
prime_number = tr51_calc_nearest_prime_number(i);
268-
for (j=0; j<sizeof(prime_number_table); j++) {
269-
if (prime_number == prime_number_table[j]) {
270-
break;
271-
}
272-
}
273-
if (j >= sizeof(prime_number_table)) {
274-
return false;
275-
}
276-
}
277-
return true;
278-
}

test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ extern "C" {
2323

2424
#include <stdbool.h>
2525

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();
3026
bool test_dh1cf_get_uc_channel_index();
3127
bool test_dh1cf_get_bc_channel_index();
32-
bool test_tr51_calc_nearest_prime_number();
3328
bool test_tr51_get_uc_channel_index();
29+
bool test_tr51_get_bc_channel_index();
3430

3531
#ifdef __cplusplus
3632
}

0 commit comments

Comments
 (0)