summaryrefslogtreecommitdiff
path: root/test/replicas.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/replicas.zig')
-rw-r--r--test/replicas.zig48
1 files changed, 29 insertions, 19 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index c100a8c1..f6aa2af2 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -35,8 +35,8 @@ const std = @import("std");
const libc = std.c;
const pardes = @import("pardes");
const replica = pardes.replica;
-const screen_state = pardes.Term.screen_state;
-const Echo = pardes.Term.Echo;
+const screen_state = @import("term").screen_state;
+const Echo = pardes.Echo;
const Key = pardes.Key;
const gpa = std.heap.c_allocator;
@@ -223,7 +223,17 @@ fn writeText(path: [:0]const u8, text: []const u8) !void {
const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, shared: bool, flood_mb: u64 };
/// The terminal pane's screen as a hash of screen_state's dump of it.
-fn screenHash(t: *pardes.Term.screen_state.Terminal) u64 {
+/// The module's own replica behind the core's handle (Replica.screens).
+fn replicaOf(r: *pardes.Term.Replica) *screen_state.Replica {
+ return @ptrCast(@alignCast(r));
+}
+
+/// The module's own track behind the core's handle (Screens.tracks).
+fn trackOf(t: *pardes.Term.Track) *screen_state.Track {
+ return @ptrCast(@alignCast(t));
+}
+
+fn screenHash(t: *screen_state.Terminal) u64 {
var buf: [8192]u8 = undefined;
var h: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(.init(0), &buf);
screen_state.dumpScreen(t, &h.writer) catch {};
@@ -416,12 +426,12 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
if (reply[5] == 1) {
// Applied: the screen is the authority's at that version.
const sc = rp.screens[pane].?;
- const vt = &rp.core().panes[pane].?.terminal.?.vt;
+ const vt = &pardes.Term.emulatorOf(rp.core().panes[pane].?.terminal.?).vt;
totals.screens_checked += 1;
- if (versions.get(@as(u64, sc.serial) << 32 | sc.rep.seq)) |want| {
+ if (versions.get(@as(u64, sc.serial) << 32 | replicaOf(sc.rep).seq)) |want| {
if (want != screenHash(vt)) {
totals.screens_wrong += 1;
- std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at version {d} is not the authority's\n", .{ r.seed, r.rtt_ms, m.who, pane, sc.rep.seq });
+ std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at version {d} is not the authority's\n", .{ r.seed, r.rtt_ms, m.who, pane, replicaOf(sc.rep).seq });
}
} else totals.screens_wrong += 1;
// Deltas while the flood runs (an RTT/2 behind it).
@@ -459,7 +469,7 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
totals.unequal += 1;
continue;
}).terminal orelse continue;
- if (screenHash(&state.vt) != screenHash(&mine.vt)) {
+ if (screenHash(&pardes.Term.emulatorOf(state).vt) != screenHash(&pardes.Term.emulatorOf(mine).vt)) {
totals.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: replica {d}'s terminal {d} at quiescence is not the authority's\n", .{ r.seed, r.rtt_ms, id, pid });
}
@@ -567,10 +577,10 @@ fn flushAll(sc: *replica.Screens, core: *pardes.Pardes, ps: []const u16, list: *
}
// Each version as the authority's screen showed it.
for (&sc.tracks, 0..) |*slot, id| if (slot.*) |*tr| {
- const key = @as(u64, tr.serial) << 32 | tr.track.version;
- if (tr.track.version == 0 or vs.contains(key)) continue;
+ const key = @as(u64, tr.serial) << 32 | trackOf(tr.track).version;
+ if (trackOf(tr.track).version == 0 or vs.contains(key)) continue;
_ = core.panes[id] orelse continue;
- try vs.put(gpa, key, screenHash(&tr.state.vt));
+ try vs.put(gpa, key, screenHash(&pardes.Term.emulatorOf(tr.state).vt));
};
}
@@ -976,7 +986,7 @@ const EchoTotals = struct {
};
fn cellCp(state: *pardes.Term.State, x: u16, y: u16) u21 {
- const ci = state.vt.screens.active.pages.getCell(.{ .active = .{ .x = x, .y = y } }) orelse return 0x10ffff;
+ const ci = pardes.Term.emulatorOf(state).vt.screens.active.pages.getCell(.{ .active = .{ .x = x, .y = y } }) orelse return 0x10ffff;
const cp = ci.cell.codepoint();
return if (cp == 0) ' ' else cp;
}
@@ -1071,7 +1081,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
for (made.items) |pr| {
const k = &typed.items[pr.seq - 1];
if (trace) {
- const sc = rp.core().panes[shell].?.terminal.?.vt.screens.active.cursor;
+ const sc = pardes.Term.emulatorOf(rp.core().panes[shell].?.terminal.?).vt.screens.active.cursor;
std.debug.print("{d} ms ({t}): key {d} predicted {any} cursor {d}; acked {d} wait {d} nd {d}; the screen's cursor {d},{d}\n", .{ m.at / 1000, m.kind, pr.seq, pr.cell, pr.cursor.x, rp.echo.acked, rp.echo.wait, rp.echo.nd, sc.x, sc.y });
}
if (pr.cell) |cell| k.pred = .{ .x = cell.x, .y = @intCast(cell.row - top), .cp = cell.cp };
@@ -1106,7 +1116,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
const state = a.core.panes[shell].?.terminal.?;
if (ty) |k| {
k.mode = sh.mode;
- k.version_before = if (screens.tracks[shell]) |*tr| tr.track.version else 0;
+ k.version_before = if (screens.tracks[shell]) |*tr| trackOf(tr.track).version else 0;
}
sh.key(m.bytes);
if (sh.out.items.len > 0) {
@@ -1115,7 +1125,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
if (ty) |k| k.echoed = true;
}
if (ty) |k| {
- const cur = state.vt.screens.active.cursor;
+ const cur = pardes.Term.emulatorOf(state).vt.screens.active.cursor;
k.after = .{ .x = @intCast(cur.x), .y = @intCast(cur.y), .row = undefined };
for (&k.after.?.row, 0..) |*cp, x| cp.* = cellCp(state, @intCast(x), @intCast(cur.y));
judgeTruth(k);
@@ -1157,11 +1167,11 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
k.first_visible = m.at;
if (trace) {
const st = core.panes[shell].?.terminal.?;
- std.debug.print("{d} ms: key {d} ('{u}') drawn: trusted {} doubt {} phase {t} sem {t}\n", .{ m.at / 1000, cell.seq, cell.cp, rp.echo.trusted, rp.echo.doubt, st.stream.handler.phase, st.vt.screens.active.cursor.semantic_content });
+ std.debug.print("{d} ms: key {d} ('{u}') drawn: trusted {} doubt {} phase {t} sem {t}\n", .{ m.at / 1000, cell.seq, cell.cp, rp.echo.trusted, rp.echo.doubt, pardes.Term.emulatorOf(st).stream.handler.phase, pardes.Term.emulatorOf(st).vt.screens.active.cursor.semantic_content });
}
}
};
- const applied = if (rp.screens[shell]) |sc| sc.rep.seq else 0;
+ const applied = if (rp.screens[shell]) |sc| replicaOf(sc.rep).seq else 0;
for (typed.items) |*k| if (k.echoed and k.seen == null and applied > k.version_before) {
k.seen = m.at;
};
@@ -1178,8 +1188,8 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
const pane = m.bytes[0];
if (reply[5] == 1) {
const sc = rp.screens[pane].?;
- if (versions.get(@as(u64, sc.serial) << 32 | sc.rep.seq)) |want| {
- if (want != screenHash(&rp.core().panes[pane].?.terminal.?.vt)) t.screens_wrong += 1;
+ if (versions.get(@as(u64, sc.serial) << 32 | replicaOf(sc.rep).seq)) |want| {
+ if (want != screenHash(&pardes.Term.emulatorOf(rp.core().panes[pane].?.terminal.?).vt)) t.screens_wrong += 1;
} else t.screens_wrong += 1;
}
try push(&queue, &n, .{ .at = up[0].arrive(random, m.at, one_way, jitter), .n = 0, .kind = .screen_up, .who = 1, .bytes = try gpa.dupe(u8, reply) });
@@ -1238,7 +1248,7 @@ fn runEcho(seed: u64, rtt_ms: u64, on: bool, et: *EchoTotals) !void {
et.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: the replica at quiescence: {s}\n", .{ seed, rtt_ms, if (rp.quiet()) "another digest" else "inputs still pending" });
}
- if (screenHash(&a.core.panes[shell].?.terminal.?.vt) != screenHash(&rp.core().panes[shell].?.terminal.?.vt)) {
+ if (screenHash(&pardes.Term.emulatorOf(a.core.panes[shell].?.terminal.?).vt) != screenHash(&pardes.Term.emulatorOf(rp.core().panes[shell].?.terminal.?).vt)) {
et.unequal += 1;
std.debug.print("seed {d} rtt {d} ms: the shell at quiescence is not the authority's\n", .{ seed, rtt_ms });
}