Clock: make monotonic_ms monotonic, so a clock jump can't freeze the session
CI / test (push) Failing after 52s

It read the wall clock. When NTP moved a phone from 1970 to now, the frame
loop's elapsed time overflowed and it slept for days.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 02:22:27 -08:00
1 parent f51ce088ad
commit 4fd2641c80
4 files changed
+30 -3

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
///|
/// The main loop sleeps for a difference of two `monotonic_ms`: on the wall clock, NTP setting the
/// time (1970 to now on a phone) froze the session for days. CLOCK_MONOTONIC can't be later than
/// /proc/uptime, which also counts suspended time; the wall clock is far past it.
test "monotonic_ms is not the wall clock" {
let before = @sys.monotonic_ms()
let text = @sys.read_proc_bytes("/proc/uptime")
let mut secs = 0UL
for c in text {
guard c is (b'0'..=b'9') else { break }
secs = secs * 10UL + (c - b'0').to_uint64()
}
assert_true(secs > 0UL)
assert_true(before <= (secs + 1UL) * 1000UL)
assert_true(@sys.monotonic_ms() >= before)
}