PlatformIO unit testing does not output only on my computer only for some ESP32 boards

I’m having a very odd issue with PlatformIO’s unit testing using the VSCode extension for PlatformIO. I am trying to run unit testing on an ESP32. Whenever I try to use pio test to run any unit tests, it with freeze when waiting for output:

C:\Git\esp32-project>pio test -f test_test
Verbose mode can be enabled via `-v, --verbose` option
Collected 9 items

Processing test_test in esp32dev environment
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Building...
Uploading...
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

At this point I am unable to cancel the testing using Ctrl+C. The only way to kill it is to close the PlatformIO CLI terminal altogether.

Things I have tried:

  • Wait 10 seconds: Problem persists
  • Power cycle the ESP32: Problem persists
  • Add a delay of 10 seconds before starting the tests: Problem persists
  • Change the monitor_speed from 115200 to 9600: Problem persists
  • Upload the test, then connect via the Serial Monitor: I see the output I would expect (although it isn’t colored). This is not a solution because I can’t run a series of tests in an automated fashion.
  • Update PlatformIO to the dev build: Problem persists
  • Uninstalling and reinstalling PlatformIO: Problem persists

Other observations

  • This problem only exists on some of the ESP32 boards I have. I have at least one ESP32 board that can run unit tests just fine. However, it doesn’t work on the board I need it to work on.
  • On the problematic boards, the problem persists across multiple PlatformIO projects with different platformio.ini files.
  • I’ve had two other people try to run the same unit tests on the problematic boards, and the unit tests DID work for them.

That last point is the most confusing for me. Why would it work on someone else’s computer but not mine? Does anyone have any ideas how I could remedy this issue?

  1. Try fixing test_port to the right port
  2. Try all 4 combinations [ (0,0), (0,1), (1,0), (1,1) ] of monitor_rts and monitor_dts settings.

Specifying the test_port worked for me, but I also had to add a delay of 2 seconds before starting the test. Any idea why test_port and the delay would be necessary for my computer but no anyone else’s computer?

Do you have any delay() in the test before running them before? The firmware might be pushing out the data too quickly.

I do have some delay now. But the unit testing worked without delay on two other people’s computers.

You should have a minimal delay in there, since the time between the end of the flash procedure (by esptool.py) and the start of serial monitor is not 0. The RX buffers of your serial adapter (in e.g. the driver or in hardware) might save you there sometimes, but if not, it’s up to the PC’s speed (and Windows being benevolent to you and not delaying stuff too much).

There is also the slight possibility that after uploading the code (and the ESP32 starts up its WiFi), the USB-serial adapter is ejected from the USB bus due to some temporary current overload. You can check in the device manager whether the COM port stays there all the time during the procedure.

Otherwise, ¯_(ツ)_/¯, magic.

Alright. Thanks so much for the help!