compile error on `#include "ArduinoFake.h"`

66 views
Skip to first unread message

Allan Gray

unread,
Dec 14, 2023, 5:22:56 AM12/14/23
to cpputest
Greetings,

I had a go at integrating ArduinoFake into a cpputest project and hit an error that I've mentioned here:

I created the following minimal example here:

I expect to be working with some engineering students in the coming months, so if possible, I'd like to get this repo to a workable example/reference repo that I can use to nudge them towards the testing discipline.

Unless there is already a good reference repo to refer arduino users to? Or maybe an alternative Arduino mock library that integrates better with cpputest?

Cheers

James W Grenning

unread,
Dec 18, 2023, 4:49:30 AM12/18/23
to 'Allan Gray' via cpputest

After a quick look, you should look at this (I could be wrong, but the thing to try is easy)

https://cpputest.github.io/manual.html#conflicts-with-operator-new-macros-stl

CppUTest forces an include file for memory leak detection that can sometime cause preprocessor errors. That link shows you what to do about it.

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/5a53509b-4599-4e5f-8872-b56410ce84dbn%40googlegroups.com.


Allan Gray

unread,
Jan 13, 2024, 6:01:17 AMJan 13
to cpputest
Your message ended up in my spam so just saw it now. At any rate, happy new year!

I was able to arrive at a minimum reproducible example here: https://github.com/graial/ArduinoFake-cpputest

It fails regardless of which #include comes first.  So I guess that means it's a problem within arduinofake

I also opened an issue here. So far his initial suggestion didn't help https://github.com/FabioBatSilva/ArduinoFake/issues/56

In his examples, he's relying on platformio for the build details, which uses unity by default

Not sure if you have any other suggestions.

cheers

Allan Gray

unread,
Jan 13, 2024, 6:01:17 AMJan 13
to cpputest
Oops, these messages ended up in my spam.  Happy new year anyway!

As per my last message on the issue:  https://github.com/cpputest/cpputest/issues/1768
I ended up creating a minimally reproducible example here.
https://github.com/graial/ArduinoFake-cpputest

I hit the same error regardless of which include statement comes first.  So  I guess that means it is somehow a problem with #include ArduinoFake 

I had opened an issue there as well but so far, no success with his initial suggestion. https://github.com/FabioBatSilva/ArduinoFake/issues/56

Not sure if you have any other suggestions.  His examples offload build details to platformio, which defaults to unity.

Cheers

On Monday, December 18, 2023 at 5:49:30 PM UTC+8 James Grenning wrote:

Allan Gray

unread,
Feb 14, 2024, 8:30:53 PMFeb 14
to cpputest
Good morning, just following up on this.

I was hoping that someone from cpputest would have at least confirmed or denied if they encountered the same error on the minimum reproducible example i posted.

From what I can tell, the above issue was caused by a discrepancy between compiler settings.  the cpputest makefile is very complicated and as far as i know, it's not possible to write tests for make or cmake.

James W Grenning

unread,
Feb 14, 2024, 8:45:15 PMFeb 14
to 'Allan Gray' via cpputest

Hi Allan

Did your make your own forced include file?

I am not a Make person.

Your cmake would need to add this gcc build command line option

-include ./MyMemoryLeakDetectorNewMacrosFile.h

The MyMemoryLeakDetectorNewMacrosFile.h file contents should look like this, given that ArduinoFake.h contains #include <unordered_map>

#ifndef MY_MEMORY_LEAK_DETECOTOR_NEW_MACROS_FILE_INCLUDED
#define MY_MEMORY_LEAK_DETECOTOR_NEW_MACROS_FILE_INCLUDED

#include <unordered_map>
#include "CppUTest/MemoryLeakDetectorNewMacros.h"

#endif

Allan Gray

unread,
Feb 20, 2024, 10:34:31 AMFeb 20
to cpputest
Hi James,

No luck yet.  I've updated my example repo to include the custom macro file as per your suggestion.   I get exactly the same error when including <unordered_map>  before MemoryLeakDetectorNewMacros.h

Another thing I've noticed, the FakeIt header file "fakeit.hpp" also includes unordered_set.  I also hit the same error if I include it.

FakeIt's docs have special builds for a number of test runners.

right now im using the standalone config via:
target_link_libraries(first_test PRIVATE
    .
    .
    FakeIt-standalone
)

Have you used CppUTest with FakeIt at all?  Do you think they can be integrated easily or would this require a bunch of extra integration effort?

Thanks and take care,

James W Grenning

unread,
Feb 20, 2024, 1:08:27 PMFeb 20
to 'Allan Gray' via cpputest

Hi Allan

I forget... Are you having a build problem or a run problem?

BTW: I've experimented with FakeIt but gave it up as the single header file solution for my uses deploying programming exercises on cyber-dojo.org. Compilation time made it impractical for me.

Allan Gray

unread,
Feb 20, 2024, 8:03:55 PMFeb 20
to cpputest
It's a compile error.  the code is here
https://github.com/graial/ArduinoFake-cpputest
hopefully the readme would allow you to reproduce what I'm seeing with just a couple CLI commands

I'm using the same compiler settings that the ArduinoFake repo does.

I can imagine that there are probably better & more efficient ways of stubbing out arduino system calls than a fakeit/mock.  But this appears (to me) to be the most mature mock in the Arduino ecosystem right now.

So it'd be super useful to be able to spin up a quick example of using CppUTest on an arduino sketch/codebase.

Allan Gray

unread,
Mar 9, 2024, 11:39:46 PMMar 9
to cpputest
Good afternoon,

Following up on this again.  Am I asking too much in requesting somebody else try to build the 'minimally reproducible example' I posted?

Thanks and take care,
Allan

James W Grenning

unread,
Mar 10, 2024, 9:04:30 AMMar 10
to 'Allan Gray' via cpputest

Hi Allan

It builds for me on a Mac. Just like the directions. But it does include any Arduino or FakeIt dependencies in MyFirstTest.cpp

Is that what you are looking for?

HTH James

Ryan Hartlage

unread,
Mar 10, 2024, 9:06:39 AMMar 10
to cppu...@googlegroups.com
Hi Allan,

I created a PR with an explanation of the issue and a fix:

Thanks,
Ryan

Allan Gray

unread,
Mar 12, 2024, 6:55:53 AMMar 12
to cpputest
Hi Ryan,

Confirmed! this worked for me!

I had been trying to follow the instructions you referenced above.  This was my first time seeing the target_compile_options() function.  Even after reading the manual page, I can't say that I understand very well what it does.  But it did work!

Glad to finally have a working implementation to work with and show to some of the early career engineers around here.

Many thanks for that!
Reply all
Reply to author
Forward
0 new messages