Skip to content

Conversation

dpgeorge
Copy link
Member

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.

Signed-off-by: Damien George <damien@micropython.org>
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (c33a02f) to head (b9d0a9b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17982   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22296    22296           
=======================================
  Hits        21937    21937           
  Misses        359      359           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Successfully merging this pull request may close these issues.

1 participant