Skip to content

tests/fio: regression coverage for ref_time_ticks() ns normalization#2690

Merged
borisbat merged 1 commit into
masterfrom
bbatkin/perf-time-roundtrip-test
May 16, 2026
Merged

tests/fio: regression coverage for ref_time_ticks() ns normalization#2690
borisbat merged 1 commit into
masterfrom
bbatkin/perf-time-roundtrip-test

Conversation

@borisbat
Copy link
Copy Markdown
Collaborator

Summary

PR #2685 normalized ref_time_ticks() to return nanoseconds on every platform (Windows used to return raw QPC ticks at the underlying counter's frequency — typically 10 MHz). The fix shipped without a unit test that would have caught a units regression.

This PR adds tests/fio/perf_time.das with four tests:

  • monotonic — 1000 successive reads never go backwards. Catches signed/unsigned mixups and wrap-around bugs in the ns conversion arithmetic.
  • sleep_roundtripsleep(100 ms) → delta must land in [80 ms, 500 ms]. The 80 ms lower bound is the load-bearing assertion: if Windows reverted to raw QPC ticks, a 100 ms sleep would surface as ~1 ms in the ns interpretation, tripping the test. Wide upper bound covers CI runner scheduler jitter.
  • get_time_usec_agreesget_time_usec(t0) and (ref_time_ticks() - t0) / 1000 agree within 5 ms. Two helpers reading the same underlying clock should not drift.
  • units_are_nanoseconds — three back-to-back sleep(100 ms) deltas stay within 200 ms of each other.

tests/aot/CMakeLists.txt:224 already covers tests/fio/*.das via FILE(GLOB CONFIGURE_DEPENDS); cmake reconfigure picks the new file up automatically (no CMake edit needed).

Test plan

  • daslang.exe dastest.das -- --test tests/fio/perf_time.das — interpreter mode, 4/4 PASS on Windows local
  • daslang.exe dastest.das -- --test tests/fio — full fio dir, 175/175 PASS (interpreter)
  • test_aot.exe -use-aot dastest.das -- --use-aot --test tests/fio/perf_time.das — AOT mode, 4/4 PASS on Windows local
  • CI: confirm green on all OSes

🤖 Generated with Claude Code

PR #2685 normalized ref_time_ticks() to nanoseconds across every
platform (Windows used to return raw QPC ticks at the underlying
counter's frequency — typically 10 MHz). The fix shipped without a
unit test that would have caught a units regression.

Add four tests under tests/fio/perf_time.das (sleep() lives in fio,
so this is the right neighborhood):

  - monotonic — 1000 successive reads never go backwards. Catches
    any signed/unsigned mixup or wrap-around bug in the ns conversion
    arithmetic.

  - sleep_roundtrip — sleep(100 ms) -> delta_ns must land in
    [80 ms, 500 ms]. The 80 ms lower bound is the load-bearing
    assertion: if Windows reverted to raw QPC ticks (10 MHz counter
    on the typical box -> a 100 ms wall-clock sleep would surface as
    1000000 "ticks" interpreted as ns, i.e. 1 ms), the test would
    trip. Wide upper bound covers CI runner scheduler jitter.

  - get_time_usec_agrees — the get_time_usec(t0) helper agrees with
    (ref_time_ticks() - t0) / 1000 within 5 ms. Two helpers reading
    the same underlying clock should not drift; if one ever ends up
    on a different code path, this notices.

  - units_are_nanoseconds — three back-to-back sleep(100 ms) deltas
    stay within 200 ms spread. If the unit accidentally changed
    mid-run (think: thread-local frequency cache going stale), the
    deltas would diverge wildly.

The test runs cleanly in both interpreter and AOT mode on Windows
(Win11 local): sleep(100 ms) -> 102-109 ms delta, get_time_usec
agrees to within microseconds. tests/aot/CMakeLists.txt:224 already
covers tests/fio/*.das via FILE(GLOB CONFIGURE_DEPENDS); cmake
reconfigure picks the new file up automatically.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 16, 2026 19:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new test file tests/fio/perf_time.das with four regression tests that pin the post‑PR‑#2685 contract that ref_time_ticks() returns nanoseconds on every platform. The tests exercise monotonicity, a sleep(100ms) round‑trip with a load‑bearing 80 ms lower bound (would catch a regression to raw QPC ticks on Windows), agreement between get_time_usec and the raw delta, and inter‑sample uniformity across three back‑to‑back sleeps. The file is automatically picked up by the existing tests/fio/*.das glob in tests/aot/CMakeLists.txt, so no build changes are required.

Changes:

  • New tests/fio/perf_time.das with 4 [test] functions covering monotonicity, sleep round‑trip bounds, helper/delta agreement, and ns unit sanity.
  • Uses the standard dastest/testing_boost public + daslib/fio + math imports consistent with the rest of tests/.
  • Tolerances chosen to absorb CI scheduler jitter (Windows up to ~200 ms) while still detecting a unit regression.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@borisbat borisbat merged commit a39e155 into master May 16, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants