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

Commit f2d7558

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Fixed tests
1 parent 149f17b commit f2d7558

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

test/nanostack/unittest/service_libs/fhss/test_fhss.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,29 @@ bool test_fhss_enable()
4444
fhss_timer.fhss_timer_stop = &fhss_timer_stop_stub;
4545

4646
// Test NULL configurations
47-
if (fhss_enable(NULL, &fhss_configuration, &fhss_timer, NULL) != -1) {
47+
if (fhss_enable(NULL, &fhss_configuration, &fhss_timer, NULL) != NULL) {
4848
return false;
4949
}
50-
if (fhss_enable(fhss_api, NULL, &fhss_timer, NULL) != -1) {
50+
if (fhss_enable(fhss_api, NULL, &fhss_timer, NULL) != NULL) {
5151
return false;
5252
}
53-
if (fhss_enable(fhss_api, &fhss_configuration, NULL, NULL) != -1) {
53+
if (fhss_enable(fhss_api, &fhss_configuration, NULL, NULL) != NULL) {
5454
return false;
5555
}
5656
// Test without channels
5757
channel_list_stub.uint8_value = 0;
58-
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != -2) {
58+
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
5959
return false;
6060
}
6161
// Test without memory
6262
nsdynmemlib_stub.returnCounter = 0;
6363
channel_list_stub.uint8_value = 50;
64-
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != -3) {
64+
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
6565
return false;
6666
}
6767
// Test with proper configuration
6868
nsdynmemlib_stub.returnCounter = 1;
69-
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != 0) {
69+
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) == NULL) {
7070
return false;
7171
}
7272
// Test that API is stored
@@ -86,7 +86,7 @@ bool test_fhss_enable()
8686
// Test tasklet creation failed
8787
fhss_beacon_tasklet_stub.int8_value = -1;
8888
nsdynmemlib_stub.returnCounter = 1;
89-
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != -5) {
89+
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
9090
return false;
9191
}
9292
fhss_disable(fhss_struct);
@@ -551,6 +551,7 @@ bool test_fhss_set_datarate()
551551
bool test_fhss_sync_with_beacon()
552552
{
553553
fhss_struct = malloc(sizeof(fhss_structure_t));
554+
memset(fhss_struct, 0, sizeof(fhss_structure_t));
554555
fhss_synchronization_beacon_payload_s payload;
555556

556557
fhss_struct->number_of_channels = 50;
@@ -564,6 +565,7 @@ bool test_fhss_sync_with_beacon()
564565
fhss_struct->platform_functions.fhss_timer_stop = &fhss_timer_stop_stub;
565566
fhss_struct->platform_functions.fhss_timer_start = &fhss_timer_start;
566567
fhss_struct->platform_functions.fhss_get_remaining_slots = &fhss_get_remaining_slots_stub;
568+
fhss_struct->platform_functions.fhss_resolution_divider = 1;
567569
fhss_struct->fhss_configuration.fhss_max_synch_interval = 240;
568570
fhss_struct->synch_interval = 150000;
569571

@@ -747,6 +749,7 @@ bool test_fhss_superframe_handler()
747749
{
748750
fhss_api_t fhss_api;
749751
fhss_struct = malloc(sizeof(fhss_structure_t));
752+
memset(fhss_struct, 0, sizeof(fhss_structure_t));
750753
fhss_struct->fhss_api = &fhss_api;
751754
fhss_struct->platform_functions.fhss_timer_start = &fhss_timer_start;
752755
fhss_struct->callbacks.read_tx_queue_size = &mac_read_tx_queue_sizes;
@@ -775,8 +778,7 @@ bool test_fhss_superframe_handler()
775778
fhss_struct->channel_list_counter = 999;
776779
fhss_superframe_handler(&fhss_api, 0);
777780
// Current superframe, channel index, Beacons sent counter and channel list counter should be cleared
778-
if (fhss_struct->current_superframe != 0 || fhss_struct->current_channel_index != 0 ||
779-
fhss_struct->synch_infos_sent_counter != 0 || fhss_struct->channel_list_counter != 0) {
781+
if (fhss_struct->current_superframe != 0 || fhss_struct->current_channel_index != 0) {
780782
return false;
781783
}
782784
fhss_struct->fhss_timeout = 50000;

test/nanostack/unittest/service_libs/fhss_config/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TEST_SRC_FILES = \
1414
../../stub/mbed_trace_stub.c \
1515
../../stub/nsdynmemLIB_stub.c \
1616
../../stub/fhss_stub.c \
17+
../../stub/fhss_ws_stub.c \
1718
../../stub/fhss_mac_interface_stub.c \
1819

1920
include ../../MakefileWorker.mk

test/nanostack/unittest/stub/fhss_stub.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
fhss_stub_def fhss_stub;
2828

29-
int8_t fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics)
29+
fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer, fhss_statistics_t *fhss_statistics)
3030
{
31-
return fhss_stub.int8_value;
31+
if (fhss_stub.int8_value == -1) {
32+
return NULL;
33+
}
34+
return &fhss_stub.fhss_struct;
3235
}
3336

3437
int8_t fhss_disable(fhss_structure_t *fhss_structure)
@@ -196,3 +199,8 @@ int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_sta
196199
{
197200
return 0;
198201
}
202+
203+
void fhss_set_internal_callbacks(fhss_structure_t *fhss_structure)
204+
{
205+
206+
}

test/nanostack/unittest/stub/fhss_ws_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@
2222
#include "Service_Libs/fhss/fhss_common.h"
2323
#include "Service_Libs/fhss/fhss.h"
2424
#include "Service_Libs/fhss/fhss_beacon.h"
25+
26+
void fhss_ws_set_internal_callbacks(fhss_structure_t *fhss_structure)
27+
{
28+
29+
}

0 commit comments

Comments
 (0)