Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

tests/extmod: Make test time_res.py more deterministic.#18347

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
andrewleech wants to merge1 commit intomicropython:master
base:master
Choose a base branch
Loading
fromandrewleech:fix_time_res_determinism

Conversation

@andrewleech
Copy link
Contributor

@andrewleechandrewleech commentedOct 30, 2025
edited
Loading

Summary

This PR improves the determinism oftests/extmod/time_res.py which has been failing intermittently on Windows CI.

Problem: The test was counting unique values returned by time functions over a 2.5-second window, expecting at least 3 unique values for second-resolution functions (gmtime(),localtime()). This approach had fundamental issues:

  1. Clock source mismatch: Usedticks_ms() (system tick timer) to measure test duration while samplinggmtime()/localtime() (RTC). On embedded platforms these are different hardware clocks that can drift relative to each other.

  2. Race conditions: To see 3 unique second values in a 2.5-second window, the RTC must advance by >2.0 seconds. Due to timing overhead and clock drift, the test could observe only 2.4 seconds of RTC time, causing spurious failures.

  3. Windows-specific issues: Windows system clock has ~15ms granularity, making the sample-counting approach particularly unreliable.

Recent CI failures:

Attempted Solution: Replace with direct resolution and bounds testing:

  • For each time function, measure value before sleep, sleep appropriate duration, measure after
  • Verify the function advanced within expected bounds (80%-200% of sleep time)
  • Lower bound checks proper resolution, upper bound catches broken implementations
  • 2x upper tolerance handles loaded CI systems while catching real problems
  • Eliminates clock drift issues by using appropriate sleep duration for each clock source

Testing

The test logic here is hopefully more robust:

  • Second-resolution functions (time(),gmtime(),localtime()): Sleep 1200ms and verify value changed within 1-2.4 second range
  • Tick functions (ticks_ms,ticks_us,ticks_ns): Sleep 150ms and verify advanced within 80%-200% of expected
  • Upper bound checking: 2x tolerance handles loaded CI systems while catching broken implementations
  • Platform handling: Gracefully handles platforms whereticks_cpu returns 0

This approach aims to tests the actual contract of each function (proper time resolution within bounds) rather than a proxy metric (sample counts in specified window).

The test should hopefully now pass reliably on all platforms including Windows, Unix, and embedded targets without platform-specific skip lists.

@codecov
Copy link

codecovbot commentedOct 30, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (4efc5e1) to head (6453fee).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@##           master   #18347   +/-   ##=======================================  Coverage   98.38%   98.38%           =======================================  Files         171      171             Lines       22297    22297           =======================================  Hits        21936    21936             Misses        361      361

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

Replace sample-counting approach with direct monotonicity andresolution tests. The previous method mixed ticks_ms() and RTCclock sources which could drift, causing non-deterministic resultsacross platforms. New approach directly tests that time functionsadvance at their documented rates.Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
@dpgeorgedpgeorge added the testsRelates to tests/ directory in source labelNov 3, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

testsRelates to tests/ directory in source

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@andrewleech@dpgeorge@pi-anl

[8]ページ先頭

©2009-2025 Movatter.jp