lib: split time_test into duration/instant/arithm tests per ref/hare/time
Mirror ref/hare/time's impl layout in the test siblings: constants -> duration_test.ww (ref/hare/time/duration.ha:9-18 owns the constants); now/sleep rows -> instant_test.ww (instant is the subject type, ref/hare/time/instant.ha; now/sleep bodies live in ref/hare/time/+linux/functions.ha, a platform split ww does not have); add/diff/compare rows -> arithm_test.ww (ref/hare/time/arithm.ha). Pure move: every @test block is byte-identical; only the section banner lines are deleted (the file names now carry them). The stale file header naming the retired `ww run lib/time/timetest.ww` entry point is dropped, not relocated (rule 8: it described a WHAT that no longer exists). Consumers: Makefile LIBRARY_TESTS entry replaced in place; test/byteid roster 44->46 (+2).
This commit is contained in:
33
lib/time/instant_test.ww
Normal file
33
lib/time/instant_test.ww
Normal file
@@ -0,0 +1,33 @@
|
||||
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)));
|
||||
};
|
||||
Reference in New Issue
Block a user