Ceedling failing to mock header

928 views Asked by At

I am trying to mock a header which is included by a source file I am testing.

The header begins with the following:

#if defined(ICM42600)
#define ICM_WHOAMI ICM42600_WHOAMI
#elif defined(ICM42602)
#define ICM_WHOAMI ICM42602_WHOAMI
#elif defined(ICM42605)
#define ICM_WHOAMI ICM42605_WHOAMI
#elif defined(ICM42622)
#define ICM_WHOAMI ICM42622_WHOAMI
#elif defined(ICM42686)
#define ICM_WHOAMI ICM42686_WHOAMI
#elif defined(ICM42688)
#define ICM_WHOAMI ICM42688_WHOAMI
#elif defined(ICM42608)
#define ICM_WHOAMI ICM42608_WHOAMI
#elif defined(IIM42623)
#define ICM_WHOAMI IIM42623_WHOAMI
#elif defined(IIM42624)
#define ICM_WHOAMI IIM42624_WHOAMI
#elif defined(IIM42625)
#define ICM_WHOAMI IIM42625_WHOAMI
#elif defined(ICM40608)
#define ICM_WHOAMI ICM40608_WHOAMI
#else
#error "Please define which ICM variant is targeted. Possible values: ICM42600, ICM42602, ICM42605, ICM42686, ICM42688, ICM42622, ICM42608, ICM4068"
#endif

and I am attempting to mock it like so:

#define ICM42600 1
#include "mock_Icm426xxDefs.h"

However, I keep getting the following error when trying to run ceedling tests:

----------------------------
Generating include list for Icm426xxDefs.h...
build/temp/_Icm426xxDefs.h:74:2: error: #error "Please define which ICM variant is targeted. Possible values: ICM42600, ICM42602, ICM42605, ICM42686, ICM42688, ICM42622, ICM42608, ICM4068"
 #error "Please define which ICM variant is targeted. Possible values: ICM42600, ICM42602, ICM42605, ICM42686, ICM42688, ICM42622, ICM42608, ICM4068"
  ^~~~~

I have no idea how to deal with this. I was under the impression that ceedling would automatically mock headers, and there's no error saying what I can do to resolve this.

2

There are 2 answers

0
user3629249 On

The output of the #error message means that none of the (other) definitions of ICM_WHOAMI was used.

Why the #define before the #include was not seen would require other info that you have not provided

0
Ray On

I had also problems with defines that were not passed to included files. Try to pass the define with option -D directly to the compiler and linker by adding them to the project.yml:

:flags: :test: :compile: :: - -D ICM42600 :link: :: - -D ICM42600