Skip to content

Commit

Permalink
Merge pull request ARMmbed#1589 from ARMmbed/IOTTHD-2218
Browse files Browse the repository at this point in the history
FHSS unit tests: Implemented FHSS WS tests
  • Loading branch information
Jarkko Paso committed Feb 28, 2018
2 parents 057b6ec + 9ae6511 commit 73c6bc1
Show file tree
Hide file tree
Showing 15 changed files with 750 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/Service_Libs/fhss/fhss.c
Expand Up @@ -61,7 +61,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
}
fhss_struct->bs = ns_dyn_mem_alloc(sizeof(fhss_bs_t));
if (!fhss_struct->bs) {
ns_dyn_mem_free(fhss_struct);
fhss_free_instance(fhss_api);
return NULL;
}
memset(fhss_struct->bs, 0, sizeof(fhss_bs_t));
Expand Down
10 changes: 10 additions & 0 deletions source/Service_Libs/fhss/fhss_common.c
Expand Up @@ -60,6 +60,16 @@ fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_
return fhss_struct;
}

int8_t fhss_free_instance(fhss_api_t *fhss_api)
{
if (fhss_struct->fhss_api != fhss_api) {
return -1;
}
ns_dyn_mem_free(fhss_struct);
fhss_struct = NULL;
return 0;
}

static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
{
(void) slots;
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_common.h
Expand Up @@ -43,6 +43,7 @@ struct fhss_structure
};

fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer);
int8_t fhss_free_instance(fhss_api_t *fhss_api);
int8_t fhss_set_datarate(fhss_structure_t *fhss_structure, uint32_t datarate);
fhss_structure_t *fhss_get_object_with_api(const fhss_api_t *fhss_api);
void fhss_clear_active_event(fhss_structure_t *fhss_structure, uint8_t event_type);
Expand Down
22 changes: 14 additions & 8 deletions source/Service_Libs/fhss/fhss_ws.c
Expand Up @@ -66,7 +66,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
}
fhss_struct->ws = ns_dyn_mem_alloc(sizeof(fhss_ws_t));
if (!fhss_struct->ws) {
ns_dyn_mem_free(fhss_struct);
fhss_free_instance(fhss_api);
return NULL;
}
memset(fhss_struct->ws, 0, sizeof(fhss_ws_t));
Expand All @@ -76,7 +76,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
return fhss_struct;
}

static void fhss_ws_update_bc_channel(fhss_structure_t *fhss_structure)
static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
{
int32_t next_channel;

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

static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
{
(void) delay;
int32_t next_channel;
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
if (!fhss_structure) {
return;
}
if (fhss_structure->ws->is_on_bc_channel == false) {
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval*1000, fhss_broadcast_handler);
fhss_structure->ws->is_on_bc_channel = true;
fhss_ws_update_bc_channel(fhss_structure);
next_channel = fhss_ws_calc_bc_channel(fhss_structure);
} else {
uint32_t timeout = (fhss_structure->ws->fhss_configuration.fhss_broadcast_interval - fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval) * 1000;
fhss_start_timer(fhss_structure, timeout, fhss_broadcast_handler);
fhss_structure->ws->is_on_bc_channel = false;
// Should return to own (unicast) listening channel after broadcast channel
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, fhss_structure->rx_channel);
next_channel = fhss_structure->rx_channel;
#ifdef FHSS_CHANNEL_DEBUG
tr_info("%"PRIu32" UC %u", fhss_structure->platform_functions.fhss_get_timestamp(fhss_structure->fhss_api), fhss_structure->rx_channel);
#endif /*FHSS_CHANNEL_DEBUG*/
}
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
}

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

