summaryrefslogtreecommitdiff
path: root/test/replicas.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 23:20:38 -0300
committerGabriel Schneider <[email protected]>2026-11-22 23:20:38 -0300
commite6dd9c5c3a60e3609e99ab2076b5a2509a014a66 (patch)
tree59e10d535fbb5ddf1a971c391e0e6b0981a6d409 /test/replicas.zig
parent6270f531cd89130a26ee3d5423a740db707f8888 (diff)
parent9e5b54cfdf73728745d2aeaafac00d823114543e (diff)
downloadpardes-e6dd9c5c3a60e3609e99ab2076b5a2509a014a66.tar.gz
pardes-e6dd9c5c3a60e3609e99ab2076b5a2509a014a66.zip
integration (a base for the next rounds, not yet the gathered line): the pair's round 12 on the viewport's line with a client's way back: pardes-m60-base (`pyquvrsv`: pardes-viewport + pardes-upgrade-back) and pardes-pair-12 (`mlutslkp` on `ntlpyokw` on `zsquynqy` on `wowqsyxt`, on pardes-raw-tty: a 9P request that changes the core waits for the pty output read before it (`Turn.awaitOutput`: pagercolor's cause on both paths); a pair's client takes the tests' clock; the pair rows name the side that went; the soak with a pair among its sides); no conflict; core-test 918/1078 (160 skipped), shell-test 1120/1123 (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/replicas.zig')
-rw-r--r--test/replicas.zig77
1 files changed, 72 insertions, 5 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index a68ce222..8f3e5ca5 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,
@@ -1173,6 +1183,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.
@@ -1219,7 +1232,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 {
@@ -1289,7 +1302,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;
@@ -1354,6 +1370,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),
@@ -1365,7 +1383,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 = &.{} });
@@ -1933,7 +1951,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`).
@@ -1978,6 +1996,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 {
@@ -2114,6 +2155,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);
@@ -2157,9 +2204,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;
@@ -3248,6 +3309,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];
@@ -3313,6 +3378,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,