summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 22:27:25 -0300
committerGabriel Schneider <[email protected]>2026-11-22 22:40:17 -0300
commit9e5b54cfdf73728745d2aeaafac00d823114543e (patch)
treed73efa786a37a830e590eed6f55af6ccfd054a3c /test
parent86414697b09897bdd5091037a4709748cecbc3bf (diff)
downloadpardes-9e5b54cfdf73728745d2aeaafac00d823114543e.tar.gz
pardes-9e5b54cfdf73728745d2aeaafac00d823114543e.zip
replicas: the soak with a pair among its sides (`--pair`): client 0 is the session's pair client, as a terminal's `pardes` is under the variable (runtime/main.zig `pair`): its socket pair made before the session, the session's end its first client (`Soak.options`: `o.pair`, joined with `.own` before the first effects by runtime/session.zig), its size the session's, no dial and no own typist (nobody else draws the session's view: `watchedHost` false), and its replica's core its own boot (`Soak.booted`: `Replica.initBoot` with the options the session starts with, as `replica.ownBoot`), kept when the welcome's digest is its own (`confirmBoot`'s rule) or else the session's dump loaded and the FIELDS of the two cores that differ printed and counted unequal (the one place a client's core comes from no dump: where the coordinator's merge57 gate saw a pair's first quiet check differ once on ReleaseSafe); a line per rtt says the boots and how many were not the session's core; three runs of `--clients 5 --pair` (Debug, loads 1.7-8.5): diverged 0 and unequal 0 at 30, 80 and 207 ms each, the pair's client booted its own core 36 times and every one was the session's at its join (no field named: none differed), quiet checks 988/0 933/0 959/0, 1327/0 1112/0 1063/0, 1076/0 1064/0 987/0, unlisted stops 0, the corpus through a client 22 of 22 scenes the same, no leak; so the merge57 gate's pair `differ` is not a boot's in Debug (not run on ReleaseSafe)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
-rw-r--r--test/replicas.zig77
1 files changed, 72 insertions, 5 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index 90f7c10d..57bd7617 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -51,6 +51,12 @@ var trace = false;
/// `--witness`: the witness judged at every run's end, not only after a
/// divergence (`Witness`).
var witness_always = false;
+/// `--pair`: client 0 is the session's pair client (Options.pair: a
+/// terminal's `pardes` as a client and its session): joined before the
+/// session's first effects, its core its own boot (replica.ownBoot), the
+/// welcome's digest its check (confirmBoot), the session's own frontend
+/// gone (no typist, its view the pair's).
+var pair_mode = false;
/// The PDF the soak opens (`--pdf`), absolute.
var pdf_path: ?[]const u8 = null;
const frame_us = 16_667;
@@ -246,6 +252,10 @@ const Totals = struct {
/// (PARDES_TEST_DIVERGE's), and clients that left; quiet checks.
joins: u64 = 0,
refused: u64 = 0,
+ /// A pair's client's own boot the session's core at its join (`--pair`),
+ /// or not (its dump loaded instead, the fields that differ said).
+ boots: u64 = 0,
+ boots_unequal: u64 = 0,
rejoined: u64 = 0,
detached: u64 = 0,
agree: u64 = 0,
@@ -1174,6 +1184,9 @@ const Soak = struct {
/// `Peers.detach` shut its link; the session's own view's is its
/// terminal's, which the soak has none of).
detach_view: ?u8 = null,
+ /// `--pair`: the session's end of client 0's link, its first client's
+ /// (`options`).
+ pair_fd: c_int = -1,
// ---- the soak ----
/// The soak's time (us): the last message's.
@@ -1220,7 +1233,7 @@ const Soak = struct {
/// its own (Core.render: drawn whenever a frame is owed and someone
/// sees it, and a terminal is always seen).
fn watchedHost(_: ?*anyopaque) bool {
- return true;
+ return !pair_mode;
}
fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void {
@@ -1290,7 +1303,10 @@ const Soak = struct {
// ---- the session loop's frontend ----
- pub fn options(_: *Soak, _: *pardes.Options) void {}
+ /// A pair's: its first client on the link `run` made.
+ pub fn options(s: *Soak, o: *pardes.Options) void {
+ if (s.pair_fd >= 0) o.pair = s.pair_fd;
+ }
pub fn open(s: *Soak, l: *SessionLoop) !pardes.Host {
s.l = l;
@@ -1355,6 +1371,8 @@ const Soak = struct {
// let go); the first leaves when it is done; the second is put off
// the session once (PARDES_TEST_DIVERGE) and joins again for its view.
for (s.clients, 0..) |*cl, c| {
+ // A pair's client joined at the loop's start.
+ if (pair_mode and c == 0) continue;
cl.dialling = true;
const at: u64 = switch (c) {
0, 1 => s.random.uintLessThan(u64, 100_000),
@@ -1366,7 +1384,7 @@ const Soak = struct {
};
try net.send(.{ .at = at, .n = 0, .kind = .dial, .who = @intCast(c + 1), .bytes = &.{} });
}
- try net.send(.{ .at = s.random.uintLessThan(u64, 200_000), .n = 0, .kind = .own, .who = 0, .bytes = &.{} });
+ if (!pair_mode) try net.send(.{ .at = s.random.uintLessThan(u64, 200_000), .n = 0, .kind = .own, .who = 0, .bytes = &.{} });
try net.send(.{ .at = tui_at, .n = 0, .kind = .output, .who = 0, .bytes = &.{} });
try net.send(.{ .at = session_at, .n = 0, .kind = .output, .who = 2, .bytes = &.{} });
try net.send(.{ .at = flood_at, .n = 0, .kind = .output, .who = 1, .bytes = &.{} });
@@ -1934,7 +1952,7 @@ const Soak = struct {
try s.totals.add(&old.stats);
old.deinit();
}
- const rp = try replica.Replica.initDump(gpa, cl.id, cl.view, m.bytes, .{ .cols = cl.cols, .rows = cl.rows, .distrusted = &cl.distrusted });
+ const rp = if (pair_mode and c == 0 and !s.has_link[0]) try s.booted(cl, m.bytes) else try replica.Replica.initDump(gpa, cl.id, cl.view, m.bytes, .{ .cols = cl.cols, .rows = cl.rows, .distrusted = &cl.distrusted });
cl.r = rp;
// In process: its clock reads are the session's machine's, and the
// units' heads carry the soak's clock (`stamp`).
@@ -1979,6 +1997,29 @@ const Soak = struct {
if (cl.left > 0 and cl.left == s.r.steps) try net.send(.{ .at = m.at + typistGap(s.random), .n = 0, .kind = .input, .who = m.who, .bytes = &.{} });
}
+ /// A pair's client's replica: its core its own boot from the options
+ /// the session was started with (`run`'s), as the pair's client makes
+ /// it (replica.ownBoot), kept when the welcome's digest is its own
+ /// (confirmBoot); else the session's dump, loaded, and the fields of
+ /// the two cores that differ said.
+ fn booted(s: *Soak, cl: *Client, dump: []const u8) !*replica.Replica {
+ s.totals.boots += 1;
+ const boot = try replica.Replica.initBoot(gpa, .{ .cols = 100, .rows = 30, .boot = .tty, .distrusted = &cl.distrusted });
+ if (boot.digest() == cl.digest) {
+ boot.id = cl.id;
+ boot.view = cl.view;
+ return boot;
+ }
+ defer boot.deinit();
+ s.totals.boots_unequal += 1;
+ const rp = try replica.Replica.initDump(gpa, cl.id, cl.view, dump, .{ .cols = cl.cols, .rows = cl.rows, .distrusted = &cl.distrusted });
+ var buf: [4096]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&buf);
+ Witness.fieldsDiffer(boot.core(), rp.core(), &w);
+ std.debug.print("seed {d} rtt {d} ms: the pair's own boot is not the session's core at its join; differ: {s}", .{ s.r.seed, s.r.rtt_ms, w.buffered() });
+ return rp;
+ }
+
/// At quiescence: every client's digest the session's, its terminals
/// the session's cell for cell, its files' texts byte for byte.
fn finish(s: *Soak) !void {
@@ -2115,6 +2156,12 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void {
var clients: [8]Client = undefined;
for (clients[0..r.clients], 0..) |*cl, c| {
cl.* = .{ .kind = if (c % 2 == 0) .tty else .window, .left = r.steps, .cols = @intCast(random.intRangeAtMost(u16, 60, 120)), .rows = @intCast(random.intRangeAtMost(u16, 16, 40)) };
+ // A pair's client is the terminal the session was started at the
+ // size of (main.zig `pair`).
+ if (pair_mode and c == 0) {
+ cl.cols = 100;
+ cl.rows = 30;
+ }
var name: [300]u8 = undefined;
cl.check = try gpa.dupeSentinel(u8, try std.fmt.bufPrint(&name, "{s}/check-{d}", .{ dir, c }), 0);
_ = libc.unlink(cl.check);
@@ -2158,9 +2205,23 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void {
.flood = flood,
.yes_len = yes.len,
.own_left = r.steps,
- .typing = r.clients + 1,
+ .typing = r.clients + @intFromBool(!pair_mode),
.media = &media,
};
+ // A pair's client's link, made before the session (main.zig `pair`):
+ // its end handed to the session's options, the soak reading the other
+ // as for a dial (`.dial`).
+ if (pair_mode) {
+ const cl = &clients[0];
+ var fds: [2]c_int = undefined;
+ if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket;
+ _ = libc.fcntl(fds[0], libc.F.SETFL, @as(c_int, @bitCast(libc.O{ .NONBLOCK = true })));
+ cl.sfd = fds[0];
+ cl.cfd = fds[1];
+ cl.handed = libc.dup(fds[0]);
+ if (cl.handed < 0) return error.NoSocket;
+ soak.pair_fd = cl.handed;
+ }
// The session: THE session loop, from its start to its end.
try SessionLoop.run(init, .{ .cols = 100, .rows = 30, .boot = .tty }, &soak);
if (soak.err) |err| return err;
@@ -3249,6 +3310,10 @@ pub fn main(init: std.process.Init) !void {
witness_always = true;
continue;
}
+ if (std.mem.eql(u8, name, "--pair")) {
+ pair_mode = true;
+ continue;
+ }
if (i + 1 >= args.len) return error.MissingValue;
i += 1;
const value = args[i];
@@ -3314,6 +3379,8 @@ pub fn main(init: std.process.Init) !void {
pardes.Term.reloads = .{};
for (first..first + seeds) |seed| try run(init, .{ .seed = seed, .rtt_ms = rtt, .steps = steps, .clients = clients, .flood_mb = flood_mb }, dir, &t);
std.debug.print("rtt {d}: {d} reloads of a terminal at joins, every side (the session's own too), {d} us each, {d} us at worst; {d} kitty images in clients at quiescence, each the session's pixels\n", .{ rtt, pardes.Term.reloads.n, pardes.Term.reloads.ns / @max(1, pardes.Term.reloads.n) / 1000, pardes.Term.reloads.worst_ns / 1000, t.images_equal });
+ if (pair_mode) std.debug.print("rtt {d}: the pair's client booted its own core {d} times, {d} of them not the session's at its join\n", .{ rtt, t.boots, t.boots_unequal });
+ if (t.boots_unequal > 0) t.unequal += t.boots_unequal;
const rollbacks = t.mispredicted + t.foreign;
std.debug.print("{d:>4} {d:>6} {d:>7} {d:>7} {d:>6} {d:>6} {d:>6} ({d}+{d}) {d:>5.1}% {d:>6} {d:>5}/{d:<6} {d:>5}/{d:<5} ({d}) {d:>7}/{d:<7} {d:>8} {d:>7}\n", .{
rtt, t.inputs, t.speculated,