static void fhss_ws_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id)
{
(void) pan_id;
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
Expand Down Expand Up @@ -201,7 +203,7 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
int32_t next_channel;
fhss_structure->callbacks.read_mac_address(fhss_structure->fhss_api, mac_address);
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {

return;
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels);
if (++fhss_structure->ws->uc_slot == fhss_structure->number_of_channels) {
Expand Down Expand Up @@ -250,7 +252,11 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_VENDOR_DEF_CF) {
if (fhss_structure->ws->fhss_configuration.vendor_defined_cf) {
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);
} else {
return -1;
}
} else {
return -1;
}
#ifdef FHSS_CHANNEL_DEBUG
tr_debug("TX channel: %u %u", tx_channel, destination_slot+1);
Expand Down Expand Up @@ -371,7 +377,7 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
fhss_structure->fhss_api->receive_frame = &fhss_ws_receive_frame_callback;
fhss_structure->fhss_api->data_tx_done = &fhss_ws_data_tx_done_callback;
fhss_structure->fhss_api->data_tx_fail = &fhss_ws_data_tx_fail_callback;
fhss_structure->fhss_api->synch_state_set = &fhss_ws_handle_state_set;
fhss_structure->fhss_api->synch_state_set = &fhss_ws_synch_state_set_callback;
fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb;
fhss_structure->fhss_api->get_retry_period = NULL;
fhss_structure->fhss_api->write_synch_info = &fhss_ws_write_synch_info_callback;
Expand Down
28 changes: 28 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_ws/Makefile
@@ -0,0 +1,28 @@
include ../../makefile_defines.txt

COMPONENT_NAME = fhss_ws_unit

#This must be changed manually
SRC_FILES = \
../../../../../source/Service_Libs/fhss/fhss_ws.c \


TEST_SRC_FILES = \
main.cpp \
fhsswstest.cpp \
test_fhss_ws.c \
../../stub/mbed_trace_stub.c \
../../stub/nsdynmemLIB_stub.c \
../../stub/common_functions_stub.c \
../../stub/channel_list_stub.c \
../../stub/channel_functions_stub.c \
../../stub/fhss_stub.c \
../../stub/fhss_common_stub.c \
../../stub/fhss_mac_interface_stub.c \
../../stub/fhss_callbacks_stub.c \
../../stub/fhss_platform_stub.c \

include ../../MakefileWorker.mk

CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

90 changes: 90 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_ws/fhsswstest.cpp
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2016-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_fhss_ws.h"


TEST_GROUP(fhssws)
{
void setup()
{
}

void teardown()
{
}
};

TEST(fhssws, test_fhss_ws_enable)
{
CHECK(test_fhss_ws_enable());
}

TEST(fhssws, test_fhss_ws_is_broadcast_channel_callback)
{
CHECK(test_fhss_ws_is_broadcast_channel_callback());
}

TEST(fhssws, test_fhss_ws_tx_handle_callback)
{
CHECK(test_fhss_ws_tx_handle_callback());
}

TEST(fhssws, test_fhss_ws_check_tx_conditions_callback)
{
CHECK(test_fhss_ws_check_tx_conditions_callback());
}

TEST(fhssws, test_fhss_ws_receive_frame_callback)
{
CHECK(test_fhss_ws_receive_frame_callback());
}

TEST(fhssws, test_fhss_ws_data_tx_done_callback)
{
CHECK(test_fhss_ws_data_tx_done_callback());
}

TEST(fhssws, test_fhss_ws_data_tx_fail_callback)
{
CHECK(test_fhss_ws_data_tx_fail_callback());
}

TEST(fhssws, test_fhss_ws_synch_state_set_callback)
{
CHECK(test_fhss_ws_synch_state_set_callback());
}

TEST(fhssws, test_fhss_ws_write_synch_info_callback)
{
CHECK(test_fhss_ws_write_synch_info_callback());
}

TEST(fhssws, test_fhss_broadcast_handler)
{
CHECK(test_fhss_broadcast_handler());
}

TEST(fhssws, test_fhss_ws_update_uc_channel_callback)
{
CHECK(test_fhss_ws_update_uc_channel_callback());
}

TEST(fhssws, test_fhss_unicast_handler)
{
CHECK(test_fhss_unicast_handler());
}
28 changes: 28 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_ws/main.cpp
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2016, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

IMPORT_TEST_GROUP(fhssws);

0 comments on commit 73c6bc1

Please sign in to comment.