summaryrefslogtreecommitdiff
path: root/src/host/script.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/script.zig')
-rw-r--r--src/host/script.zig49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/host/script.zig b/src/host/script.zig
index 12774b6..9e1dddf 100644
--- a/src/host/script.zig
+++ b/src/host/script.zig
@@ -18,8 +18,13 @@
//! await FIELD VALUE [~T] run frames until it holds (a minute at most)
//! print FIELD write a field's value to stderr (a vector,
//! array or struct: every value in it), no frame
-//! expect-snapshot N live state equals snapshot N, leaf by leaf
-//! (padding ignored), exactly
+//! expect-snapshot NAME live state equals the newest mark NAME, leaf
+//! by leaf (padding ignored, and leaves a layout
+//! change reset), exactly
+//! expect-key WHY FIELD VALUE
+//! the newest keyframe of this session taken for
+//! WHY (`Sessions.Why`: before_reload, mark...)
+//! holds VALUE, read in its own layout
//! expect-log TEXT a recent console line contains TEXT
//! expect-no-log TEXT no recent console line does
//! expect-audio KEY stream KEY has received samples
@@ -49,6 +54,8 @@ const abi = @import("abi");
const Host = @import("Host.zig");
const fields = @import("fields.zig");
const memory = @import("memory.zig");
+const Console = @import("Console.zig");
+const Sessions = @import("Sessions.zig");
pub const frame_ns: u64 = std.time.ns_per_s / 60;
/// The most frames `await` plays: a minute.
@@ -150,10 +157,31 @@ fn step(host: *Host, arena: std.mem.Allocator, command: []const u8, rest: []cons
}
return;
} else if (eq(u8, command, "expect-snapshot")) {
- const index = std.fmt.parseInt(usize, rest, 10) catch return error.InvalidSlot;
- if (!host.timeline.bank.hasSnapshot(index)) return error.EmptySnapshot;
- if (!same(host, index)) return error.ExpectationFailed;
+ const saved = try Console.markState(host, arena, rest);
+ if (!same(host, saved.layout, saved.bytes, rest)) return error.ExpectationFailed;
return;
+ } else if (eq(u8, command, "expect-key")) {
+ const why = std.meta.stringToEnum(Sessions.Why, words.next() orelse "") orelse return error.UnknownWhy;
+ const path = words.next() orelse return error.ExpectedField;
+ const want = std.mem.trim(u8, words.rest(), " \t");
+ const s = &host.sessions;
+ try s.commit(.none);
+ var k = s.keys;
+ while (k > 0) {
+ k -= 1;
+ const key = try s.load(s.session, k);
+ defer key.free(host.gpa);
+ if (key.why != why) continue;
+ const leaf = (try memory.layoutOf(arena, key.layout)).find(path) orelse return error.UnknownField;
+ if (fields.matches(leaf, key.state, want)) return;
+ var buf: [128]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&buf);
+ fields.format(leaf, key.state, &w) catch {};
+ std.debug.print(" {s} keyframe {d}: {s} expected {s}, found {s}\n", .{ @tagName(why), k, path, want, w.buffered() });
+ return error.ExpectationFailed;
+ }
+ std.debug.print(" no {s} keyframe in this session\n", .{@tagName(why)});
+ return error.ExpectationFailed;
} else if (eq(u8, command, "expect-log") or eq(u8, command, "expect-no-log")) {
var found = false;
for (&host.console.lines) |*l| {
@@ -263,15 +291,14 @@ fn holds(host: *Host, path: []const u8, want: []const u8, tolerance: ?f64) bool
return @abs(value - target) <= t;
}
-/// Live state against snapshot `index`, leaf by leaf; prints the first few
-/// differences.
-fn same(host: *Host, index: usize) bool {
+/// Live state against mark `name`'s (`saved`, taken in layout `from`), leaf
+/// by leaf over the leaves migration kept; prints the first few differences.
+fn same(host: *Host, from: memory.Layout, saved: []const u8, name: []const u8) bool {
const layout = host.state.layout;
const live = host.live();
- const saved = host.timeline.bank.slot(index);
var count: usize = 0;
for (layout.fields) |leaf| {
- if (leaf.whole()) continue;
+ if (leaf.whole() or (from.hash != layout.hash and !memory.keeps(from, leaf))) continue;
var it = leaf.elements();
while (it.next()) |offset| {
if (std.mem.eql(u8, live[offset..][0..leaf.size], saved[offset..][0..leaf.size])) continue;
@@ -282,7 +309,7 @@ fn same(host: *Host, index: usize) bool {
leaf.name(offset, &w) catch {};
w.writeAll(": live ") catch {};
fields.format(leaf.at(offset), live, &w) catch {};
- w.print(", snapshot {d} ", .{index}) catch {};
+ w.print(", snapshot {s} ", .{name}) catch {};
fields.format(leaf.at(offset), saved, &w) catch {};
std.debug.print(" {s}\n", .{w.buffered()});
}