diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/daemon.py | 6 | ||||
| -rw-r--r-- | test/kitty.zig | 4 | ||||
| -rw-r--r-- | test/perf.zig | 5 | ||||
| -rw-r--r-- | test/replicas.zig | 77 | ||||
| -rw-r--r-- | test/terminal.zig | 8 |
5 files changed, 86 insertions, 14 deletions
diff --git a/test/daemon.py b/test/daemon.py index 6e7bad3f..dc1abcbc 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -925,7 +925,11 @@ def pair_rows(binary): t, c, nine, session, pane = started('lone', dict(env, PARDES_DAEMON='off')) typed_detach(t, nine, pane) time.sleep(1) - assert c.poll() is None and alive(session), 'a Detach with no daemon is refused' + # Which went, if one did: the client's exit and its screen's last + # words, the session's life (its stderr is /dev/null: no log). + went = [w for w, gone in (('the client', c.poll() is not None), ('the session', not alive(session))) if gone] + assert not went, (f'a Detach with no daemon is refused: {" and ".join(went)} went (client exit {c.poll()}, ' + f'session {"alive" if alive(session) else "gone"}); the terminal\'s last bytes: {t.text()[-600:]!r}') nine.socket.close() t.close() terms.remove(t) diff --git a/test/kitty.zig b/test/kitty.zig index 22b62fb2..0bd849c2 100644 --- a/test/kitty.zig +++ b/test/kitty.zig @@ -641,7 +641,7 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].dst.y); // A narrower pane reflows the text; the image stays on its row. const pane = r.pane(0); - pane.resizeGrid(0, 40, pane.rows); + pane.resizeGrid(r.p, 40, pane.rows); const text = try pardes.Term.scrollback(pane.terminal, r.frame.allocator()); var row: usize = 0; var lines = std.mem.splitScalar(u8, text, '\n'); @@ -1167,7 +1167,7 @@ fn fuzzRun(seed: u64, steps: usize, trace: bool) !bool { r.p.update(.{ .resize = .{ .cols = cols, .rows = rows, .cell_pixels = .{ .w = 1 + rng.uintLessThan(u16, 30), .h = 1 + rng.uintLessThan(u16, 60) } } }); r.drain(); }, - 1 => r.pane(0).resizeGrid(0, 1 + rng.uintLessThan(u16, 120), 1 + rng.uintLessThan(u16, 40)), + 1 => r.pane(0).resizeGrid(r.p, 1 + rng.uintLessThan(u16, 120), 1 + rng.uintLessThan(u16, 40)), 2, 3 => { const drawn = try r.places(); if (trace) std.debug.print(" {d} places, {d} placements, {d} images\n", .{ drawn.len, r.placementCount(0), r.storage(0).images.count() }); diff --git a/test/perf.zig b/test/perf.zig index 30e15dcc..8622e31b 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -316,6 +316,7 @@ fn measureCreation(io: std.Io, reps: usize, json: bool) !void { for ([_]bool{ false, true }) |terminal| { var cold_ns: u64 = 0; var cold_deinit_ns: u64 = 0; + var outside: pardes.Term.Outside = .{}; var calls: usize = 0; var bytes: usize = 0; var live: usize = 0; @@ -325,12 +326,12 @@ fn measureCreation(io: std.Io, reps: usize, json: bool) !void { const allocator = counter.allocator(); const begin = nowNs(); const pane = if (terminal) - try pardes.panes.createTerminal(allocator, screen_cols, screen_rows) + try pardes.panes.createTerminal(&outside, allocator, screen_cols, screen_rows) else try pardes.panes.createDoc(allocator, screen_cols, screen_rows); const constructed = nowNs(); const retained = counter.live; - if (pane.terminal) |state| pardes.Term.close(state, allocator); + if (pane.terminal) |state| pardes.Term.close(&outside, state); allocator.destroy(pane); const destroyed = nowNs(); if (counter.live != 0) return error.LeakedPaneMemory; 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, diff --git a/test/terminal.zig b/test/terminal.zig index bad70081..03bcd294 100644 --- a/test/terminal.zig +++ b/test/terminal.zig @@ -82,9 +82,10 @@ fn lineBreaks(comptime n: usize) [2 * n]u8 { test "replay ownership is terminal-only and construction rolls back on allocation failure" { const Case = struct { fn run(gpa: std.mem.Allocator, terminal: bool) !void { - const pane = if (terminal) try panes.createTerminal(gpa, 40, 12) else try panes.createDoc(gpa, 40, 12); + var outside: Term.Outside = .{}; + const pane = if (terminal) try panes.createTerminal(&outside, gpa, 40, 12) else try panes.createDoc(gpa, 40, 12); defer gpa.destroy(pane); - defer if (pane.terminal) |state| close(state, gpa); + defer if (pane.terminal) |state| close(&outside, state); try std.testing.expectEqual(terminal, pane.terminal != null); } }; @@ -98,7 +99,6 @@ test "document construction allocates only the pane and has inert terminal defau const allocator = failing.allocator(); const pane = try panes.createDoc(allocator, 40, 12); defer allocator.destroy(pane); - defer if (pane.terminal) |state| close(state, allocator); try std.testing.expect(pane.terminal == null); try std.testing.expectEqual(@as(usize, 1), failing.alloc_index); try std.testing.expectEqual(@as(usize, 0), failing.resize_index); @@ -109,7 +109,7 @@ test "document construction allocates only the pane and has inert terminal defau try std.testing.expectEqual(Term.Prompt{}, prompt(pane.terminal)); pane.scrollBy(100); pane.followOutput(); - pane.resizeGrid(0, 80, 24); + pane.resizeGrid(undefined, 80, 24); // no terminal: the core is never read try std.testing.expectEqual(Term.Grid{}, grid(pane.terminal)); try std.testing.expectEqualStrings("", try scrollback(pane.terminal, allocator)); try std.testing.expect(!failing.has_induced_failure); |
