Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Unit test tasks: how to access static functions

Posted 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:

  1. 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(); } }

  1. 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 functions

Posted 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 functions

Posted 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner