Skip to content

Commit

Permalink
FHSS unit tests: Implemented FHSS common unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Mar 6, 2018
1 parent 2188af4 commit f973986
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 5 deletions.
9 changes: 4 additions & 5 deletions source/Service_Libs/fhss/fhss_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static bool fhss_read_active_event(fhss_structure_t *fhss_structure, uint8_t eve

fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer)
{
if (fhss_struct) {
if (fhss_struct || !fhss_api || !fhss_timer) {
return NULL;
}
fhss_struct = ns_dyn_mem_alloc(sizeof(fhss_structure_t));
Expand All @@ -61,7 +61,7 @@ fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_

int8_t fhss_free_instance(fhss_api_t *fhss_api)
{
if (fhss_struct->fhss_api != fhss_api) {
if (!fhss_struct || fhss_struct->fhss_api != fhss_api) {
return -1;
}
ns_dyn_mem_free(fhss_struct);
Expand All @@ -80,7 +80,7 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)

static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id)
{
if (timer_id <0 || !fhss_struct) {
if (timer_id < 0 || !fhss_struct) {
return NULL;
}
if (fhss_struct->fhss_event_timer == timer_id) {
Expand Down Expand Up @@ -140,7 +140,6 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
ns_dyn_mem_free(fhss_structure->bs);
ns_dyn_mem_free(fhss_structure->ws);
ns_dyn_mem_free(fhss_structure);
fhss_structure = 0;
fhss_struct = 0;
return 0;
}
Expand Down Expand Up @@ -189,7 +188,7 @@ int fhss_update_synch_parent_address(fhss_structure_t *fhss_structure)

void fhss_trig_event(fhss_structure_t *fhss_structure, uint8_t event_type)
{
if (fhss_read_active_event(fhss_structure, event_type) == true) {
if (!fhss_structure || fhss_read_active_event(fhss_structure, event_type) == true) {
return;
}
arm_event_s event;
Expand Down
26 changes: 26 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include ../../makefile_defines.txt

COMPONENT_NAME = fhss_common_unit

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


TEST_SRC_FILES = \
main.cpp \
fhsscommontest.cpp \
test_fhss_common.c \
../../stub/mbed_trace_stub.c \
../../stub/nsdynmemLIB_stub.c \
../../stub/event_stub.c \
../../stub/ns_timer_stub.c \
../../stub/fhss_stub.c \
../../stub/fhss_config_stub.c \
../../stub/fhss_platform_stub.c \
../../stub/fhss_callbacks_stub.c \

include ../../MakefileWorker.mk

CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2016 ARM. All rights reserved.
*/
#include "CppUTest/TestHarness.h"
#include "test_fhss_common.h"


TEST_GROUP(fhss_common)
{
void setup()
{
}

void teardown()
{
}
};

TEST(fhss_common, test_fhss_allocate_instance)
{
CHECK(test_fhss_allocate_instance());
}

TEST(fhss_common, test_fhss_free_instance)
{
CHECK(test_fhss_free_instance());
}

TEST(fhss_common, test_fhss_set_datarate)
{
CHECK(test_fhss_set_datarate());
}

TEST(fhss_common, test_fhss_get_object_with_api)
{
CHECK(test_fhss_get_object_with_api());
}

TEST(fhss_common, test_fhss_disable)
{
CHECK(test_fhss_disable());
}

TEST(fhss_common, test_fhss_start_timer)
{
CHECK(test_fhss_start_timer());
}

TEST(fhss_common, test_fhss_timeout_start)
{
CHECK(test_fhss_timeout_start());
}

TEST(fhss_common, test_fhss_timeout_stop)
{
CHECK(test_fhss_timeout_stop());
}

TEST(fhss_common, test_fhss_update_synch_parent_address)
{
CHECK(test_fhss_update_synch_parent_address());
}

TEST(fhss_common, test_fhss_trig_event)
{
CHECK(test_fhss_trig_event());
}

TEST(fhss_common, test_fhss_compare_with_synch_parent_address)
{
CHECK(test_fhss_compare_with_synch_parent_address());
}

TEST(fhss_common, test_fhss_use_broadcast_queue_cb)
{
CHECK(test_fhss_use_broadcast_queue_cb());
}

TEST(fhss_common, test_fhss_read_timestamp_cb)
{
CHECK(test_fhss_read_timestamp_cb());
}

TEST(fhss_common, test_fhss_init_callbacks_cb)
{
CHECK(test_fhss_init_callbacks_cb());
}

TEST(fhss_common, test_fhss_clear_active_event)
{
CHECK(test_fhss_clear_active_event());
}
15 changes: 15 additions & 0 deletions test/nanostack/unittest/service_libs/fhss_common/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2016 ARM. All rights reserved.
*/

#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(fhss_common);

Loading

0 comments on commit f973986

Please sign in to comment.