diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 17:19:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 17:19:46 -0300 |
| commit | d20a480e5d556b522aedfc7ec67fa423f37c8d1d (patch) | |
| tree | 8b5e333fef2f37997b1420831aaf204f20e346a3 /test/behaviour | |
| parent | 023793be1112bc35b50551580d273f4cf611b3da (diff) | |
| download | pardes-d20a480e5d556b522aedfc7ec67fa423f37c8d1d.tar.gz pardes-d20a480e5d556b522aedfc7ec67fa423f37c8d1d.zip | |
test: four more of src/ninep/ctl.zig's tests through the 9P tree alone, on opens a test holds: Session's hold, readFid, writeFid and clunk (and truncate, readAt and stat for the pane files' tests next), an open kept as an event reader or a lock holder keeps one; lock and unlock on one ctl open against another (test/behaviour/panes), the event reader taking a pane's look, exec and tag clicks and acting on them written back, a refused Del written back EIO (new test/behaviour/event), /pager answering on the open that asked (other_files); each checked to fail against a break: another open's lock taken, a reader never taking a click, an event write-back's failure not captured, /pager answering the session's last result; the old pager test's two-line write refused is a handle-less write's alone (an open takes the second line as the text) and is gone
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/event.zig | 55 | ||||
| -rw-r--r-- | test/behaviour/other_files.zig | 42 | ||||
| -rw-r--r-- | test/behaviour/panes.zig | 44 |
3 files changed, 141 insertions, 0 deletions
diff --git a/test/behaviour/event.zig b/test/behaviour/event.zig new file mode 100644 index 00000000..8aebe8f4 --- /dev/null +++ b/test/behaviour/event.zig @@ -0,0 +1,55 @@ +//! docs/typ/reference.typ, event <event>. +const std = @import("std"); +const Session = @import("session").Session; + +fn has(hay: []const u8, needle: []const u8) bool { + return std.mem.indexOf(u8, hay, needle) != null; +} + +test "event: a pane's own look and exec go to the event reader holding it, which writes them back to act" { + var s = try Session.initFile(std.testing.allocator, "Msg routed\n"); + defer s.deinit(); + const n = try s.focused(); + const ev = try s.hold(s.at("/pane/{d}/event", .{n}), 2); + try s.write(s.at("/pane/{d}/exec", .{n}), "Msg routed\n"); + // Not done: the reader has it, as it would a middle click. + try std.testing.expect(!has(try s.read("/log"), "routed")); + const record = try s.readFid(ev); + // Flag 1: its first word is a builtin; no 2, no expansion follows. + try std.testing.expectEqualStrings("FX0 0 1 10 Msg routed\n", record); + // Written back, it is done. + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ev, record)); + try std.testing.expect(has(try s.read("/log"), s.at("msg {d} routed\n", .{n}))); + try s.write(s.at("/pane/{d}/look", .{n}), "one.txt:3\n"); + try std.testing.expectEqualStrings("FL0 0 4 9 one.txt:3\n", try s.readFid(ev)); + // The root's is a click at the pane with the keyboard, this one. + try s.write("/exec", "Msg rooted\n"); + try std.testing.expect(!has(try s.read("/log"), "rooted")); + try std.testing.expectEqualStrings("FX0 0 1 10 Msg rooted\n", try s.readFid(ev)); + // A click in its tag is the reader's too, an `x` record, as acme's is; + // written back, it is done. + try s.write(s.at("/pane/{d}/tagexec", .{n}), "Msg tagged\n"); + try std.testing.expect(!has(try s.read("/log"), "tagged")); + const tagged = try s.readFid(ev); + try std.testing.expectEqualStrings("Fx0 0 1 10 Msg tagged\n", tagged); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ev, tagged)); + try std.testing.expect(has(try s.read("/log"), s.at("msg {d} tagged\n", .{n}))); + s.clunk(ev); + // With no reader, the root's and the pane's act at once. + try s.write(s.at("/pane/{d}/exec", .{n}), "Msg direct\n"); + try std.testing.expect(has(try s.read("/log"), s.at("msg {d} direct\n", .{n}))); +} + +test "event: a refused Del written back through event fails that write, EIO, with its err" { + var s = try Session.initFile(std.testing.allocator, "text\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/body", .{n}), "more\n"); // unsaved + const ev = try s.hold(s.at("/pane/{d}/event", .{n}), 2); + defer s.clunk(ev); + try s.write(s.at("/pane/{d}/exec", .{n}), "Del\n"); + const record = try s.readFid(ev); + try std.testing.expectEqual(@as(u16, 5), try s.writeFid(ev, record)); + try std.testing.expect(has(s.said, "Modified")); + _ = try s.read(s.at("/pane/{d}/ctl", .{n})); // still there +} diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index c0f9c08f..8625df3b 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -28,3 +28,45 @@ test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Al try s.keys("i\u{F015}zy\x1b"); try s.expect(s.at("/pane/{d}/body", .{try s.focused()}), "yx\n"); } + +test "other-files: pager answers its +Pager on the open that asked, whatever another client exec'd meanwhile, and refuses a directory it cannot page in" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const asked = try s.hold("/pager", 2); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(asked, "/tmp\n")); + // Another client execs between the request and its read: a pane of its own. + const racer = try s.hold("/exec", 2); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(racer, "New\n")); + s.clunk(racer); + const paged = try s.readFid(asked); + s.clunk(asked); + // A fresh open reads the session's last answer, the racer's pane. + try std.testing.expect(!std.mem.eql(u8, paged, try s.read("/exec"))); + try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, paged, "\n")}), "/tmp/+Pager\n"); + // Refused, an open answers nothing, not the session's last answer. + const refused = try s.hold("/pager", 2); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(refused, "relative\n")); + try std.testing.expectEqualStrings("", try s.readFid(refused)); + s.clunk(refused); + // Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the + // one made above, which keeps its page. + const resolved = try s.hold("/pager", 2); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(resolved, "/tmp/../tmp/.\n")); + const second = try s.readFid(resolved); + s.clunk(resolved); + try std.testing.expect(!std.mem.eql(u8, paged, second)); + try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, second, "\n")}), "/tmp/+Pager\n"); + try s.expect(s.at("/pane/{s}/name", .{std.mem.trimEnd(u8, paged, "\n")}), "/tmp/+Pager\n"); + // One that may not be written is refused, permission denied (Linux's /proc/1). + try std.testing.expectEqual(@as(u16, 1), try s.refused("/pager", "/proc/1\n")); + // One directory an open: one refused is not followed by another, as a + // mount sends two lines in two writes. + const twice = try s.hold("/pager", 2); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(twice, "relative\n")); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(twice, "/tmp\n")); + s.clunk(twice); + try std.testing.expectEqual(@as(u16, 22), try s.refused("/pager", "relative\n")); + try std.testing.expectEqualStrings("pager: invalid directory \"relative\": must be absolute", s.said); + try std.testing.expectEqual(@as(u16, 2), try s.refused("/pager", "/tmp/pardes-surely-missing-dir\n")); + try std.testing.expectEqual(@as(u16, 20), try s.refused("/pager", "/etc/passwd\n")); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index d48ff812..9aa28c6a 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -115,3 +115,47 @@ test "panes: the pane ctl takes acme's verbs and the pane's builtins, and refuse try std.testing.expectEqual(@as(u16, 2), try s.refused(s.at("/pane/{d}/ctl", .{other}), "Del\nMsg after\n")); try std.testing.expectError(error.Refused, s.read(s.at("/pane/{d}/ctl", .{other}))); } + +test "panes: a second lock is refused until the holder unlocks or closes, and binds nobody else" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); + defer s.deinit(); + const n = try s.focused(); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const a = try s.hold(ctl, 2); + const b = try s.hold(ctl, 1); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "lock\n")); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "lock\n")); + // Another open's lock is refused at once, and so is its unlock; writes + // to the pane's other files are not. + try std.testing.expectEqual(@as(u16, 16), try s.writeFid(b, "lock\n")); + try std.testing.expectEqualStrings("file in use: another open of this ctl holds the lock", s.said); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(b, "unlock\n")); + try std.testing.expectEqualStrings("pane not locked by this open", s.said); + try s.write(s.at("/pane/{d}/addr", .{n}), "1"); + try s.write(s.at("/pane/{d}/data", .{n}), "ONE\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "ONE\ntwo\n"); + // Once the holder unlocks, the other's try takes it. + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "unlock\n")); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(b, "lock\n")); + try std.testing.expectEqual(@as(u16, 16), try s.writeFid(a, "lock\nunlock\n")); + // Closing the holder gives it up. + s.clunk(b); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(a, "lock\nunlock\nlock\n")); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(a, "unlock\nunlock\n")); + // Still a's: another open is refused it. + const c = try s.hold(ctl, 1); + try std.testing.expectEqual(@as(u16, 16), try s.writeFid(c, "lock\n")); + s.clunk(c); + // The lock lives and dies with the pane. + const other = try s.newPane(); + const d = try s.hold(s.at("/pane/{d}/ctl", .{other}), 1); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(d, "lock\n")); + try s.write(s.at("/pane/{d}/ctl", .{other}), "Del\n"); + try std.testing.expectEqual(@as(u16, 2), try s.writeFid(d, "lock\n")); + s.clunk(d); + s.clunk(a); + // a's close gave its lock up too. + const e = try s.hold(ctl, 1); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(e, "lock\n")); + s.clunk(e); +} |
