Skip to content

Commit

Permalink
FHSS unit tests: Fixed tr51 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Oct 29, 2018
1 parent 4cf7fdf commit 4c74f96
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions source/Service_Libs/fhss/channel_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#ifndef CHANNEL_FUNC_H_
#define CHANNEL_FUNC_H_

/**
* @brief Function calculates nearest (higher) prime number for given start value.
* @param start_value Start value.
* @return Calculated prime number.
*/
uint16_t tr51_calc_nearest_prime_number(uint16_t start_value);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ bool test_tr51_get_uc_channel_index()
int i;
uint16_t number_of_channels = 129;
int32_t channel;
int16_t channel_table[number_of_channels];
int16_t channel_table[number_of_channels+10];
uint8_t output_table[number_of_channels];
int32_t test_table[number_of_channels];
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};

tr51_init_channel_table(channel_table, number_of_channels);
for (i=0; i<number_of_channels; i++) {
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, i, mac, number_of_channels, NULL);
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, output_table, i, mac, number_of_channels, NULL);
// Not sure yet which one is correct since there might be bug in spec
// if (channel != test_HopSequenceTable[i]) {
if (channel != test_HopSequenceTable2[i]) {
Expand All @@ -117,7 +118,7 @@ bool test_tr51_get_uc_channel_index()
uint32_t excluded_channels[8] = {0x40100401, 0x10040100, 0x04010040, 0, 0, 0, 0, 0};
uint16_t number_of_excluded_channels = 10;
for (i=0; i<number_of_channels-number_of_excluded_channels; i++) {
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, i, mac, number_of_channels, excluded_channels);
test_table[i] = channel = tr51_get_uc_channel_index(channel_table, output_table, i, mac, number_of_channels, excluded_channels);
// Shouldn't find channel from excluded channels
if (channel_on_the_list(excluded_channels, channel)) {
return false;
Expand All @@ -140,10 +141,11 @@ bool test_tr51_get_bc_channel_index()
int32_t channel;
uint16_t bsi = 100;
int32_t test_table[number_of_channels];
int16_t channel_table[number_of_channels];
int16_t channel_table[number_of_channels+10];
uint8_t output_table[number_of_channels];
tr51_init_channel_table(channel_table, number_of_channels);
for (int i=0; i<number_of_channels; i++) {
test_table[i] = channel = tr51_get_bc_channel_index(channel_table, i, bsi, number_of_channels, NULL);
test_table[i] = channel = tr51_get_bc_channel_index(channel_table, output_table, i, bsi, number_of_channels, NULL);
if (channel != test_HopSequenceTable3[i]) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ bool test_fhss_ws_enable()
return false;
}
// Test success
nsdynmemlib_stub.returnCounter = 2;
nsdynmemlib_stub.returnCounter = 3;
if (fhss_ws_enable(&fhss_api, &fhss_configuration, &fhss_timer) == NULL) {
return false;
}
free(fhss_common_stub.fhss_struct.ws->tr51_channel_table);
free(fhss_common_stub.fhss_struct.ws->tr51_output_table);
free(fhss_common_stub.fhss_struct.ws);
return true;
}
Expand Down
9 changes: 7 additions & 2 deletions test/nanostack/unittest/stub/channel_functions_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ int tr51_init_channel_table(int16_t *channel_table, int16_t number_of_channels)
return 0;
}

int32_t tr51_get_uc_channel_index(int16_t *channel_table, uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
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)
{
channel_functions_stub.uint8_value = slot_number;
return 3;
}

int32_t tr51_get_bc_channel_index(int16_t *channel_table, uint16_t slot_number, uint16_t bsi, int16_t number_of_channels)
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)
{
return 4;
}

uint16_t tr51_calc_nearest_prime_number(uint16_t start_value)
{
return 0;
}

0 comments on commit 4c74f96

Please sign in to comment.