Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists