simulator: Add basic test for the clock
This commit is contained in:
@@ -96,3 +96,7 @@ fn getExecutableEntryPoint(self: *Simulator, name: []const u8) ?EntryPoint {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
test {
|
||||
_ = @import("test_simulator.zig");
|
||||
}
|
||||
|
||||
@@ -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()) {}
|
||||
}
|
||||
Reference in New Issue
Block a user