FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [July 2016 Threads] Unit test tasks: how to access static functionsPosted by flntobi on July 15, 2016 Hi
In order to program with the Test Driven Development (TDD) paradigm it is essential to unit test all modules. I use the simple unit test environment Unity. The idea of unit testing is to test all public functions. Static (i.e. private) functions are indirectly tested.
There are two problems with unit testing FreeRTOS code:
- Stubs (test environment) need to be created to mimic the FreeRTOS queue behaviour. I solved this by dividing the run function into two functions and calling them with the testinput for the queues:
:::c
static void run(void parameters)
{
runInit();
for(;;)
{
/ encapsulated in extra function to allow unit testing */
runMain();
}
}
- The problem with the FreeRTOS architecture is that the tasks are based on static functions (the run function). I solved this by using the preprocessor define "-Dstatic=", which removes the keyword static from the code. This is not an elegant way because 1. the unittest is not run on the orignal code and 2. the static variables inside the functions become non static.
Does anyone know a better solution to this problem?
Thanks in advance of any help
Unit test tasks: how to access static functionsPosted by rtel on July 15, 2016 If you look at the bottom of tasks.c you will see the following code:
#ifdef FREERTOS_MODULE_TEST
#include "tasks_test_access_functions.h"
#endif
The header file is something you have to provide yourself, but allows
you to insert code into the source file that gives you access to all the
static functions and data the file contains. I don't think there are
equivalents in the other source files (?) but you could use the same
technique.
Unit test tasks: how to access static functionsPosted by richard_damon on July 15, 2016 FreeRTOS does NOT requrie tasks functions to be 'static', but can be global, letting you build a seperate test file that calls the task. You also can add a stub function that isn't static that calls the task (and perhaps is only present when compiling for test).
My normal procedure is I do NOT make my task functions static, but also do not put an extern definition for them in a header file, so other files can't accidently call it. This allows a test procedure to make the call as needed.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|