ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
684 stars 276 forks source link

Mocking FreeRTOS "task.h" failing due to attribute parsing #452

Open silabs-theophilel opened 1 year ago

silabs-theophilel commented 1 year ago

Hello,

I am trying to mock "task.h" using CMock (in a ceedling environment).

There is one problem I encountered wich is the following:

An internal FreeRTOS symbol is defined as :

    #define portDONT_DISCARD                   __attribute__( ( used ) )

And a function is declared as follows in "task.h" header file:

portDONT_DISCARD void vTaskSwitchContext(void) PRIVILEGED_FUNCTION;

When mocking in my unit test the header file with 'mock_' prefix:

//-- mocking necessary file for compilation
#include "mock_em_core.h"
#include "mock_sid_pal_log_ifc.h"
#include "mock_sid_pal_assert_ifc.h"
#include "mock_queue.h"
#include "mock_task.h".   <----- HERE

The generated Mock is looking like this, causing a compilation error:

                                                                    --> HERE missing argument
void vTaskSwitchContext_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, )void cmock_to_return);

The message error:

In file included from build/test/runners/test_swi_runner.c:11:
build/test/mocks/mock_task.h:901:74: error: expected parameter declarator
void vTaskSwitchContext_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, )void cmock_to_return);
mvandervoord commented 8 months ago

If you add portDONT_DISCARD to your :strippables list, I believe this problem will go away.