VSS Build vs Test issue

I’m creating a project for the ESP32 using the ESP-IDF framework in Visual Studio Code on MacOS.

I have some common code defined under lib which I include in my unit tests

lib
├── id_list
│   ├── id_list.c
│   └── id_list.h
└── str_util
    ├── str_util.c
    └── str_util.h

The tests are in tests/

test
└── test_desktop
    ├── test_all.c
    ├── test_id_list.c
    ├── test_id_list.h
    ├── test_str_util.c
    └── test_str_util.h

My platform.ini is defined as follows:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = espidf
monitor_speed = 115200
build_flags = -DCORE_DEBUG_LEVEL=1
test_ignore = test_desktop

[env:native]
platform = native

If I try to build the app using the Build icon at the bottom of the VSS window, it tries to build both my app and run the unit tests. This would be fine except for the fact that the src directory is not configured correctly for the tests and so it ends up including src/** files which I don’t want as it then complains with errors like

src/main.c:1:10: fatal error: 'freertos/FreeRTOS.h' file not found
#include "freertos/FreeRTOS.h"

If I manually build the app (without the tests)

$pio run -e esp32doit-devkit-v1
Processing esp32doit-devkit-v1 (platform: espressif32; board: esp32doit-devkit-v1; framework: espidf)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 1.12.4 > DOIT ESP32 DEVKIT V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf 3.40001.200521 (4.0.1) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.20600.0 (2.6.0) 
 - tool-ninja 1.9.0 
 - toolchain-esp32ulp 1.22851.190618 (2.28.51) 
 - toolchain-xtensa32 2.80200.200226 (8.2.0)
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 2 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <id_list>
|-- <str_util>
Building in release mode
Retrieving maximum program size .pio/build/esp32doit-devkit-v1/firmware.elf
Checking size .pio/build/esp32doit-devkit-v1/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.1% (used 39508 bytes from 327680 bytes)
Flash: [======    ]  62.9% (used 659578 bytes from 1048576 bytes)
================================================================== [SUCCESS] Took 9.94 seconds ==================================================================

Environment          Status    Duration
-------------------  --------  ------------
esp32doit-devkit-v1  SUCCESS   00:00:09.940
native               IGNORED
================================================================== 1 succeeded in 00:00:09.940 ==================================================================

It correctly ignores the Test folder.

If I then run the tests manually or using the test icon at the bottom of the VSC window, it correctly ignores the src folder because of the test_ignore = test_desktop directive in plaformio.ini

$ pio test
Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing test_desktop in native environment
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Testing...
test/test_desktop/test_all.c:75:test_initialise_list    [PASSED]
test/test_desktop/test_all.c:76:test_add_items_to_list  [PASSED]
test/test_desktop/test_all.c:77:test_add_items_list_extension   [PASSED]
test/test_desktop/test_all.c:78:test_parse_strings_to_ids       [PASSED]
test/test_desktop/test_all.c:9:test_starts_with [PASSED]

-----------------------
5 Tests 0 Failures 0 Ignored
OK
=================================================================== [PASSED] Took 1.74 seconds ===================================================================

Test          Environment          Status    Duration
------------  -------------------  --------  ------------
test_desktop  esp32doit-devkit-v1  IGNORED
test_desktop  native               PASSED    00:00:01.740
================================================================== 1 succeeded in 00:00:01.740 ==================================================================

Is there a way that I can configure the Build icon only to build the app and not to build the tests?

I think what I need is the ability to control the source files used to build each environment rather than relying on Platformio to try and do the right thing?

There are src_filter (docs) and other test options like test_build_project_src (docs) which you might want to have a look at.

Thanks @maxgerhardt. I did read the docs and try a few things out but without much success.

I’ll try again and report back if/when I have a better solution.

1 Like

To control which environments are built when you hit the Build (All) button… have a look at default_envs.

Thanks for the tip. I added this at the start of my platformio.ini file and it now targets just the ESP32 codebase

[platformio]
default_envs = esp32doit-devkit-v1
...

I now see the other environment ignored which is exactly what I wanted.

Environment          Status    Duration
-------------------  --------  ------------
esp32doit-devkit-v1  SUCCESS   00:02:02.075
native               IGNORED

Thanks

1 Like