Skip to content

Platformio unit test runs the same test case twice #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lightway29 opened this issue Oct 30, 2023 · 10 comments
Open

Platformio unit test runs the same test case twice #32

lightway29 opened this issue Oct 30, 2023 · 10 comments

Comments

@lightway29
Copy link

lightway29 commented Oct 30, 2023

Trying to run a sample test case for mbed framework. Got everything working but running into an issue where the same test case runs twice and one fails and one passes.

https://community.platformio.org/t/platformio-unit-test-runs-the-same-test-case-twice/36404/3

Screenshot 2023-10-26 at 17 05 02

platformio.ini

[env:lpc1768]
platform = nxplpc
board = lpc1768
framework = mbed
test_speed = 9600
test_port = /dev/cu.usbmodem142302

test_sample.cpp

#include <mbed.h>
#include <unity.h>


#define WAIT_TIME_MS 2000

void test_numbers(void)
{
    TEST_ASSERT_EQUAL(13,13);
}



void setUp(void) {
    // set stuff up here
   
}

void tearDown(void) {
    // clean stuff up here
}


int main()
{
    thread_sleep_for(WAIT_TIME_MS);
    UNITY_BEGIN(); // IMPORTANT LINE!
    RUN_TEST(test_numbers);
    UNITY_END();

}

Folder structure

Screenshot 2023-10-26 at 17 07 02

@valeros
Copy link
Member

valeros commented Oct 30, 2023

Hi @lightway29, there might be a conflict between the Unity distribution bundled with the mbed package and the one used by PlatformIO. Could you please try to add a special file .mbedignore to the root of your project (next to platformio.ini) with the following content:

mbed-os/features/frameworks/unity/*

Then clean and test again.

@lightway29
Copy link
Author

lightway29 commented Oct 31, 2023

> Hi @lightway29, there might be a conflict between the Unity distribution bundled with the mbed package and the one used by PlatformIO. Could you please try to add a special file .mbedignore to the root of your project (next to platformio.ini) with the following content:

mbed-os/features/frameworks/unity/*

Then clean and test again.

Hi @valeros,

Cleaned and checked including the `mbedignore' file to the root. Still get the same result.

Screenshot 2023-10-31 at 10 50 03 Screenshot 2023-10-31 at 10 50 52

Have attached the sample project if it helps
pio-testframework-mbed.zip

@valeros
Copy link
Member

valeros commented Oct 31, 2023

That's strange, what version of the nxplpc dev-platform are you using?

@lightway29
Copy link
Author

lightway29 commented Nov 1, 2023

That's strange, what version of the nxplpc dev-platform are you using?

Screenshot 2023-11-01 at 10 14 03

@valeros @ivankravets
I have also experimented on the following

  • By removing both versions of nxplpc 5.3.0 and 9.0.0 then by installing 10.0.0
  • Tried on a windows freshly installed windows pc as well.

FYI - I tried with Arduino and that works perfectly

@valeros
Copy link
Member

valeros commented Nov 1, 2023

Please delete all previous platform instances, clean the project, run your tests in verbose mode via pio test -vvv > piotest.log.txt 2>&1 and attach here that log file.

@lightway29
Copy link
Author

Please delete all previous platform instances, clean the project, run your tests in verbose mode via pio test -vvv > piotest.log.txt 2>&1 and attach here that log file.

@valeros

Attached piotest log file below.

piotest.log.txt

@valeros
Copy link
Member

valeros commented Nov 1, 2023

Strange, according to the log file the Unity sources from the framework are still compiled even though they should be excluded from the build. What's more, I also compiled your project example and it seems to work as expected on Linux and Windows. What happens if you manually remove the /Users/YOUR_USER/.platformio/packages/framework-mbed/features/frameworks/unity folder?

@lightway29
Copy link
Author

Strange, according to the log file the Unity sources from the framework are still compiled even though they should be excluded from the build. What's more, I also compiled your project example and it seems to work as expected on Linux and Windows. What happens if you manually remove the /Users/YOUR_USER/.platformio/packages/framework-mbed/features/frameworks/unity folder?

@valeros
That did the trick. Removed all the frameworks related to Mbed and ran the code it worked fine. One thing I have noticed is that the board needs to be removed and plugged back again every time I run the test. Simply pressing the reset button won't run the test.

@valeros
Copy link
Member

valeros commented Nov 2, 2023

One thing I have noticed is that the board needs to be removed and plugged back again every time I run the test. Simply pressing the reset button won't run the test.

Not sure how the USB communication is implemented on this board, maybe it's a virtual COM port, so you can try adding a delay before UNITY_BEGIN just to make sure the MCU have enough time to reinitialize USB.

@IngmarPaetzold
Copy link

I have a similar issue: when running several testcases, it works perfectly in native environment, but on the target (Arduino Mega 2560), it sometimes runs all, sometimes only the last one, and sometimes the latter twice (-> see this issue here).
However, I do not have the mbed package, thus, cannot remove it. Maybe this is the same bug?
See the description in platformio forum here: https://community.platformio.org/t/unit-test-runs-only-one-testcase-on-target/42778

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants