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

Commit 49c213a

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Added more tx handle tests
1 parent d5cc85a commit 49c213a

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

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

Lines changed: 33 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
@@ -90,7 +91,7 @@ static fhss_api_t *test_generate_fhss_api(void)
9091
memset(&ws, 0, sizeof(fhss_ws_t));
9192
memset(&fhss_callbacks_stub, 0, sizeof(fhss_callbacks_stub_def));
9293
memset(&fhss_common_stub, 0, sizeof(fhss_common_stub_def));
93-
neighbor_info.uc_timing_info.ufsi = 1000;
94+
neighbor_info.uc_timing_info.ufsi = 1000000;
9495
neighbor_info.uc_timing_info.unicast_channel_function = WS_TR51CF;
9596
neighbor_info.uc_timing_info.unicast_dwell_interval = 200;
9697
neighbor_info.uc_timing_info.utt_rx_timestamp = 100000;
@@ -191,9 +192,37 @@ bool test_fhss_ws_tx_handle_callback()
191192
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) {
192193
return false;
193194
}
194-
// 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+
*/
195200
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
196-
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)) {
203+
return false;
204+
}
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)) {
197226
return false;
198227
}
199228
// For more coverage, set neighbor info NULL

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)