Skip to content

Commit 9ae6511

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Implemented FHSS WS tests
1 parent 8147217 commit 9ae6511

File tree

15 files changed

+750
-10
lines changed

15 files changed

+750
-10
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
6161
}
6262
fhss_struct->bs = ns_dyn_mem_alloc(sizeof(fhss_bs_t));
6363
if (!fhss_struct->bs) {
64-
ns_dyn_mem_free(fhss_struct);
64+
fhss_free_instance(fhss_api);
6565
return NULL;
6666
}
6767
memset(fhss_struct->bs, 0, sizeof(fhss_bs_t));

source/Service_Libs/fhss/fhss_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_
6060
return fhss_struct;
6161
}
6262

63+
int8_t fhss_free_instance(fhss_api_t *fhss_api)
64+
{
65+
if (fhss_struct->fhss_api != fhss_api) {
66+
return -1;
67+
}
68+
ns_dyn_mem_free(fhss_struct);
69+
fhss_struct = NULL;
70+
return 0;
71+
}
72+
6373
static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
6474
{
6575
(void) slots;

source/Service_Libs/fhss/fhss_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct fhss_structure
4343
};
4444

4545
fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer);
46+
int8_t fhss_free_instance(fhss_api_t *fhss_api);
4647
int8_t fhss_set_datarate(fhss_structure_t *fhss_structure, uint32_t datarate);
4748
fhss_structure_t *fhss_get_object_with_api(const fhss_api_t *fhss_api);
4849
void fhss_clear_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
6666
}
6767
fhss_struct->ws = ns_dyn_mem_alloc(sizeof(fhss_ws_t));
6868
if (!fhss_struct->ws) {
69-
ns_dyn_mem_free(fhss_struct);
69+
fhss_free_instance(fhss_api);
7070
return NULL;
7171
}
7272
memset(fhss_struct->ws, 0, sizeof(fhss_ws_t));
@@ -76,7 +76,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
7676
return fhss_struct;
7777
}
7878

79-
static void fhss_ws_update_bc_channel(fhss_structure_t *fhss_structure)
79+
static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
8080
{
8181
int32_t next_channel;
8282

@@ -98,30 +98,32 @@ static void fhss_ws_update_bc_channel(fhss_structure_t *fhss_structure)
9898
#ifdef FHSS_CHANNEL_DEBUG
9999
tr_info("%"PRIu32" BC %u %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), next_channel, fhss_structure->ws->bc_slot);
100100
#endif /*FHSS_CHANNEL_DEBUG*/
101-
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
101+
return next_channel;
102102
}
103103

104104
static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
105105
{
106106
(void) delay;
107+
int32_t next_channel;
107108
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
108109
if (!fhss_structure) {
109110
return;
110111
}
111112
if (fhss_structure->ws->is_on_bc_channel == false) {
112113
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval*1000, fhss_broadcast_handler);
113114
fhss_structure->ws->is_on_bc_channel = true;
114-
fhss_ws_update_bc_channel(fhss_structure);
115+
next_channel = fhss_ws_calc_bc_channel(fhss_structure);
115116
} else {
116117
uint32_t timeout = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) * 1000;
117118
fhss_start_timer(fhss_structure, timeout, fhss_broadcast_handler);
118119
fhss_structure->ws->is_on_bc_channel = false;
119120
// Should return to own (unicast) listening channel after broadcast channel
120-
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, fhss_structure->rx_channel);
121+
next_channel = fhss_structure->rx_channel;
121122
#ifdef FHSS_CHANNEL_DEBUG
122123
tr_info("%"PRIu32" UC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), fhss_structure->rx_channel);
123124
#endif /*FHSS_CHANNEL_DEBUG*/
124125
}
126+
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
125127
}
126128

127129
static int own_floor(float value)
@@ -172,7 +174,7 @@ static uint32_t fhss_ws_get_sf_timeout_callback(fhss_structure_t *fhss_structure
172174
return fhss_structure->ws->fhss_configuration.fhss_uc_dwell_interval * 1000;
173175
}
174176

