Raspberry Pi Pico unit testing

There is an simple project to understand how to run test for a project on RP2040-ETH board. Test file is very simple:

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

void tearDown(void) {}

int add(int a, int b)
{
    return a + b;
}

void test_calculator_addition(void) {
    TEST_ASSERT_EQUAL(32, add(25, 7));
}

void setup() {
    delay(2000);

    UNITY_BEGIN();
    RUN_TEST(test_calculator_addition);
    UNITY_END();
}

void loop() {
    delay(1000);
    Serial.println("Step");
}

If I try to run Test command, nothing happens


and there is a warning in verbose mode about diffrerent HWID than expected

image
It seems uploading works fine but there are no test results.

Am I doing something wrong?
ini file:

Can you test the exact code from https://github.com/maxgerhardt/platform-raspberrypi/issues/28#issuecomment-1533664099?

Thanks for idea!
It works if configuration is changed from board = pico
to board = rpipico.
Trying to understand what the difference is…

That’s weird…

board = pico
board_build.core = earlephilhower

should be equivalent to

board = rpipico

otherwise I’ve made a mistake. Need to double check.

Other RP Pico board with the same sympthoms.
W5500-EVB-Pico works fine but configuration:

[env:5500_evb_pico]
platform = raspberrypi
board = wiznet_5500_evb_pico
framework = arduino
test_framework = unity
test_build_src = yes

doesn’t run unit tests.
Verbose mode shows equal warning:


Current device has a different ID that system expects
image

Maybe there is some magic option to run tests in W5500-EVB-Pico case?

Then set monitor_port = COMxxx accordingly and possibly delay after upload so that the referenced COM port has time to appear.

Monitor port is set propertly and delay after after upload was added. But it doesn’t help

That does pio devices show after the test executable has been uploaded? (Or when a regular firmware that uses the USB serial is uploaded)

Still the same


code of extra_script.py

Import("env")

def after_upload(source, target, env):
    print("Delay while uploading...")
    import time
    time.sleep(5)
    print("Done!")

env.AddPostAction("upload", after_upload)

code of ini file

[env:5500_evb_pico]
platform = raspberrypi
board = wiznet_5500_evb_pico
framework = arduino
test_framework = unity
test_build_src = yes
extra_scripts = post:extra_script.py

new delay row inside tests

void setup()
{
    delay(5000);
    UNITY_BEGIN();
    RUN_TEST(test_something);
    UNITY_END();
}

After spending a lot of time finally I did it!
Extra script is not required, delay in setup() method is enough for W5500-EVB-Pico board


Playing with delay value I got: 5 seconds delay is a bit long, 3 seconds allows to run test. If decrease delay more, it doesn’t work

Does it not work with a more standard

// wait until computer has connected to USB serial
while(!Serial) {}

code instead of delay?

1 Like

Yes, it works as well, thanks