Unit test C with keywords for the compiler

I am writing unit tests for some embedded C that run on the host machine (not yet tested on the target computer) and compiled using GCC. I am using Ceedling build system with Unity testing base for testing.

One of the files I would like to test includes a file (say ah), which includes another file (say cpu.h), which is part of the board support package from the vendor of embedded devices, and uses keywords specific for (e.g. __cregister, e.g., c extern __cregister volatile unsigned int IER;.

Another problem, again with such a file included in the BSP, is the built-in assemblies asm(), for example, in #define FOO_ASM asm("FOO").

They, of course, cause an error in the construction of tests, because GCC does not recognize these keywords.

I thought I could prevent these BSP headers from being added when Ceedling generates a layout by adding #include "mock_a.h"to my test file, but GCC still compiles ah and therefore bh

Is there a better way to solve such problems?

I could add something like the following to the BSP file, but I do not want to change the code of the provider that will change or rewrite my changes with the new version, I would better understand how to properly isolate the device.

// Unknown how __cregister is initially defined
#ifdef TEST
    #undef __cregister // Redefine __cregister to nothing
    #define __cregister
#endif

extern __cregister volatile unsigned int IER;
+2
source share
1 answer

I eventually completed the method described in my comment on the OP.

So, for an example from my original post

/* foo.h */
extern __cregister volatile unsigned int IER;
#define FOO_BAR_ASM asm("BAR");

test/support/ include BSP :

/*foo.h - in test/support */
extern volatile unsigned int IER;
#define FOO_BAR_ASM

include, #include "mock_foo.h" .

+1

Source: https://habr.com/ru/post/1669032/


All Articles