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/session.zig | |
| 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/session.zig')
| -rw-r--r-- | test/session.zig | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/session.zig b/test/session.zig index 8b3c5c41..aa6288ff 100644 --- a/test/session.zig +++ b/test/session.zig @@ -182,6 +182,61 @@ pub const Session = struct { fn pardesOf(s: *Session) *Pardes { return @ptrCast(@alignCast(s.core)); } + + // ninep: + + /// An open kept until `clunk`, as an event reader or a lock holder + /// keeps one. + pub const Fid = struct { node: u64, handle: u32 }; + + /// `path` opened (omode 0 read, 1 write, 2 both) and held. + pub fn hold(s: *Session, path: []const u8, omode: u8) !Fid { + const node, const h = try s.open(path, omode); + return .{ .node = node, .handle = h }; + } + + /// One read on a held open (an event record, an answer). + pub fn readFid(s: *Session, f: Fid) ![]const u8 { + const r = s.serve(.{ .tag = 0, .op = .read, .node = f.node, .handle = f.handle, .size = 1 << 16 }); + if (r.status != .ok) return refusal("a held open", r); + return s.arena.allocator().dupe(u8, pardesOf(s).fsPayload(r)); + } + + /// One write on a held open: 0 when taken, else its errno, its words in `said`. + pub fn writeFid(s: *Session, f: Fid, data: []const u8) !u16 { + const r = s.serve(.{ .tag = 0, .op = .write, .node = f.node, .handle = f.handle, .data = data }); + if (r.status == .ok) return 0; + s.said = try s.arena.allocator().dupe(u8, r.ename); + return r.errno; + } + + pub fn clunk(s: *Session, f: Fid) void { + _ = s.serve(.{ .tag = 0, .op = .release, .node = f.node, .handle = f.handle, .opened = true }); + } + + /// A held open's file truncated, as an OTRUNC open (`> data`) does. + pub fn truncate(s: *Session, f: Fid) !void { + const r = s.serve(.{ .tag = 0, .op = .setattr, .node = f.node, .truncate = true }); + if (r.status != .ok) return refusal("truncate", r); + } + + /// One read of `size` bytes at `off`, on an open of its own. + pub fn readAt(s: *Session, path: []const u8, off: u64, size: u32) ![]const u8 { + const f = try s.hold(path, 0); + defer s.clunk(f); + const r = s.serve(.{ .tag = 0, .op = .read, .node = f.node, .handle = f.handle, .off = off, .size = size }); + if (r.status != .ok) return refusal(path, r); + return s.arena.allocator().dupe(u8, pardesOf(s).fsPayload(r)); + } + + /// What a stat of `path` answers: its size, mode and qid version. + pub fn stat(s: *Session, path: []const u8) !struct { size: u64, mode: u16, version: u32 } { + const f = try s.hold(path, 0); + defer s.clunk(f); + const r = s.serve(.{ .tag = 0, .op = .getattr, .node = f.node }); + if (r.status != .ok) return refusal(path, r); + return .{ .size = r.attr.size, .mode = r.attr.mode, .version = r.attr.version }; + } }; fn refusal(path: []const u8, r: Reply) error{Refused} { |
