Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Cmock Ignoring #if

33 views
Skip to first unread message

Wilmer Suarez

unread,
May 3, 2024, 10:18:33 PM5/3/24
to ThrowTheSwitch Forums
Hello,

I have the following code in a header file:
 
...

#if ( STATIC_ALLOCATION == 1)
typedef struct xSTATIC_RINGBUFFER {
size_t xDummy1[2];
UBaseType_t uxDummy2;
BaseType_t xDummy3;
void *pvDummy4[11];
StaticSemaphore_t xDummy5[2];
portMUX_TYPE muxDummy;
} StaticRingbuffer_t;
#endif

...

#if ( STATIC_ALLOCATION == 1)
RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize,
RingbufferType_t xBufferType,
uint8_t *pucRingbufferStorage,
StaticRingbuffer_t *pxStaticRingbuffer);
#endif

...

No matter if STATIC_ALLOCTION is set 0 or 1, when mocked, StaticRingbuffer_t is ignored (resulting in 'unknown type name' errors) but cmake generates functions for xRingbufferCreateStatic. Why's CMock ignoring the condition for the function declaration but not for the struct? Am I misunderstanding something here?


Mark Vander Voord

unread,
May 4, 2024, 10:54:43 PM5/4/24
to throwth...@googlegroups.com
Hi.

CMock doesn't contain a full C parser. You can run your files through a C preprocessor before feeding them to Ceedling, which will fix issues like the one you're seeing. This is an option with using Ceedling builds. It can also be done with other make systems by adding another intermediate step.

In the long run, we'd like to support full parsing in CMock, but it doesn't do this at this time.

Mark

--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/7e1facb5-e900-4f22-aa39-3463b928b828n%40googlegroups.com.

Wilmer Suarez

unread,
Sep 6, 2024, 9:10:42 AM9/6/24
to ThrowTheSwitch Forums
I'm using ESP-IDF's CMock integration. Any guidance on how that can be done in that environment?

Mike Karlesky

unread,
Sep 18, 2024, 11:53:54 AM9/18/24
to throwth...@googlegroups.com

The only option is to set up some kind of build step that runs your header files through something like gcc's preprocessor mode. This works well but does take some rigging to get right. CMock is only capable of plain text parsing of header files, not C parsing. The Ceedling tool can do this for you as well as run mocking, but it probably does not integrate into the ESP-IDF in the same way that CMock does.

Reply all
Reply to author
Forward
0 new messages