Skip to content

tests/ports/rp2: Convert rp2.DMA test to a unittest and make it more reliable #17202

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

Conversation

dpgeorge
Copy link
Member

Summary

This PR converts the rp2.DMA test to a unittest (in the first commit, should be a no-op in terms of functionality of the test) and makes it more reliable across all platforms (in the second commit).

Changes to the test to make it more reliable are:

  • Allow the DMA instance to be any instance, not just DMA(0); eg WLAN may be using DMA(0).
  • Make the DMA timing test run a little faster by preloading dma.active.
  • Run the DMA timing test 10 times and take the average time taken as the test result, to eliminate any big effects of caching.
  • Change the expected time to range(30, 80) to cover RP2040, RP2350, RISC-V variants, and both bytecode and native emitter.
  • Add a sleep_ms(1) after waiting for the IRQ to fire, so that any scheduled code gets a chance to run when the test is compiled with the native emitter.

Testing

With these changes this test passes reliably on RPI_PICO, RPI_PICO_W, RPI_PICO2, RPI_PICO2_W, RPI_PICO2-RISCV and RPI_PICO2_W-RISCV, in both bytecode and native emitter mode, with and without WLAN enabled.

The changes here picked up the bug fixed by #17201.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Apr 28, 2025
@dpgeorge dpgeorge requested a review from projectgus April 28, 2025 03:34
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (3f1df4b) to head (00a0cd7).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17202   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21890    21890           
=======================================
  Hits        21572    21572           
  Misses        318      318           

☔ 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.

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.

This is a really good test refactor!

dpgeorge added 2 commits May 1, 2025 13:18
This test is rather complicated and benefits from being a unittest.

Signed-off-by: Damien George <damien@micropython.org>
Changes in this commit:
- Allow the DMA instance to be any instance, not just DMA(0); eg WLAN may
  be using DMA(0).
- Make the DMA timing test run a little faster by preloading `dma.active`.
- Run the DMA timing test 10 times and take the average time taken as the
  test result, to eliminate any big effects of caching.
- Change the expected time to `range(30, 80)` to cover RP2040, RP2350,
  RISC-V variants, and both bytecode and native emitter.
- Add a `sleep_ms(1)` after waiting for the IRQ to fire, so that any
  scheduled code gets a chance to run when the test is compiled with the
  native emitter.

With these changes this test passes reliably on RPI_PICO, RPI_PICO_W,
RPI_PICO2, RPI_PICO2_W, RPI_PICO2-RISCV and RPI_PICO2_W-RISCV, in both
bytecode and native emitter mode, with and without WLAN enabled.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the tests-ports-rp2-dma-convert-to-unittest branch from 451d7c8 to 00a0cd7 Compare May 1, 2025 03:19
@dpgeorge dpgeorge merged commit 00a0cd7 into micropython:master May 1, 2025
23 of 24 checks passed
@dpgeorge dpgeorge deleted the tests-ports-rp2-dma-convert-to-unittest branch May 1, 2025 03:30
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.

2 participants