tests/ports/rp2: Decrease test lower bound for thread lightsleep time. #17982
+8
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes the rp2-specific lightsleep test more lenient, so it passes.
This test was added in #16454, and even back then it did not pass reliably on RP2040. The issue is that threads can race each other to enter lightsleep mode, and when one of them actually stops the CPU clock the other thread is stopped as well. Depending on whether the other thread was just entering or just exiting lightsleep itself, the total duration of all sleeps can vary and can be as small as 2*T.
So, adjust the minimum to allow 2*T.
Work done in collaboration with @projectgus .
Testing
Tested on RPI_PICO, RPI_PICO_W and RPI_PICO2 in RISCV mode. It passes on all of them reliably.
Trade-offs and Alternatives
This makes the test more lenient, ie less strict. But this part of the test is really only there to make sure the rp2 doesn't lock up, rather than make sure the lightsleep is accurate.
machine.lightsleep()
is anyway (1) specified only to wait at most the given time; and (2) not well specified when multiple threads call it at the same time. So it seems OK to make the test more lenient.