Embedded unit testing on esp32 not working?

Hello,

I’ve started looking into unit testing. I created a new file test.test_embedded/test_main.cpp. Here’s its content:

#include <Arduino.h>
#include "unity.h"

void test_blank(){
    int i = 5;
    TEST_ASSERT_EQUAL(i, 5);
}

// setup connects serial, runs test cases (upcoming)
void setup() {
  delay(2000);

  //
  UNITY_BEGIN();

  // calls to tests will go here
  RUN_TEST(test_blank);

  UNITY_END();
}

void loop() {
  // nothing to be done here.
}

Here’s my platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
board_build.partitions = partition_table.csv
test_ignore = test_desktop

[env:native]
platform = native
test_ignore = test_embedded

And here’s the output I get when running the test:

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

Processing test_embedded in esp32dev environment
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Uploading...
Connecting....
Writing at 0x00001000... (100 %)
Wrote 16848 bytes (10928 compressed) at 0x00001000 in 0.1 seconds (effective 1075.0 kbit/s)...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 7996.8 kbit/s)...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 35894.2 kbit/s)...
Writing at 0x00010000... (14 %)
Writing at 0x00020000... (71 %)
Wrote 205216 bytes (102652 compressed) at 0x00010000 in 1.6 seconds (effective 1009.2 kbit/s)...
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

ets Jun  8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6412
entry 0x400806a8

Nothing happens after that, even after a few minutes. Pressing RST on my ESP32 adds the following lines to the output:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6412
entry 0x400806a8

Once again, nothing happens after that.
I’m new to Platformio, I’ve looked into the tutorials on Unit Testing, and it seems that this should provide a vastly different output.
Could you please explain to me what I’m doing wrong?

I moved on to something else, and think I accidentally found the issue. Here’s my partition table:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
factory,  app,  factory,   0x10000, 0x140000,
app0,     app,  ota_0,   0x150000,0x140000,
eeprom,   data, 0x99,    0x290000,0x1000,
spiffs,   data, spiffs,  0x291000,0x16F000,

“factory” contains the factory loaded firmware, “app0” the latest one (downloaded from a web server).
The issue: When uploading the firmware through Serial, the firmware is written to factory, but for some reason, the boot flag is set to the app0 partition.
That’s why the test doesn’t work: the test firmware is not the one booting. I used “Erase Flash” and ran the test again to confirm this theory:

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

Processing test_esp32 in esp32dev environment
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
lib/Commons/Commons.cpp: In function 'void printPartitionTable()':
lib/Commons/Commons.cpp:83:70: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
       } while (_mypartiterator = (esp_partition_next(_mypartiterator)));
                                                                      ^
lib/Commons/Commons.cpp:92:68: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     } while (_mypartiterator = (esp_partition_next(_mypartiterator)));
                                                                    ^
Uploading...
Connecting....
Writing at 0x00001000... (100 %)
Wrote 16848 bytes (10928 compressed) at 0x00001000 in 0.1 seconds (effective 1042.9 kbit/s)...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.0 seconds (effective 8409.1 kbit/s)...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 32198.4 kbit/s)...
Writing at 0x00010000... (14 %)
Writing at 0x00020000... (71 %)
Wrote 205216 bytes (102648 compressed) at 0x00010000 in 1.6 seconds (effective 1009.6 kbit/s)...
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

ets Jun  8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6412
entry 0x400806a8
test/test_esp32/test_main.cpp:17:test_blank     [PASSED]
-----------------------
1 Tests 0 Failures 0 Ignored
================================================================================= [PASSED] Took 12.92 seconds =================================================================================

Test        Environment    Status    Duration
----------  -------------  --------  ------------
test_esp32  esp32dev       PASSED    00:00:12.925
================================================================================= 1 succeeded in 00:00:12.925 =================================================================================

New question: Do any of you know how to ensure the boot flag is properly set when we load the firmware through Serial ? (I use platformio + VSCode).

1 Like