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

Commit bb152ce

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1617 from ARMmbed/IOTTHD-2321
Iotthd 2321
2 parents 681dedd + 49c213a commit bb152ce

File tree

8 files changed

+210
-4
lines changed

8 files changed

+210
-4
lines changed

test/nanostack/unittest/service_libs/fhss_config/fhssconfigtest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ TEST(fhss_config, test_ns_fhss_create)
4848
{
4949
CHECK(test_ns_fhss_create());
5050
}
51+
52+
TEST(fhss_config, test_ns_fhss_ws_set_parent)
53+
{
54+
CHECK(test_ns_fhss_ws_set_parent());
55+
}
56+
57+
TEST(fhss_config, test_ns_fhss_ws_remove_parent)
58+
{
59+
CHECK(test_ns_fhss_ws_remove_parent());
60+
}

test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,38 @@ bool test_ns_fhss_configuration_set()
118118
ns_fhss_configuration_set(NULL, NULL);
119119
return true;
120120
}
121+
122+
bool test_ns_fhss_ws_set_parent()
123+
{
124+
fhss_api_t api;
125+
uint8_t dest_address[8] = {1,2,3,4,5,6,7,8};
126+
broadcast_timing_info_t bc_timing_info;
127+
// Test without api
128+
fhss_common_stub.bool_value = false;
129+
if (-1 != ns_fhss_ws_set_parent(NULL, dest_address, &bc_timing_info)) {
130+
return false;
131+
}
132+
// Test success
133+
fhss_common_stub.bool_value = true;
134+
if (0 != ns_fhss_ws_set_parent(&api, dest_address, &bc_timing_info)) {
135+
return false;
136+
}
137+
return true;
138+
}
139+
140+
bool test_ns_fhss_ws_remove_parent()
141+
{
142+
fhss_api_t api;
143+
uint8_t dest_address[8] = {1,2,3,4,5,6,7,8};
144+
// Test without api
145+
fhss_common_stub.bool_value = false;
146+
if (-1 != ns_fhss_ws_remove_parent(NULL, dest_address)) {
147+
return false;
148+
}
149+
// Test success
150+
fhss_common_stub.bool_value = true;
151+
if (0 != ns_fhss_ws_remove_parent(&api, dest_address)) {
152+
return false;
153+
}
154+
return true;
155+
}

test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ bool test_ns_fhss_ws_create();
3131
bool test_ns_fhss_delete();
3232
// Test setting synchronization time configuration
3333
bool test_ns_fhss_configuration_set();
34+
// Test setting WS parent
35+
bool test_ns_fhss_ws_set_parent();
36+
// Test removing WS parent
37+
bool test_ns_fhss_ws_remove_parent();
3438

3539

3640
#ifdef __cplusplus

test/nanostack/unittest/service_libs/fhss_ws/fhsswstest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ TEST(fhssws, test_fhss_unicast_handler)
8888
{
8989
CHECK(test_fhss_unicast_handler());
9090
}
91+
92+
TEST(fhssws, test_fhss_ws_set_parent)
93+
{
94+
CHECK(test_fhss_ws_set_parent());
95+
}
96+
97+
TEST(fhssws, test_fhss_ws_remove_parent)
98+
{
99+
CHECK(test_fhss_ws_remove_parent());
100+
}

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

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
#include "fhss_stub.h"
2828
#include "fhss_callbacks_stub.h"
2929
#include "fhss_platform_stub.h"
30+
#include "channel_functions_stub.h"
3031
#include "common_functions_stub.h"
3132

3233
#define VENDOR_CHANNEL 89
3334
#define DEFAULT_CHANNEL 99
3435
#define DEFAULT_PANID 0xabcd
3536
#define DEFAULT_FRAME_TYPE FHSS_DATA_FRAME
3637
#define DEFAULT_FHSS_STATE FHSS_SYNCHRONIZED
37-
#define DEFAULT_TX_TIME 0
38+
#define DEFAULT_TX_TIME 1000000
3839
#define DEFAULT_TIMER_DELAY 0
3940
#define DEFAULT_FRAME_LENGTH 100
4041
#define DEFAULT_PHY_HEAD_LENGTH 10
@@ -54,6 +55,11 @@ static int32_t app_channel_function(const fhss_api_t *api, uint16_t slot, uint8_
5455
return VENDOR_CHANNEL;
5556
}
5657

