Is it possible to use espidf with the native platform when running tests?
I’m creating some tests with test_build_src = yes and would like to test code using data types from esp-idf (like esp_err_t). Currently, I can only get tests to work on the embedded device. If I try running it natively, I get a compilation error:
1 | #include <esp_log.h>
| ^~~~~~~~~~~
compilation terminated.
*** [.pio/build/native/src/ui/led.o] Error 1
src/ui/button.c:1:10: fatal error: esp_log.h: No such file or directory
I’ve also tried adding framework = espidf to my platformio.ini, but this would require me to include a board too.
This is probably an architecture question. We have our code split so that as much as possible is “core” and doesn’t call any microprocessor-specific code at all. Instead, it uses interfaces to adapters which are in a separate lib to interact with the processor.
The core code can be tested natively, and you pass in a fake whenever the core code accesses an adapter.
Obviously the processor-specific code must be tested on-chip, but that’s surprisingly little.
Doing this makes testing of core code lovely and easy - you can pass-on fakes that do whatever you want to simulate. And they’re much quicker of course (though unity remains slow compared to most unit-test frameworks).