simulator: expose reachableSometimes via Simulator
This commit is contained in:
+26
-5
@@ -7,7 +7,8 @@ const Trace = @import("trace.zig").Trace;
|
|||||||
const Scheduler = @import("scheduler.zig");
|
const Scheduler = @import("scheduler.zig");
|
||||||
const Network = @import("network.zig");
|
const Network = @import("network.zig");
|
||||||
const Node = @import("node.zig");
|
const Node = @import("node.zig");
|
||||||
const Sometimes = @import("sometimes.zig").Sometimes;
|
const sometimes_mod = @import("sometimes.zig");
|
||||||
|
const Sometimes = sometimes_mod.Sometimes;
|
||||||
|
|
||||||
pub const EntryPoint = Scheduler.MainEntryPoint;
|
pub const EntryPoint = Scheduler.MainEntryPoint;
|
||||||
|
|
||||||
@@ -26,9 +27,24 @@ var g_sometimes: ?*Sometimes = null;
|
|||||||
//
|
//
|
||||||
// This never changes the behaviour of the program under test: if no simulation
|
// This never changes the behaviour of the program under test: if no simulation
|
||||||
// is active the call is a no-op.
|
// is active the call is a no-op.
|
||||||
pub fn assertSometimes(cond: bool, src: std.builtin.SourceLocation, label: ?[]const u8) void {
|
pub fn assertSometimes(cond: bool, comptime src: std.builtin.SourceLocation, comptime label: ?[]const u8) void {
|
||||||
|
const site = sometimes_mod.registerSite(src, label, .assert);
|
||||||
const registry = g_sometimes orelse return;
|
const registry = g_sometimes orelse return;
|
||||||
registry.record(cond, src, label);
|
registry.record(cond, site.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Records that this call site was reached. This is the conditionless form of
|
||||||
|
// assertSometimes() for branches where reaching the line is the coverage signal.
|
||||||
|
pub fn reachableSometimes(comptime src: std.builtin.SourceLocation, comptime label: ?[]const u8) void {
|
||||||
|
const site = sometimes_mod.registerSite(src, label, .reachable);
|
||||||
|
const registry = g_sometimes orelse return;
|
||||||
|
registry.record(true, site.*);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prints every compiled assertSometimes()/reachableSometimes() call site known
|
||||||
|
// to this binary. This is independent of whether a simulation has run.
|
||||||
|
pub fn reportSometimesSites() void {
|
||||||
|
sometimes_mod.reportCompileTimeSites();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SpawnOptions = struct {
|
const SpawnOptions = struct {
|
||||||
@@ -68,6 +84,7 @@ pub fn init(self: *Simulator, gpa: Allocator, real_io: std.Io, seed: u64) void {
|
|||||||
self.real_io = real_io;
|
self.real_io = real_io;
|
||||||
self.next_node_id = 0;
|
self.next_node_id = 0;
|
||||||
self.sometimes.init(gpa);
|
self.sometimes.init(gpa);
|
||||||
|
self.sometimes.seedCompileTimeSites();
|
||||||
g_sometimes = &self.sometimes;
|
g_sometimes = &self.sometimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +107,17 @@ pub fn deinit(self: *Simulator) void {
|
|||||||
self.trace.deinit();
|
self.trace.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prints which sometimes-assertions were taken (✓) and which were reached
|
// Prints which sometimes-assertions were taken and which were reached
|
||||||
// but never satisfied (✗). Called automatically by deinit(); expose it so
|
// but never satisfied. Called automatically by deinit(); expose it so
|
||||||
// callers can choose exactly when the report is emitted.
|
// callers can choose exactly when the report is emitted.
|
||||||
pub fn reportSometimes(self: *Simulator) void {
|
pub fn reportSometimes(self: *Simulator) void {
|
||||||
self.sometimes.report();
|
self.sometimes.report();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sometimesCovered(self: *Simulator) bool {
|
||||||
|
return self.sometimes.allReached();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setTraceOutputFile(self: *Simulator, path: []const u8) !void {
|
pub fn setTraceOutputFile(self: *Simulator, path: []const u8) !void {
|
||||||
try self.trace.setOutputFile(path);
|
try self.trace.setOutputFile(path);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user