Skip to content

Commit 4c74f96

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Fixed tr51 tests
1 parent 4cf7fdf commit 4c74f96

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

source/Service_Libs/fhss/channel_functions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#ifndef CHANNEL_FUNC_H_
1818
#define CHANNEL_FUNC_H_
1919

20+
/**
21+
* @brief Function calculates nearest (higher) prime number for given start value.
22+
* @param start_value Start value.
23+
* @return Calculated prime number.
24+
*/
2025
uint16_t tr51_calc_nearest_prime_number(uint16_t start_value);
2126

2227
/**

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ bool test_tr51_get_uc_channel_index()
8686
int i;
8787
uint16_t number_of_channels = 129;
8888
int32_t channel;
89-
int16_t channel_table[number_of_channels];
89+
int16_t channel_table[number_of_channels+10];
90+
uint8_t output_table[number_of_channels];
9091
int32_t test_table[number_of_channels];
9192
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
9293

9394
tr51_init_channel_table(channel_table, number_of_channels);
9495
for (i=0; i<number_of_channels; i++) {
95-
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, i, mac, number_of_channels, NULL);
96+
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, output_table, i, mac, number_of_channels, NULL);
9697
// Not sure yet which one is correct since there might be bug in spec
9798
// if (channel != test_HopSequenceTable[i]) {
9899
if (channel != test_HopSequenceTable2[i]) {
@@ -117,7 +118,7 @@ bool test_tr51_get_uc_channel_index()
117118
uint32_t excluded_channels[8] = {0x40100401, 0x10040100, 0x04010040, 0, 0, 0, 0, 0};
118119
uint16_t number_of_excluded_channels = 10;
119120
for (i=0; i<number_of_channels-number_of_excluded_channels; i++) {
120-
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, i, mac, number_of_channels, excluded_channels);
121+
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, output_table, i, mac, number_of_channels, excluded_channels);
121122
// Shouldn't find channel from excluded channels
122123
if (channel_on_the_list(excluded_channels, channel)) {
123124
return false;
@@ -140,10 +141,11 @@ bool test_tr51_get_bc_channel_index()
140141
int32_t channel;
141142
uint16_t bsi = 100;
142143
int32_t test_table[number_of_channels];
143-
int16_t channel_table[number_of_channels];
144+
int16_t channel_table[number_of_channels+10];
145+
uint8_t output_table[number_of_channels];
144146
tr51_init_channel_table(channel_table, number_of_channels);
145147
for (int i=0; i<number_of_channels; i++) {
146-
test_table[i] = channel = tr51_get_bc_channel_index(channel_table, i, bsi, number_of_channels, NULL);
148+
test_table[i] = channel = tr51_get_bc_channel_index(channel_table, output_table, i, bsi, number_of_channels, NULL);
147149
if (channel != test_HopSequenceTable3[i]) {
148150
return false;
149151
}

test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ bool test_fhss_ws_enable()
179179
return false;
180180
}
181181
// Test success
182-
nsdynmemlib_stub.returnCounter = 2;
182+
nsdynmemlib_stub.returnCounter = 3;
183183
if (fhss_ws_enable(&fhss_api, &fhss_configuration, &fhss_timer) == NULL) {
184184
return false;
185185
}
186186
free(fhss_common_stub.fhss_struct.ws->tr51_channel_table);
187+
free(fhss_common_stub.fhss_struct.ws->tr51_output_table);
187188
free(fhss_common_stub.fhss_struct.ws);
188189
return true;
189190
}

test/nanostack/unittest/stub/channel_functions_stub.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ int tr51_init_channel_table(int16_t *channel_table, int16_t number_of_channels)
3535
return 0;
3636
}
3737

38-
int32_t tr51_get_uc_channel_index(int16_t *channel_table, uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
38+
int32_t tr51_get_uc_channel_index(int16_t *channel_table, uint8_t *output_table, uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
3939
{
4040
channel_functions_stub.uint8_value = slot_number;
4141
return 3;
4242
}
4343

44-
int32_t tr51_get_bc_channel_index(int16_t *channel_table, uint16_t slot_number, uint16_t bsi, int16_t number_of_channels)
44+
int32_t tr51_get_bc_channel_index(int16_t *channel_table, uint8_t *output_table, uint16_t slot_number, uint16_t bsi, int16_t number_of_channels)
4545
{
4646
return 4;
4747
}
48+
49+
uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
50+
{
51+
return 0;
52+
}

0 commit comments

Comments
 (0)