Skip to content

Commit f973986

Browse files
author
Jarkko Paso
committed
FHSS unit tests: Implemented FHSS common unit tests
1 parent 2188af4 commit f973986

File tree

7 files changed

+496
-5
lines changed

7 files changed

+496
-5
lines changed

source/Service_Libs/fhss/fhss_common.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static bool fhss_read_active_event(fhss_structure_t *fhss_structure, uint8_t eve
4242

4343
fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer)
4444
{
45-
if (fhss_struct) {
45+
if (fhss_struct || !fhss_api || !fhss_timer) {
4646
return NULL;
4747
}
4848
fhss_struct = ns_dyn_mem_alloc(sizeof(fhss_structure_t));
@@ -61,7 +61,7 @@ fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_
6161

6262
int8_t fhss_free_instance(fhss_api_t *fhss_api)
6363
{
64-
if (fhss_struct->fhss_api != fhss_api) {
64+
if (!fhss_struct || fhss_struct->fhss_api != fhss_api) {
6565
return -1;
6666
}
6767
ns_dyn_mem_free(fhss_struct);
@@ -80,7 +80,7 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
8080

8181
static fhss_structure_t *fhss_get_object_with_timer_id(const int8_t timer_id)
8282
{
83-
if (timer_id <0 || !fhss_struct) {
83+
if (timer_id < 0 || !fhss_struct) {
8484
return NULL;
8585
}
8686
if (fhss_struct->fhss_event_timer == timer_id) {
@@ -140,7 +140,6 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
140140
ns_dyn_mem_free(fhss_structure->bs);
141141
ns_dyn_mem_free(fhss_structure->ws);
142142
ns_dyn_mem_free(fhss_structure);
143-
fhss_structure = 0;
144143
fhss_struct = 0;
145144
return 0;
146145
}
@@ -189,7 +188,7 @@ int fhss_update_synch_parent_address(fhss_structure_t *fhss_structure)
189188

190189
void fhss_trig_event(fhss_structure_t *fhss_structure, uint8_t event_type)
191190
{
192-
if (fhss_read_active_event(fhss_structure, event_type) == true) {
191+
if (!fhss_structure || fhss_read_active_event(fhss_structure, event_type) == true) {
193192
return;
194193
}
195194
arm_event_s event;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
include ../../makefile_defines.txt
2+
3+
COMPONENT_NAME = fhss_common_unit
4+
5+
#This must be changed manually
6+
SRC_FILES = \
7+
../../../../../source/Service_Libs/fhss/fhss_common.c \
8+
9+
10+
TEST_SRC_FILES = \
11+
main.cpp \
12+
fhsscommontest.cpp \
13+
test_fhss_common.c \
14+
../../stub/mbed_trace_stub.c \
15+
../../stub/nsdynmemLIB_stub.c \
16+
../../stub/event_stub.c \
17+
../../stub/ns_timer_stub.c \
18+
../../stub/fhss_stub.c \
19+
../../stub/fhss_config_stub.c \
20+
../../stub/fhss_platform_stub.c \
21+
../../stub/fhss_callbacks_stub.c \
22+
23+
include ../../MakefileWorker.mk
24+
25+
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT
26+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2016 ARM. All rights reserved.
3+
*/
4+
#include "CppUTest/TestHarness.h"
5+
#include "test_fhss_common.h"
6+
7+
8+
TEST_GROUP(fhss_common)
9+
{
10+
void setup()
11+
{
12+
}
13+
14+
void teardown()
15+
{
16+
}
17+
};
18+
19+
TEST(fhss_common, test_fhss_allocate_instance)
20+
{
21+
CHECK(test_fhss_allocate_instance());
22+
}
23+
24+
TEST(fhss_common, test_fhss_free_instance)
25+
{
26+
CHECK(test_fhss_free_instance());
27+
}
28+
29+
TEST(fhss_common, test_fhss_set_datarate)
30+
{
31+
CHECK(test_fhss_set_datarate());
32+
}
33+
34+
TEST(fhss_common, test_fhss_get_object_with_api)
35+
{
36+
CHECK(test_fhss_get_object_with_api());
37+
}
38+
39+
TEST(fhss_common, test_fhss_disable)
40+
{
41+
CHECK(test_fhss_disable());
42+
}
43+
44+
TEST(fhss_common, test_fhss_start_timer)
45+
{
46+
CHECK(test_fhss_start_timer());
47+
}
48+
49+
TEST(fhss_common, test_fhss_timeout_start)
50+
{
51+
CHECK(test_fhss_timeout_start());
52+
}
53+
54+
TEST(fhss_common, test_fhss_timeout_stop)
55+
{
56+
CHECK(test_fhss_timeout_stop());
57+
}
58+
59+
TEST(fhss_common, test_fhss_update_synch_parent_address)
60+
{
61+
CHECK(test_fhss_update_synch_parent_address());
62+
}
63+
64+
TEST(fhss_common, test_fhss_trig_event)
65+
{
66+
CHECK(test_fhss_trig_event());
67+
}
68+
69+
TEST(fhss_common, test_fhss_compare_with_synch_parent_address)
70+
{
71+
CHECK(test_fhss_compare_with_synch_parent_address());
72+
}
73+
74+
TEST(fhss_common, test_fhss_use_broadcast_queue_cb)
75+
{
76+
CHECK(test_fhss_use_broadcast_queue_cb());
77+
}
78+
79+
TEST(fhss_common, test_fhss_read_timestamp_cb)
80+
{
81+
CHECK(test_fhss_read_timestamp_cb());
82+
}
83+
84+
TEST(fhss_common, test_fhss_init_callbacks_cb)
85+
{
86+
CHECK(test_fhss_init_callbacks_cb());
87+
}
88+
89+
TEST(fhss_common, test_fhss_clear_active_event)
90+
{
91+
CHECK(test_fhss_clear_active_event());
92+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2016 ARM. All rights reserved.
3+
*/
4+
5+
#include "CppUTest/CommandLineTestRunner.h"
6+
#include "CppUTest/TestPlugin.h"
7+
#include "CppUTest/TestRegistry.h"
8+
#include "CppUTestExt/MockSupportPlugin.h"
9+
int main(int ac, char** av)
10+
{
11+
return CommandLineTestRunner::RunAllTests(ac, av);
12+
}
13+
14+
IMPORT_TEST_GROUP(fhss_common);
15+

0 commit comments

Comments
 (0)