Knowing from other languages and platforms we want to use Unit-Testing during the Build-Process BEFORE the code is flashed to the hardware. This should be possible for simple functions tests which have no need for the ESP32 hardware.
But as we understand yet the C++ code is compiled (and linked) for the ESP32 chip and shall not run on the developing system or in a CI/CD pipeline.
Is there any way to emulate ESP32 (for C++) or run Unit-Tests on any other way on another systems?
note: We are using 'platformio' for the build.
It is possible to do this with the qemu_esp32 emulator. You can compile your test runner and run it directly on the emulator instead of flashing it to a real esp32 chip.
Here is an example of how to do this (adapted from esp32_qemu_unity_test_action):
idf.py build
cd build
esptool.py --chip esp32 merge_bin --fill-flash-size 4MB -o flash_image.bin @flash_args
/opt/qemu/bin/qemu-system-xtensa -nographic -no-reboot -machine esp32 -drive file=flash_image.bin,if=mtd,format=raw -serial file:output.log
By specifying -no-reboot
, the emulator will simply exit instead of rebooting.