Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tests/run-tests.py: Wait for soft reset if a target skips a test. #15990

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

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

dpgeorge
Copy link
Member

Summary

Commit 69c25ea made raising SystemExit do a soft reset (on bare-metal targets). This means that any test which is skipped by a target (by raising SystemExit) will trigger a soft reset on that target, and then it must execute its startup code, such as boot.py.

If the timing is right, this startup code can be unintentionally interrupted by the test runner when preparing the next test, because the test runner enters the raw REPL again via a Ctrl-C Ctrl-A ctrl-D sequence (in Pyboard.enter_raw_repl()).

When this happens (boot.py is interrupted) the target may not be set up correctly, and it may (in the case of stm32 boards) flash LEDs and take extra time, slowing down the test run.

Fix this by explicitly waiting (with a short 1 second timeout) for the target to finish its soft reset when it skips a test.

Testing

Run the test suite many times over and stm32 boards will occasionally have their boot.py interrupted and flash their LEDs to indicate that. With this patch applied you don't ever see that behaviour.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Oct 10, 2024
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (1223fa9) to head (7746785).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15990   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21336    21336           
=======================================
  Hits        21031    21031           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dpgeorge dpgeorge requested a review from projectgus October 10, 2024 05:53
@dpgeorge dpgeorge added this to the release-1.24.0 milestone Oct 10, 2024
# to skip the test. It does this via a SystemExit which triggers a soft
# reset. Wait for the soft reset to finish, so we don't interrupt the
# start-up code (eg boot.py) when preparing to run the next test.
pyb.read_until(1, b"raw REPL; CTRL-B to exit\r\n", timeout=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if 1 second is really long enough here?

I'm thinking of the likes of a wifi board that's used for multitests where it's common to have wifi & network setup in boot.py, this can take longer.

Considering this will continue sooner when that startup message is received I'd be inclined to set a reasonably long timeout for the less common cases that need it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the total timeout, but actually the timeout between characters received over the serial connection.

Well, you're right that it could still take a while, with nothing printed for many seconds.

I can increase it. All boards are expected to do a soft reset after skipping a test, so it should only time out if something is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now changed this to use the default timeout of 10 seconds.

Tested on stm32, rp2 and esp32 boards and the wait for the soft reset after a skip is quick (because they don't do much in their boot.py).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable, looks good!

@dpgeorge dpgeorge force-pushed the tests-run-tests-wait-skip branch from e88a784 to 59b1984 Compare October 11, 2024 05:06
Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good change to me, I'm pretty sure I've seen this behaviour before.

Commit 69c25ea made raising `SystemExit`
do a soft reset (on bare-metal targets).  This means that any test which is
skipped by a target (by raising `SystemExit`) will trigger a soft reset on
that target, and then it must execute its startup code, such as `boot.py`.

If the timing is right, this startup code can be unintentionally
interrupted by the test runner when preparing the next test, because the
test runner enters the raw REPL again via a Ctrl-C Ctrl-A ctrl-D sequence
(in `Pyboard.enter_raw_repl()`).

When this happens (`boot.py` is interrupted) the target may not be set up
correctly, and it may (in the case of stm32 boards) flash LEDs and take
extra time, slowing down the test run.

Fix this by explicitly waiting for the target to finish its soft reset when
it skips a test.

Signed-off-by: Damien George <[email protected]>
@dpgeorge dpgeorge force-pushed the tests-run-tests-wait-skip branch from 59b1984 to 7746785 Compare October 15, 2024 00:23
@dpgeorge dpgeorge merged commit 7746785 into micropython:master Oct 15, 2024
26 checks passed
@dpgeorge dpgeorge deleted the tests-run-tests-wait-skip branch October 15, 2024 00:39
@dpgeorge
Copy link
Member Author

Thanks for the reviews!

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

Successfully merging this pull request may close these issues.

3 participants