Skip to content

Commit 2012347

Browse files
author
Jarkko Paso
committed
Fixed FHSS UFSI calculation unit tests
1 parent 436f16e commit 2012347

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

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

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,36 @@ bool test_fhss_ws_synch_state_set_callback()
648648
return true;
649649
}
650650

651+
static void test_reset_synch_info(uint8_t *synch_info)
652+
{
653+
memset(synch_info, 0, 100);
654+
synch_info[0] = 0x05;
655+
synch_info[1] = 0x15;
656+
synch_info[2] = 0x02;
657+
synch_info[3] = 0x00;
658+
synch_info[4] = 0x00;
659+
synch_info[5] = 0x00;
660+
synch_info[6] = 0x00;
661+
synch_info[7] = 0x05;
662+
synch_info[8] = 0x15;
663+
synch_info[9] = 0x01;
664+
synch_info[10] = 0x04;
665+
synch_info[11] = 0x00;
666+
synch_info[12] = 0x00;
667+
synch_info[13] = 0x00;
668+
synch_info[14] = 0x00;
669+
synch_info[15] = 0x3f;
670+
}
671+
651672
bool test_fhss_ws_write_synch_info_callback()
652673
{
653674
fhss_api_t *api = test_generate_fhss_api();
654675
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
655676
fhss_common_stub.fhss_struct.rx_channel = 0;
656677
fhss_common_stub.fhss_struct.ws->unicast_timer_running = true;
657-
uint8_t synch_info[100] = {0x05, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3f};
678+
uint8_t synch_info[100];
679+
test_reset_synch_info(synch_info);
680+
658681
// Test when FHSS struct not found
659682
disable_fhss_struct();
660683
if (fhss_common_stub.fhss_struct.fhss_api->write_synch_info(api, synch_info, sizeof(synch_info), DEFAULT_FRAME_TYPE, DEFAULT_TX_TIME) != -1) {
@@ -671,6 +694,7 @@ bool test_fhss_ws_write_synch_info_callback()
671694
}
672695
fhss_platform_stub.remaining_slots_value = 100000;
673696
fhss_callbacks_stub.uint32_value = 1000000;
697+
fhss_common_stub.fhss_struct.ws->next_uc_timeout = fhss_callbacks_stub.uint32_value + fhss_platform_stub.remaining_slots_value;
674698
/* Test the UFSI field in synch info
675699
* slot: | 0(200ms) | 1(200ms) | 2(200ms) | 3(200ms) |
676700
* | ufsi(597ms) -> 1001599 |
@@ -680,8 +704,10 @@ bool test_fhss_ws_write_synch_info_callback()
680704
|| (test_ufsi(&synch_info[11], 1001599) != true)) {
681705
return false;
682706
}
707+
test_reset_synch_info(synch_info);
683708
// Test when timestamp overflows
684709
fhss_callbacks_stub.uint32_value = 4294960000;
710+
fhss_common_stub.fhss_struct.ws->next_uc_timeout = fhss_callbacks_stub.uint32_value + fhss_platform_stub.remaining_slots_value;
685711
/* Test the UFSI field in synch info
686712
* slot: | 0(200ms) | 1(200ms) | 2(200ms) | 3(200ms) |
687713
* | ufsi(597ms) -> 1001599 |
@@ -691,7 +717,33 @@ bool test_fhss_ws_write_synch_info_callback()
691717
|| (test_ufsi(&synch_info[11], 1001599) != true)) {
692718
return false;
693719
}
694-
720+
test_reset_synch_info(synch_info);
721+
// Test when TX time has passed
722+
fhss_callbacks_stub.uint32_value = 1000000;
723+
fhss_common_stub.fhss_struct.ws->next_uc_timeout = fhss_callbacks_stub.uint32_value + fhss_platform_stub.remaining_slots_value;
724+
/* Test the UFSI field in synch info
725+
* slot: | 0(200ms) | 1(200ms) | 2(200ms) | 3(200ms) |
726+
* | ufsi(500ms) -> 838860
727+
* timestamps: TX at 995000us|written at 1000000us|
728+
*/
729+
if ((fhss_common_stub.fhss_struct.fhss_api->write_synch_info(api, synch_info, sizeof(synch_info), DEFAULT_FRAME_TYPE, fhss_callbacks_stub.uint32_value - 5000) != 0)
730+
|| (test_ufsi(&synch_info[11], 838860) != true)) {
731+
return false;
732+
}
733+
test_reset_synch_info(synch_info);
734+
// Test when interrupt is delayed
735+
fhss_platform_stub.remaining_slots_value = 0;
736+
fhss_callbacks_stub.uint32_value = 1000000;
737+
fhss_common_stub.fhss_struct.ws->next_uc_timeout = fhss_callbacks_stub.uint32_value - 5000;
738+
/* Test the UFSI field in synch info
739+
* slot: | 0(200ms) | 1(200ms) | 2(200ms) | 3(200ms) |
740+
* | ufsi(597ms) -> 1001599
741+
* timestamps: written at 1000000us|TX at 1005000us|
742+
*/
743+
if ((fhss_common_stub.fhss_struct.fhss_api->write_synch_info(api, synch_info, sizeof(synch_info), DEFAULT_FRAME_TYPE, fhss_callbacks_stub.uint32_value + 7000) != 0)
744+
|| (test_ufsi(&synch_info[11], 1026765) != true)) {
745+
return false;
746+
}
695747
// Test when IE element not found
696748
memset(synch_info, 0, sizeof(synch_info));
697749
if (fhss_common_stub.fhss_struct.fhss_api->write_synch_info(api, synch_info, sizeof(synch_info), DEFAULT_FRAME_TYPE, DEFAULT_TX_TIME) != 0) {

0 commit comments

Comments
 (0)