Skip to content

Commit a849c8d

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Update FHSS tests
- Some tests removed and will be refactored later
1 parent 83bd90e commit a849c8d

File tree

4 files changed

+7
-72
lines changed

4 files changed

+7
-72
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
8282
fhss_reset(fhss_struct);
8383

8484
if (fhss_beacon_create_tasklet(fhss_struct) < 0) {
85-
// XXX: should we free the fhss_structure here?
85+
ns_dyn_mem_free(fhss_struct->bs);
86+
ns_dyn_mem_free(fhss_struct);
8687
return NULL;
8788
}
8889

test/nanostack/unittest/service_libs/fhss/fhsstest.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ TEST(fhss, test_fhss_timeout_start)
3939
CHECK(test_fhss_timeout_start());
4040
}
4141

42-
TEST(fhss, test_fhss_event_timer_cb)
43-
{
44-
CHECK(test_fhss_event_timer_cb());
45-
}
4642

4743
TEST(fhss, test_fhss_update_synch_parent_address)
4844
{

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

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@
3333

3434
static fhss_api_t fhss_test_api;
3535
static fhss_timer_t fhss_test_timer;
36-
static fhss_structure_t *fhss_struct;
36+
static fhss_structure_t *fhss_struct = NULL;
3737

3838

3939
static void test_alloc_fhss_struct(void)
4040
{
4141
nsdynmemlib_stub.returnCounter += 1;
42+
fhss_test_timer.fhss_timer_stop = &fhss_timer_stop_stub;
4243
fhss_struct = fhss_allocate_instance(&fhss_test_api, &fhss_test_timer);
44+
fhss_set_callbacks(fhss_struct);
4345
fhss_struct->bs = malloc(sizeof(fhss_bs_t));
4446
}
4547

4648
static void test_free_fhss_struct(void)
4749
{
48-
free(fhss_struct->bs);
49-
free(fhss_struct);
50+
fhss_disable(fhss_struct);
5051
fhss_struct = NULL;
5152
}
5253

@@ -81,34 +82,7 @@ bool test_fhss_enable()
8182
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
8283
return false;
8384
}
84-
// Test with proper configuration
85-
nsdynmemlib_stub.returnCounter = 2;
86-
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) == NULL) {
87-
return false;
88-
}
89-
// Test that API is stored
90-
if (fhss_struct != fhss_get_object_with_api(fhss_api)) {
91-
return false;
92-
}
93-
// Test NULL API
94-
if (fhss_struct == fhss_get_object_with_api(NULL)) {
95-
return false;
96-
}
97-
// Test fake API
98-
fhss_api_t fhss_fake_api;
99-
if (fhss_struct == fhss_get_object_with_api(&fhss_fake_api)) {
100-
return false;
101-
}
102-
test_free_fhss_struct();
103-
fhss_struct = 0;
104-
// Test tasklet creation failed
105-
fhss_beacon_tasklet_stub.int8_value = -1;
106-
nsdynmemlib_stub.returnCounter = 2;
107-
if (fhss_enable(fhss_api, &fhss_configuration, &fhss_timer, NULL) != NULL) {
108-
return false;
109-
}
110-
test_free_fhss_struct();
111-
fhss_struct = 0;
85+
11286
return true;
11387
}
11488

@@ -182,7 +156,6 @@ bool test_fhss_set_synch_configuration()
182156
return false;
183157
}
184158
test_free_fhss_struct();
185-
fhss_struct = 0;
186159
return true;
187160
}
188161

@@ -208,7 +181,6 @@ bool test_fhss_set_datarate()
208181
return false;
209182
}
210183
test_free_fhss_struct();
211-
fhss_struct = 0;
212184
return true;
213185
}
214186

@@ -316,38 +288,6 @@ bool test_fhss_update_synch_parent_address()
316288
return true;
317289
}
318290

319-
bool test_fhss_event_timer_cb()
320-
{
321-
fhss_api_t fhss_api;
322-
fhss_configuration_t fhss_configuration;
323-
fhss_timer_t fhss_timer;
324-
nsdynmemlib_stub.returnCounter = 2;
325-
ns_timer_stub.cb_counter = 1;
326-
fhss_timer.fhss_timer_stop = &fhss_timer_stop_stub;
327-
328-
// To register callback, execute fhss enable
329-
fhss_enable(&fhss_api, &fhss_configuration, &fhss_timer, NULL);
330-
331-
fhss_struct->callbacks.tx_poll = mac_poll_tx_queue;
332-
fhss_struct->fhss_event_timer = 0;
333-
334-
if( ns_timer_stub.cb ){
335-
// Test with invalid timer id
336-
ns_timer_stub.cb(-1, 0);
337-
}
338-
if( ns_timer_stub.cb ){
339-
// Test with wrong timer id
340-
ns_timer_stub.cb(1, 0);
341-
}
342-
if( ns_timer_stub.cb ){
343-
// Test with proper timer id
344-
ns_timer_stub.cb(0, 0);
345-
}
346-
test_free_fhss_struct();
347-
fhss_struct = 0;
348-
return true;
349-
}
350-
351291
bool test_fhss_timeout_start()
352292
{
353293
uint32_t time = 1000;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ bool test_fhss_get_parent_address();
3737
bool test_fhss_compare_with_synch_parent_address();
3838
// Test updating synch parent address
3939
bool test_fhss_update_synch_parent_address();
40-
// Test event timer callback
41-
bool test_fhss_event_timer_cb();
4240
// Test starting FHSS timeout
4341
bool test_fhss_timeout_start();
4442
// Test stopping FHSS timeout

0 commit comments

Comments
 (0)