Skip to content
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

PlatformIO test building code twice run #4307

Closed
1 task done
robsonos opened this issue Jun 7, 2022 · 5 comments
Closed
1 task done

PlatformIO test building code twice run #4307

robsonos opened this issue Jun 7, 2022 · 5 comments

Comments

@robsonos
Copy link

robsonos commented Jun 7, 2022

What kind of issue is this?

  • PlatformIO Core.

Configuration

Operating system:

PlatformIO Version (platformio --version): PlatformIO Core, version 6.0.2

Description of problem

PlatformIO test seems to be compiling twice

Steps to Reproduce

  1. Create a project
  2. Create a test
  3. Run pio test -vvv

Actual Results

The two images below are the results from the same pio test -vvv run. I split them in two to increase the resolution
image
image

Expected Results

PlatformIO test to build once per run

Additional info

Commenting lines 139, 141 and 142 from the file below seems to do the trick. I am not sure what impact this would have on other platforms.

if self.options.without_building:
targets.append("nobuild")
else:
targets.append("__test")

@ivankravets
Copy link
Member

There are 2 different stages: firmware building and firmware uploading. The firmware uploading stage depends on the building stage. There is no "rebuilding", the "uploading" stage reuses all objects that were compiled at the first stage.

If your project has custom requirements, you can override default configuration with a custom testing framework https://docs.platformio.org/en/latest/advanced/unit-testing/frameworks/custom/index.html

@robsonos
Copy link
Author

robsonos commented Jun 8, 2022

Hi @ivankravets,

I am aware of those stages, what I am pointing out is that Platformio is effectively building the test firmware twice, which can be very time consuming for large unit tests.

You don't even need a board to observe this issue. I am running this test in a simple Uno project:

platfromio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino

src/main.cpp (not really needed, but here it is):

#include <Arduino.h>

void setup() {}

void loop() {}

test/tets_test/main.cpp:

#include <Arduino.h>

void setup(){
    Serial.begin(9600);
}

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

As previously mentioned, my understanding is that stage_uploading() verifies for if self.options.without_building , which is never true for unit testing (unless of course if --without-building is passed in the cli). Thus "__test" is added to the target list, which causes a second build just prior to uploading. Perhaps none of those 4 lines are actually needed there.

@ivankravets
Copy link
Member

Thanks, I think we can merge these stages into the one if there are no custom stages are passed.

@ivankravets
Copy link
Member

Thanks for the report! Please re-test with pio upgrade --dev.

Does it work as expected now?

@robsonos
Copy link
Author

No worries. It works like a charm now.
Cheers.

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

No branches or pull requests

2 participants