simulator: Add basic test for the clock

This commit is contained in:
2026-05-22 11:07:16 +02:00
parent c663ed56f0
commit c2c7a3ac83
2 changed files with 32 additions and 0 deletions
+4
View File
@@ -96,3 +96,7 @@ fn getExecutableEntryPoint(self: *Simulator, name: []const u8) ?EntryPoint {
}
return null;
}
test {
_ = @import("test_simulator.zig");
}
+28
View File
@@ -0,0 +1,28 @@
const std = @import("std");
const Simulator = @import("simulator.zig");
const Io = std.Io;
const Clock = Io.Clock;
fn testClockGrowsMonotonically(init: std.process.Init) anyerror!void {
const io = init.io;
const t1 = Clock.boot.now(io);
const t2 = Clock.boot.now(io);
try std.testing.expect(t1.nanoseconds <= t2.nanoseconds);
const t3 = Clock.boot.now(io);
try std.testing.expect(t2.nanoseconds <= t3.nanoseconds);
}
test "clock grows monotonically" {
var sim: Simulator = undefined;
sim.init(std.heap.page_allocator, std.Options.debug_io);
defer sim.deinit();
try sim.addExecutable("program_a", testClockGrowsMonotonically);
try sim.spawn("program_a", .{});
while (sim.scheduleOne()) {}
}