58+
static fhss_ws_neighbor_timing_info_t *app_no_neighbor_info(const fhss_api_t *api, uint8_t eui64[8])
59+
{
60+
return NULL;
61+
}
62+
5763
static fhss_ws_neighbor_timing_info_t *app_get_neighbor_info(const fhss_api_t *api, uint8_t eui64[8])
5864
{
5965
return &neighbor_info;
@@ -85,6 +91,10 @@ static fhss_api_t *test_generate_fhss_api(void)
8591
memset(&ws, 0, sizeof(fhss_ws_t));
8692
memset(&fhss_callbacks_stub, 0, sizeof(fhss_callbacks_stub_def));
8793
memset(&fhss_common_stub, 0, sizeof(fhss_common_stub_def));
94+
neighbor_info.uc_timing_info.ufsi = 1000000;
95+
neighbor_info.uc_timing_info.unicast_channel_function = WS_TR51CF;
96+
neighbor_info.uc_timing_info.unicast_dwell_interval = 200;
97+
neighbor_info.uc_timing_info.utt_rx_timestamp = 100000;
8898
fhss_common_stub.fhss_struct.fhss_api = &fhss_api;
8999
fhss_common_stub.fhss_struct.ws = &ws;
90100
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_uc_dwell_interval = 200;
@@ -170,17 +180,53 @@ bool test_fhss_ws_tx_handle_callback()
170180
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, true, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != 0) {
171181
return false;
172182
}
173-
// Test fixed channel
183+
// Test when no neighbor info found
174184
fhss_common_stub.fhss_struct.fhss_state = DEFAULT_FHSS_STATE;
185+
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_no_neighbor_info;
186+
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -1) {
187+
return false;
188+
}
189+
// Test fixed channel
190+
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_get_neighbor_info;
175191
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
176192
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -1) {
177193
return false;
178194
}
179-
// Test TR51 channel function
195+
/* Test TR51 channel function
196+
* Dest. slot: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
197+
* |dest. ufsi| 900ms |
198+
* timestamps: 100000us| 1000000us|
199+
*/
180200
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
181-
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != 0) {
201+
if ((fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != 0)
202+
|| (channel_functions_stub.uint8_value != 7)) {
182203
return false;
183204
}
205+
/* Test TR51 channel function when timestamp overflows
206+
* Dest. slot: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
207+
* |dest. ufsi| 1000ms |
208+
* timestamps: 4294867000us| 900000us|
209+
*/
210+
neighbor_info.uc_timing_info.utt_rx_timestamp = 4294867000;
211+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
212+
if ((fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, 900000) != 0)
213+
|| (channel_functions_stub.uint8_value != 7)) {
214+
return false;
215+
}
216+
/* Test TR51 channel function when channel list overflows
217+
* Dest. slot: | 0 | 1 | 2 | 3 |...| 0 | 1 | 2 | 3 |
218+
* |dest. ufsi| 10000ms |
219+
* timestamps: 100000us| 10100000us|
220+
*/
221+
neighbor_info.uc_timing_info.utt_rx_timestamp = 100000;
222+
uint32_t tx_time = neighbor_info.uc_timing_info.utt_rx_timestamp + (fhss_common_stub.fhss_struct.number_of_channels * neighbor_info.uc_timing_info.unicast_dwell_interval * 1000);
223+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
224+
if ((fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, tx_time) != 0)
225+
|| (channel_functions_stub.uint8_value != 2)) {
226+
return false;
227+
}
228+
// For more coverage, set neighbor info NULL
229+
memset(&neighbor_info, 0, sizeof(fhss_ws_neighbor_timing_info_t));
184230
// Test direct hash channel function
185231
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_DH1CF;
186232
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != 0) {
@@ -418,3 +464,62 @@ bool test_fhss_unicast_handler()
418464
fhss_common_stub.callback[0](fhss_common_stub.fhss_struct.fhss_api, DEFAULT_TIMER_DELAY);
419465
return true;
420466
}
467+
468+
bool test_fhss_ws_set_parent()
469+
{
470+
uint8_t dest_address[8] = {1,2,3,4,5,6,7,8};
471+
broadcast_timing_info_t bc_timing_info;
472+
memset(&bc_timing_info, 0, sizeof(broadcast_timing_info_t));
473+
fhss_api_t *api = test_generate_fhss_api();
474+
475+
// Test without WS enabled FHSS
476+
fhss_structure_t fake_fhss_structure;
477+
memset(&fake_fhss_structure, 0, sizeof(fhss_structure_t));
478+
if (-1 != fhss_ws_set_parent(&fake_fhss_structure, dest_address, &bc_timing_info)) {
479+
return false;
480+
}
481+
// Test success
482+
bc_timing_info.broadcast_channel_function = WS_TR51CF;
483+
bc_timing_info.broadcast_dwell_interval = 250;
484+
bc_timing_info.broadcast_interval = 1000;
485+
bc_timing_info.broadcast_interval_offset = 2000;
486+
bc_timing_info.broadcast_schedule_id = 1;
487+
bc_timing_info.broadcast_slot = 10;
488+
bc_timing_info.bt_rx_timestamp = 100000;
489+
if (0 != fhss_ws_set_parent(&fhss_common_stub.fhss_struct, dest_address, &bc_timing_info)
490+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_channel_function != WS_TR51CF)
491+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_dwell_interval != 250)
492+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_interval != 1000)
493+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_interval_offset != 2000)
494+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_schedule_id != 1)
495+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_slot != 10)
496+
|| (fhss_common_stub.fhss_struct.ws->parent_bc_info->bt_rx_timestamp != 100000)) {
497+
return false;
498+
}
499+
// Test updating value
500+
bc_timing_info.broadcast_interval_offset = 5000;
501+
if (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_interval_offset != 5000) {
502+
return false;
503+
}
504+
return true;
505+
}
506+
507+
bool test_fhss_ws_remove_parent()
508+
{
509+
uint8_t dest_address[8] = {1,2,3,4,5,6,7,8};
510+
fhss_api_t *api = test_generate_fhss_api();
511+
broadcast_timing_info_t bc_timing_info;
512+
fhss_common_stub.fhss_struct.ws->parent_bc_info = &bc_timing_info;
513+
514+
// Test without WS enabled FHSS
515+
fhss_structure_t fake_fhss_structure;
516+
memset(&fake_fhss_structure, 0, sizeof(fhss_structure_t));
517+
if (-1 != fhss_ws_remove_parent(&fake_fhss_structure, dest_address)) {
518+
return false;
519+
}
520+
// Test success
521+
if ((0 != fhss_ws_remove_parent(&fhss_common_stub.fhss_struct, dest_address)) || (fhss_common_stub.fhss_struct.ws->parent_bc_info != NULL)) {
522+
return false;
523+
}
524+
return true;
525+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ bool test_fhss_ws_write_synch_info_callback();
3535
bool test_fhss_broadcast_handler();
3636
bool test_fhss_ws_update_uc_channel_callback();
3737
bool test_fhss_unicast_handler();
38+
bool test_fhss_ws_set_parent();
39+
bool test_fhss_ws_remove_parent();
3840

3941
#ifdef __cplusplus
4042
}

test/nanostack/unittest/stub/channel_functions_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
* limitations under the License.
1616
*/
1717
#include "nsconfig.h"
18+
#include "channel_functions_stub.h"
1819
#include <string.h>
1920

21+
channel_functions_stub_def channel_functions_stub;
22+
2023
int32_t dh1cf_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
2124
{
2225
return 1;
@@ -29,6 +32,7 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n
2932

3033
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels)
3134
{
35+
channel_functions_stub.uint8_value = slot_number;
3236
return 3;
3337
}
3438

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2016, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef __CHANNEL_FUNCTIONS_STUB_H__
19+
#define __CHANNEL_FUNCTIONS_STUB_H__
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
26+
typedef struct {
27+
uint8_t uint8_value;
28+
} channel_functions_stub_def;
29+
30+
extern channel_functions_stub_def channel_functions_stub;
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif // __CHANNEL_FUNCTIONS_STUB_H__

0 commit comments

Comments
 (0)