package time_test; import time; @test fn nowmonotonic() void = { let a = time.now(time.clock.monotonic); let b = time.now(time.clock.monotonic); // Two back-to-back calls — b can equal a (same ns tick) but // must never precede it. assert(!(time.compare(a, b) > 0i8)); }; // Sanity check that the syscall plumbing actually lands real bytes // in the instant. 2020-01-01 UTC = 1577836800 unix seconds; any // past-2020 wall clock satisfies this. (CI / test machines running // pre-2020 would fail here; acceptable trade for catching a // zero-init / wrong-slot regression.) @test fn nowrealtime() void = { let t = time.now(time.clock.realtime); assert(!(t.sec < 1577836800i64)); assert(!(t.nsec < 0i64)); assert(!(t.nsec >= 1000000000i64)); }; @test fn sleepmonotonic() void = { let before: time.instant = time.now(time.clock.monotonic); time.sleep((5i64 * (time.millisecond: i64)): time.duration, time.clock.monotonic); let after: time.instant = time.now(time.clock.monotonic); let elapsed: i64 = time.diff(before, after): i64; assert(!(elapsed < 5i64 * (time.millisecond: i64))); };