diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/behaviour/addons.zig | 46 | ||||
| -rw-r--r-- | test/fs_namespace.zig | 4 | ||||
| -rw-r--r-- | test/mode.zig | 2 | ||||
| -rw-r--r-- | test/panes.zig | 10 | ||||
| -rw-r--r-- | test/replicas.zig | 3 | ||||
| -rw-r--r-- | test/session.zig | 23 |
6 files changed, 75 insertions, 13 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index c91bda1a..523aefb9 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -33,12 +33,12 @@ fn unload(s: *Session, name: []const u8) void { test "addons: Addon load takes a library in, /addons lists it with the kinds compiled in, its words join /commands and Help, and Addon unload lets it go" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); - try std.testing.expect(has(try s.read("/addons"), "image 1 1.0 0 - - static\n")); + try std.testing.expect(has(try s.read("/addons"), "image 1 2.0 0 - - static\n")); try load(&s, fake.ok); defer unload(&s, "fake"); // `<kind> <version> <abi> <panes open> <path> <blake3> <state>`. const listed = try s.read("/addons"); - const at = std.mem.indexOf(u8, listed, "\nfake 1 1.0 0 /").?; + const at = std.mem.indexOf(u8, listed, "\nfake 1 2.0 0 /").?; var fields = std.mem.tokenizeScalar(u8, listed[at + 1 .. std.mem.indexOfScalarPos(u8, listed, at + 1, '\n').?], ' '); for (0..5) |_| _ = fields.next(); try std.testing.expectEqual(@as(usize, 64), fields.next().?.len); @@ -52,7 +52,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com // A pane of it open, it stays; closed, it goes. try s.write("/ctl", "Fake\n"); const pane = try paneOf(&s, "fake"); - try std.testing.expect(has(try s.read("/addons"), "\nfake 1 1.0 1 /")); + try std.testing.expect(has(try s.read("/addons"), "\nfake 1 2.0 1 /")); try std.testing.expect(try s.refused("/ctl", "Addon unload fake\n") != 0); try std.testing.expect(has(s.said, "1 fake pane is open")); try s.write(s.at("/pane/{d}/ctl", .{pane}), "Del\n"); @@ -69,10 +69,10 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose defer s.deinit(); for ([_][]const u8{ fake.abi, fake.no_export, fake.core_word }) |path| try load(&s, path); const listed = try s.read("/addons"); - try std.testing.expect(has(listed, "\nfakeabi 1 2.0 0 /")); - try std.testing.expect(has(listed, " refused: wants abi 2, this pardes speaks 1\n")); + try std.testing.expect(has(listed, "\nfakeabi 1 3.0 0 /")); + try std.testing.expect(has(listed, " refused: wants abi 3, this pardes speaks 2\n")); try std.testing.expect(has(listed, " refused: it has no pardes_addon\n")); - try std.testing.expect(has(listed, "\nfakeword 1 1.0 0 /")); + try std.testing.expect(has(listed, "\nfakeword 1 2.0 0 /")); try std.testing.expect(has(listed, " refused: word Save is the core's\n")); // A file that is no library at all: listed with what the loader said. var tmp = std.testing.tmpDir(.{}); @@ -189,6 +189,40 @@ test "addons: Addon reload moves every pane of the kind to the library as it is try std.testing.expect(!std.mem.eql(u8, before, try s.read("/addons"))); } +test "addons: a job under way across a reload answers into nothing, its library kept until it has; the reloaded pane's own jobs land" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + const copy = struct { + fn of(ss: *Session, d: std.Io.Dir, from: []const u8) !void { + try d.writeFile(std.testing.io, .{ .sub_path = "fake.so", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, from, ss.arena.allocator(), .limited(64 << 20)) }); + } + }.of; + try copy(&s, tmp.dir, fake.ok); + try s.write("/ctl", s.at("Addon load {s}/fake.so\n", .{dir})); + defer unload(&s, "fake"); + try s.write("/ctl", "Fake\n"); + const pane = try paneOf(&s, "fake"); + try s.write(s.at("/pane/{d}/ctl", .{pane}), "FakeBump 5\n"); + // A job taken by a worker, still running as the library is replaced + // by another (one with no record: the pane comes back at its place, 5, + // then its words' last values, FakeBump 5: 10). + s.hold_jobs = true; + try s.write(s.at("/pane/{d}/ctl", .{pane}), "FakeJob\n"); + try copy(&s, tmp.dir, fake.no_dump); + try s.write("/ctl", "Addon reload fake\n"); + try std.testing.expect(has(try s.screen(), "count 10 ")); + // It answers now, from the old library's code: of another generation, + // the answer is dropped, and the old library goes after it. + s.releaseJobs(); + try std.testing.expect(has(try s.screen(), "count 10 ")); + try s.write(s.at("/pane/{d}/ctl", .{pane}), "FakeJob\n"); + try std.testing.expect(has(try s.screen(), "count 16 ")); +} + test "addons: a Look at a file whose extension an addon claims opens a pane of its kind, and its words are in Help" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig index ac638e41..939232fc 100644 --- a/test/fs_namespace.zig +++ b/test/fs_namespace.zig @@ -303,8 +303,8 @@ test "images decode through explicit filesystem mounts, and a dump reads one on defer p.deinit(); var arena = std.heap.ArenaAllocator.init(gpa); defer arena.deinit(); - // Its decode lands at the step after it (a job, run here at once). - p.update(.tick); + // Its decode is a job its host runs: here, at once. + while (p.nextEffect()) |e| p.perform(e); _ = try p.render(arena.allocator()); const shown = p.surface.placements.items; try std.testing.expectEqual(@as(usize, 1), shown.len); diff --git a/test/mode.zig b/test/mode.zig index 86de0488..a03d9dc1 100644 --- a/test/mode.zig +++ b/test/mode.zig @@ -92,7 +92,7 @@ test "Mode from actual tag Exec preserves parked file and output insert transact test "Mode leaves image and PDF document modes unchanged" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); - const picture = try pardes.Kind.open(p, 1, &panes.Image.kind, "/mode-test.png", ""); + const picture = try pardes.Kind.open(p, 1, pardes.Kind.image, "/mode-test.png", ""); try mode(p, 1, .normal); try std.testing.expect(picture.addon != null); if (comptime panes.Pdf.enabled) { diff --git a/test/panes.zig b/test/panes.zig index f51c2b27..2a24e62e 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -2250,7 +2250,15 @@ const ImageTests = struct { test "pane-local renderer choices are visible in the image tag" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); - const pane = try pardes.Kind.open(p, p.freeSlot().?, &image.kind, "/tmp/picture.ppm", null); + pardes.image.start(std.testing.io, std.testing.allocator); + defer pardes.image.stop(); + // A picture shown (its decode landed, a frame drawn): the core's + // art words after the kind's `img`, then its path. + const id = p.freeSlot().?; + const pane = try pardes.Kind.open(p, id, pardes.Kind.image, "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03"); + while (p.nextEffect()) |e| p.perform(e); + pardes.exec.placeNew(p, 0, 0, id, .doc); + _ = try p.render(p.scratch.allocator()); pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false }; try std.testing.expectEqualStrings( config.tag_image ++ " petscii:on palette:terminal ascii:off /tmp/picture.ppm", diff --git a/test/replicas.zig b/test/replicas.zig index 280b85f4..338dae16 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -483,7 +483,8 @@ fn push(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void { fn flushAll(sc: *replica.Screens, core: *pardes.Pardes, ps: []const u16, list: *std.ArrayListUnmanaged([]u8), q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, now: u64, dl: []Link, rnd: std.Random, ow: u64, jt: u64, vs: *std.AutoHashMapUnmanaged(u64, u64), tot: *Totals) !void { for (ps, 0..) |peer, c| { list.clearRetainingCapacity(); - try sc.flush(core, peer, list); + // No pane of a kind here: the view a Shadow is painted for is moot. + try sc.flush(core, peer, 0, list); for (list.items) |bytes| { tot.deltas += 1; tot.delta_bytes += bytes.len; diff --git a/test/session.zig b/test/session.zig index 87bf784e..4919c0a3 100644 --- a/test/session.zig +++ b/test/session.zig @@ -34,6 +34,11 @@ pub const Session = struct { /// What the language words' questions are asked of their servers /// through (initLanguage); none, and they go unanswered. languages: ?std.Io = null, + /// Kinds' jobs taken as a host's worker takes them and held, not run, + /// until `releaseJobs`: a job under way across what a test does + /// meanwhile (a reload). + hold_jobs: bool = false, + held: std.ArrayList(*pardes.host_io.KindJob) = .empty, /// A session showing one file pane holding `text`, keeping what outlives /// it in a database in memory (src/Db.zig). @@ -87,8 +92,8 @@ pub const Session = struct { } pub fn deinit(s: *Session) void { + s.held.deinit(pardesOf(s).gpa); pardesOf(s).deinit(); - pardes.Addon.unloadAll(); s.arena.deinit(); } @@ -229,12 +234,26 @@ pub const Session = struct { .save_file, .save_text => s.saved += 1, // Into the session's state (a database in memory, or its file). .write_dump => pardes.host_io.writeDump(pardesOf(s), pardesOf(s).dump_out.?), - .addon => |a| pardes.Addon.perform(pardesOf(s), a.op, a.pane, a.arg.slice()), + .addon => pardesOf(s).perform(e), + // A kind's job, here and at once, as the host's worker would; + // held while a test holds them (`hold_jobs`). + .job => |j| if (!s.hold_jobs) pardesOf(s).perform(e) else if (pardes.host_io.KindJob.take(pardesOf(s), j.pane, j.serial, j.token)) |taken| s.held.append(pardesOf(s).gpa, taken) catch taken.drop(), .lsp => |q| if (s.languages) |io| s.askServer(io, .{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }), else => {}, }; } + /// The jobs held, run now and answered as the host's workers would. + pub fn releaseJobs(s: *Session) void { + s.hold_jobs = false; + for (s.held.items) |j| { + j.run(); + j.land(pardesOf(s)); + } + s.held.clearRetainingCapacity(); + s.drain(); + } + /// A language word's question asked of its server as a host asks it /// (host_io.Lsp), here and at once: its answer the core's next event. fn askServer(s: *Session, io: std.Io, req: pardes.host_io.Lsp.Request) void { |
