I'm trying to implement unit tests in Unity (Learn more about Unity) with a little help of CMock (Learn more about CMock). To do that I use the Ceedling tool which combines all Unity components into a one framework (Learn more about Ceedling).
Everything works as expect until I add FreeRTOS to my project/testing. When added, Ceedling struggles to generate mocks for FreeRTOS components, like queue.c or list.c. It gives following error:
Generating include list for queue.h...
build/temp/_queue.h:32:6: error: #error "include FreeRTOS.h" must appear in source files before "include queue.h"
32 | #error "include FreeRTOS.h" must appear in source files before "include queue.h"
| ^~~~~
In file included from build/temp/_queue.h:40:
../build/_deps/rtos.freertos-src/include/task.h:32:6: error: #error "include FreeRTOS.h must appear in source files before include task.h"
32 | #error "include FreeRTOS.h must appear in source files before include task.h"
| ^~~~~
In file included from ../build/_deps/rtos.freertos-src/include/task.h:35,
from build/temp/_queue.h:40:
../build/_deps/rtos.freertos-src/include/list.h:60:6: error: #error "FreeRTOS.h must be included before list.h"
60 | #error "FreeRTOS.h must be included before list.h"
| ^~~~~
For me, it looks like compiles queue.c file to find out list of functions which then should be mocked. That's ok but I don't know to force it to add FreeRTOS.h include while it cheks queue.c or list.c files.
I modified my project.yml file so paths to FreeRTOS are added and also FreeRTOS.h header is added to includes:
:paths:
:test:
- +:test/**
- -:test/support
- ../
- ../build/_deps/rtos.freertos-src/portable/GCC/ARM_CM4F
- ../build/_deps/rtos.freertos-src/include
- ../debug/
:source:
- src/**
- ../build/_deps/rtos.freertos-src/portable/GCC/ARM_CM4F/**
- ../build/_deps/rtos.freertos-src/include/**
- ../build/_deps/rtos.freertos-src/**
:support:
- test/support
:libraries: []
... skipped lines ...
... skipped lines ...
... skipped lines ...
:cmock:
:mock_prefix: mock_
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
:plugins:
- :ignore
- :callback
:treat_as:
uint8: HEX8
uint16: HEX16
uint32: UINT32
int8: INT8
bool: UINT8
:includes_h_pre_orig_header:
- FreeRTOS.h
:includes_c_pre_header:
- FreeRTOS.h
:includes:
- ../debug/assert.h
- FreeRTOS.h
Even with added includes_h_pre_orig_header, includes_c_pre_header and includes it still fails like FreeRTOS.h. is not added before queue.h nor list.h headers.
I've found similar problem, the resolution there was to add Init and Verify calls to SetUp and Teardown methods in the test script and also to add Expect for calls related to FreeRTOS. I tried that without luck.
My test script is simple:
#include "unity.h"
#include "cmock.h"
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "mock_queue.h"
#include "test.h"
void setUp(void) {
mock_queue_Init();
mock_list_Init();
mock_task_Init();
}
void tearDown(void) {
mock_queue_Verify();
mock_list_Verify();
mock_task_Verify();
}
void test_Rtos(void)
{
xQueueCreate_Expect(8, 16);
TestRtos();
}
The source file is also simple, just created to check if Ceedling will work with FreeRTOS:
#include "test.h"
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "queue.h"
void TestRtos(void)
{
QueueHandle_t someQueue = xQueueCreate(8, 16);
uxQueueMessagesWaiting(someQueue);
}
I also looked at some examples from Amazon but their project.yml doesn't even mention some paths or header files related to FreeRTOS. What I missed here?