Skip to content

tests/thread: Adjust thread tests so most are able to run on rp2 port. #13351

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 3 commits into from
Jan 5, 2024

Conversation

dpgeorge
Copy link
Member

@dpgeorge dpgeorge commented Jan 4, 2024

The aim of this commit is to make it so that the existing thread tests can be used to test the _thread module on the rp2 port. The rp2 port only allows up to one thread to be created at a time, and does not have the GIL enabled.

The following changes have been made:

  • run-tests.py skips mutation tests on rp2, because there's no GIL.
  • run-tests.py skips other tests on rp2 that require more than one thread.
  • The tests stop trying to start a new thread after there is an OSError, which indicates that the system cannot create more threads.
  • Some of these tests also now run the test function on the main thread, not just the spawned threads.
  • In some tests the output printing is adjusted so it's the same regardless of how many threads were spawned.
  • Some time.sleep(1) are replaced with time.sleep(0) to make the tests run a little faster (finish sooner when the work is done).

For the most part the tests are unchanged for existing platforms like esp32 and unix.

This test was removed long ago in eb0e3ba.

Signed-off-by: Damien George <damien@micropython.org>
The aim of this commit is to make it so that the existing thread tests can
be used to test the _thread module on the rp2 port.  The rp2 port only
allows up to one thread to be created at a time, and does not have the GIL
enabled.

The following changes have been made:
- run-tests.py skips mutation tests on rp2, because there's no GIL.
- run-tests.py skips other tests on rp2 that require more than one thread.
- The tests stop trying to start a new thread after there is an OSError,
  which indicates that the system cannot create more threads.
- Some of these tests also now run the test function on the main thread,
  not just the spawned threads.
- In some tests the output printing is adjusted so it's the same regardless
  of how many threads were spawned.
- Some time.sleep(1) are replaced with time.sleep(0) to make the tests run
  a little faster (finish sooner when the work is done).

For the most part the tests are unchanged for existing platforms like esp32
and unix.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Jan 4, 2024
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (dc2a4e3) 98.40% compared to head (a003ac2) 98.40%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13351   +/-   ##
=======================================
  Coverage   98.40%   98.40%           
=======================================
  Files         159      159           
  Lines       21088    21088           
=======================================
  Hits        20752    20752           
  Misses        336      336           

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

The existing thread_sleep1.py test only tests execution, not accuracy, of
time.sleep.  Also the existing test only tests sleep(0) on targets like rp2
that can only create a single thread.

The new test in this commit checks for timing accuracy on the main thread
and one other thread when they run at the same time.

Signed-off-by: Damien George <damien@micropython.org>
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.

1 participant