175-
static void fhss_ws_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
177+
static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
176178
{
177179
(void) pan_id;
178180
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
@@ -201,7 +203,7 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
201203
int32_t next_channel;
202204
fhss_structure->callbacks.read_mac_address(fhss_structure->fhss_api, mac_address);
203205
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
204-
206+
return;
205207
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
206208
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels);
207209
if (++fhss_structure->ws->uc_slot == fhss_structure->number_of_channels) {
@@ -250,7 +252,11 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
250252
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_VENDOR_DEF_CF) {
251253
if (fhss_structure->ws->fhss_configuration.vendor_defined_cf) {
252254
tx_channel = fhss_structure->ws->fhss_configuration.vendor_defined_cf(fhss_structure->fhss_api, fhss_structure->ws->bc_slot, destination_address, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels);
255+
} else {
256+
return -1;
253257
}
258+
} else {
259+
return -1;
254260
}
255261
#ifdef FHSS_CHANNEL_DEBUG
256262
tr_debug("TX channel: %u %u", tx_channel, destination_slot+1);
@@ -371,7 +377,7 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
371377
fhss_structure->fhss_api->receive_frame = &fhss_ws_receive_frame_callback;
372378
fhss_structure->fhss_api->data_tx_done = &fhss_ws_data_tx_done_callback;
373379
fhss_structure->fhss_api->data_tx_fail = &fhss_ws_data_tx_fail_callback;
374-
fhss_structure->fhss_api->synch_state_set = &fhss_ws_handle_state_set;
380+
fhss_structure->fhss_api->synch_state_set = &fhss_ws_synch_state_set_callback;
375381
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
376382
fhss_structure->fhss_api->get_retry_period = NULL;
377383
fhss_structure->fhss_api->write_synch_info = &fhss_ws_write_synch_info_callback;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = fhss_ws_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/Service_Libs/fhss/fhss_ws.c \
8+
9+
10+
TEST_SRC_FILES = \
11+
main.cpp \
12+
fhsswstest.cpp \
13+
test_fhss_ws.c \
14+
../../stub/mbed_trace_stub.c \
15+
../../stub/nsdynmemLIB_stub.c \
16+
../../stub/common_functions_stub.c \
17+
../../stub/channel_list_stub.c \
18+
../../stub/channel_functions_stub.c \
19+
../../stub/fhss_stub.c \
20+
../../stub/fhss_common_stub.c \
21+
../../stub/fhss_mac_interface_stub.c \
22+
../../stub/fhss_callbacks_stub.c \
23+
../../stub/fhss_platform_stub.c \
24+
25+
include ../../MakefileWorker.mk
26+
27+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
28+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2016-2017, 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+
#include "CppUTest/TestHarness.h"
18+
#include "test_fhss_ws.h"
19+
20+
21+
TEST_GROUP(fhssws)
22+
{
23+
void setup()
24+
{
25+
}
26+
27+
void teardown()
28+
{
29+
}
30+
};
31+
32+
TEST(fhssws, test_fhss_ws_enable)
33+
{
34+
CHECK(test_fhss_ws_enable());
35+
}
36+
37+
TEST(fhssws, test_fhss_ws_is_broadcast_channel_callback)
38+
{
39+
CHECK(test_fhss_ws_is_broadcast_channel_callback());
40+
}
41+
42+
TEST(fhssws, test_fhss_ws_tx_handle_callback)
43+
{
44+
CHECK(test_fhss_ws_tx_handle_callback());
45+
}
46+
47+
TEST(fhssws, test_fhss_ws_check_tx_conditions_callback)
48+
{
49+
CHECK(test_fhss_ws_check_tx_conditions_callback());
50+
}
51+
52+
TEST(fhssws, test_fhss_ws_receive_frame_callback)
53+
{
54+
CHECK(test_fhss_ws_receive_frame_callback());
55+
}
56+
57+
TEST(fhssws, test_fhss_ws_data_tx_done_callback)
58+
{
59+
CHECK(test_fhss_ws_data_tx_done_callback());
60+
}
61+
62+
TEST(fhssws, test_fhss_ws_data_tx_fail_callback)
63+
{
64+
CHECK(test_fhss_ws_data_tx_fail_callback());
65+
}
66+
67+
TEST(fhssws, test_fhss_ws_synch_state_set_callback)
68+
{
69+
CHECK(test_fhss_ws_synch_state_set_callback());
70+
}
71+
72+
TEST(fhssws, test_fhss_ws_write_synch_info_callback)
73+
{
74+
CHECK(test_fhss_ws_write_synch_info_callback());
75+
}
76+
77+
TEST(fhssws, test_fhss_broadcast_handler)
78+
{
79+
CHECK(test_fhss_broadcast_handler());
80+
}
81+
82+
TEST(fhssws, test_fhss_ws_update_uc_channel_callback)
83+
{
84+
CHECK(test_fhss_ws_update_uc_channel_callback());
85+
}
86+
87+
TEST(fhssws, test_fhss_unicast_handler)
88+
{
89+
CHECK(test_fhss_unicast_handler());
90+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#include "CppUTest/CommandLineTestRunner.h"
19+
#include "CppUTest/TestPlugin.h"
20+
#include "CppUTest/TestRegistry.h"
21+
#include "CppUTestExt/MockSupportPlugin.h"
22+
int main(int ac, char** av)
23+
{
24+
return CommandLineTestRunner::RunAllTests(ac, av);
25+
}
26+
27+
IMPORT_TEST_GROUP(fhssws);
28+

0 commit comments

Comments
 (0)