Build multiple source for Arduino MCU and native for testing

Currently I work on a project that runs on an ESP32 with the Arduino framework. Next to the main sources, I have have some tools for validating components, sensors and actuators that also run on ESP32. I want to add unit tests using ‘native’ for some algorithms that don’t directly interface to the hardware.

This is where it gets interesting. I can run the tools using pio run -e i2c_scan for the ESP32 using the ‘build_source_filter’ and the extends keyword.
But if I want to run the tests, I still need to do pio test -e native

Is it possible to let pio test to only run the ‘native’ environment?
What would be the best way to split the tests into native ones and those that run inline on the ESP32?

My platformio.ini file looks like this:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = house2

[esp32]
platform = espressif32
board = nodemcu-32s
framework = arduino
upload_port = /dev/ttyUSB0
monitor_speed = 115200
monitor_port = /dev/ttyUSB0
lib_deps = 
    budryerson/TFLI2C@^0.2.0
    adafruit/Adafruit PWM Servo Driver Library@^2.4.1
    robtillaart/MCP23017@^0.2.6
    sparkfun/SparkFun VL53L1X 4m Laser Distance Sensor@^1.2.11

[env:house2]
extends = esp32

[env:native]
platform = native
build_flags = 
    -D UNITY_INT_WIDTH=32

[env:io_extender]
extends = esp32
build_src_filter = +<../tools/io_extender/io_extender.cpp>

[env:i2c_scan]
extends = esp32
build_src_filter = +<../tools/i2c_scan/i2c_scan.cpp>

[env:luna_config]
extends = esp32
build_src_filter = +<../tools/luna_config/luna_config.cpp>

[env:servoshield]
extends = esp32
build_src_filter = +<../tools/servoshield/servoshield.cpp>

[env:i2c_distance]
extends = esp32
build_src_filter =  +<../tools/i2c_distance/i2c_distance.cpp>

[env:luna_array]
extends = esp32
build_src_filter =  +<../tools/luna_array/luna_array.cpp>

[env:status_leds]
extends = esp32
build_src_filter =  +<../tools/status_leds/status_leds.cpp>

Full project is here:

If you have the latest core version (pio upgrade), it works just like the offiicial documentation says.

>pio test --help
Usage: pio test [OPTIONS]

Options:
  -e, --environment TEXT
  -f, --filter PATTERN         Filter tests by a pattern
  -i, --ignore PATTERN         Ignore tests by a pattern
[...]

So just pio test -e native.

2 Likes

If that’s what it takes, then I will stick with it.