I am building software for the arduino platform, but want to run the tests using the native platform and ArduinoFake. This works, except that all the Arduino libraries specify
platforms="arduino" in the library.json, which means the libraries can’t be used on the “native” platform? I am using for instance ArduinoJson, DallasTemperature, etc. I understand that if it really depends on hardware, for instance because of SPI or stuff, it won’t work on the native platform. I don’t mind having to create Mock versions in that case (if ArduinoFake doesn’t provide them). But making Mock versions of every library seems a bit of a waste of time. Am I doing something wrong here?
Basically the error I run into when running
pio run -e native is
fatal error: ArduinoJson.h: No such file or directory
and similar for DallasTemperature.h and others. The libaries are located in .pio/libdeps/native (after running
pio lib install ArduinoJson. Also, if I run
pio run -t idedata -d . it doesn’t list the libraries in the ‘includes’ list for the native environment, but it does list them for the other environments.
This is the native environment of my platform.ini:
platform = native
test_ignore = test_embedded
build_flags = -g
You should be able to add
lib_compat_mode = off to that
platformio.ini to make it so the LDF doesn’t do any compatibility checks… as the default
soft mode still does the
framework = arduino check.
I think I am getting closer. I added
lib_compat_mode = off to my platformio.ini “native” environment, which makes sure that libraries that compatibility check for frameworks isn’t done. So all libraries are included, irrespective of platform or framework. I made sure at the top of
src/main.h (for NATIVE devices) I first
#include <MockLib.h> which in turn
#include <ArduinoFake.json>. So that way I think it should first include ArduinoFake and all it’s stuff, and I can add additional stuff in MockLib.
This works except for one issue: I see that ArduinoFake does include the
avr/interrupt.h. But in my source I also
#include <avr/interrupt.h> but during compiling, I get the error
fatal error: avr/interrupt.h: No such file or directory
This is the building output:
Building in release mode
In file included from .pio/libdeps/native/OneWire_ID1/OneWire.cpp:144:
.pio/libdeps/native/OneWire_ID1/util/OneWire_direct_gpio.h:416:2: warning: #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture." [-Wcpp]
416 | #warning "OneWire. Fallback mode. Using API calls for pinMode,digitalRead and digitalWrite. Operation of this library is not guaranteed on this architecture."
In file included from lib/mylib/src/mylib.cpp:17:
lib/mylib/src/mylib.h:5:10: fatal error: avr/interrupt.h: No such file or directory
The issue I had here is that ArduinoFake has these files in
arduino/avr/interrup.h. The easy way for me to fix it is make my own ‘avr/interrupt.h’ in my MockLib library and in there just
#include arduino/avr/interrupt.h, effectively creating an alias.