diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 00:01:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 30a603341e3b23da6e5ab5995b060c8e4ec52242 (patch) | |
| tree | 9a24941b147a5265e6b0726285e9501cd7b61c6d /test | |
| parent | afc60e735274b0de5423ac375a9ea582f64b516f (diff) | |
| download | pardes-30a603341e3b23da6e5ab5995b060c8e4ec52242.tar.gz pardes-30a603341e3b23da6e5ab5995b060c8e4ec52242.zip | |
test: the GPU move's gates, sharper: a window the harness starts runs under PARDES_TEST_WRAP when it names a command (perf stat, a script), given the window's argv, its binary made absolute; a test window's series keeps its frames as PAM (P7 RGB_ALPHA), so the corpus sees the alpha a blend writes (latest.ppm and every other capture stay RGB); the corpus adds a translucent addon picture, test/veil.zig (zig build veil: a GPU pass that clears to half alpha and draws nothing), for the addon pipeline's colour factor, which the snake's opaque picture never showed; the snake's window ends with its pane gone and at rest, so it ends having drawn as many frames every run
Diffstat (limited to 'test')
| -rw-r--r-- | test/process.zig | 22 | ||||
| -rw-r--r-- | test/process/window.zig | 24 | ||||
| -rw-r--r-- | test/veil.zig | 37 |
3 files changed, 71 insertions, 12 deletions
diff --git a/test/process.zig b/test/process.zig index 67d883ca..126a7924 100644 --- a/test/process.zig +++ b/test/process.zig @@ -616,12 +616,22 @@ pub const Detached = struct { try std.fmt.bufPrintSentinel(&bufs[1], "--9p={s}", .{opts.socket orelse name}, 0) else try std.fmt.bufPrintSentinel(&bufs[1], "--detach={s}", .{name}, 0); + // PARDES_TEST_WRAP: a command a window runs under (`perf stat ...`, + // a script), given the window's own argv; the binary made absolute, + // as the child runs elsewhere. + const wrap = if (gui) std.c.getenv("PARDES_TEST_WRAP") else null; + var exe_buf: [4096]u8 = undefined; var argv: [24][:0]const u8 = undefined; - if (opts.args.len + 3 > argv.len) return error.TooManyArgs; - argv[0] = exe; - argv[1] = first; - for (opts.args, 0..) |a, k| argv[2 + k] = a; - argv[2 + opts.args.len] = fixture; + if (opts.args.len + 4 > argv.len) return error.TooManyArgs; + var at: usize = 0; + if (wrap) |w| { + argv[0] = std.mem.span(w); + at = 1; + } + argv[at] = if (wrap != null) std.mem.span(realpath(exe, &exe_buf) orelse return error.NoBinary) else exe; + argv[at + 1] = first; + for (opts.args, 0..) |a, k| argv[at + 2 + k] = a; + argv[at + 2 + opts.args.len] = fixture; var grid_buf: [2][8]u8 = undefined; var env: [16][2][:0]const u8 = undefined; var n: usize = 0; @@ -641,7 +651,7 @@ pub const Detached = struct { env[n] = kv; n += 1; } - d.child = try Child.spawn(argv[0 .. 3 + opts.args.len], .{ + d.child = try Child.spawn(argv[0 .. at + 3 + opts.args.len], .{ .root = dir, .env = env[0..n], // A window runs on a terminal of its own, as one started from a diff --git a/test/process/window.zig b/test/process/window.zig index e39e0963..687b9000 100644 --- a/test/process/window.zig +++ b/test/process/window.zig @@ -197,7 +197,8 @@ extern "c" fn system(cmd: [*:0]const u8) c_int; extern "c" fn ioctl(fd: c_int, request: c_ulong, ...) c_int; /// The frames a corpus keeps (`corpus`): numbered in the order kept, each -/// with its sha256 (sha256sum's lines) and its scene. +/// a PAM with its alpha (the window's series), with its sha256 (sha256sum's +/// lines) and its scene. const Corpus = struct { gpa: std.mem.Allocator, a: std.mem.Allocator, @@ -268,11 +269,11 @@ const Corpus = struct { fn take(k: *Corpus, d: *process.Detached, lo: u32, hi: u32, label: []const u8) !void { for (lo..hi) |i| { - const bytes = try process.readWhole(k.gpa, k.at("{s}/frame-{d:0>5}.ppm", .{ d.captures(), i })); + const bytes = try process.readWhole(k.gpa, k.at("{s}/frame-{d:0>5}.pam", .{ d.captures(), i })); defer k.gpa.free(bytes); var digest: [32]u8 = undefined; std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{}); - const name = k.at("frame-{d:0>5}.ppm", .{k.n}); + const name = k.at("frame-{d:0>5}.pam", .{k.n}); try process.writeFile(k.a, k.at("{s}/{s}", .{ k.out, name }), bytes); try k.sums.print(k.a, "{x} {s}\n", .{ digest, name }); try k.scenes.print(k.a, "{d:0>5} {s}\n", .{ k.n, label }); @@ -284,7 +285,7 @@ const Corpus = struct { fn prune(k: *Corpus, d: *process.Detached, below: u32) void { while (k.pruned < below) : (k.pruned += 1) { - const path = std.fmt.allocPrintSentinel(k.a, "{s}/frame-{d:0>5}.ppm", .{ d.captures(), k.pruned }, 0) catch return; + const path = std.fmt.allocPrintSentinel(k.a, "{s}/frame-{d:0>5}.pam", .{ d.captures(), k.pruned }, 0) catch return; _ = std.c.unlink(path); } } @@ -384,8 +385,8 @@ fn corpusRoot(a: std.mem.Allocator) !void { /// frame corpus. Twelve scenes on the hidden window under the virtual /// clock, each step one input (a 9P write, or one event on its terminal) /// and then idle; the frames a step keeps go to PARDES_GUI_CORPUS as -/// frame-NNNNN.ppm, their sha256 in frames.sha256 (sha256sum's lines), -/// their scenes in scenes.txt. Two builds' corpora on one machine are the +/// frame-NNNNN.pam (RGBA: a blend's alpha too), their sha256 in +/// frames.sha256 (sha256sum's lines), their scenes in scenes.txt. Two builds' corpora on one machine are the /// same bytes, or the renderer changed: a GPU and its driver draw their own /// pixels, so it gates a build against a build, never a machine. /// PARDES_GUI_CORPUS_SNAKE is the snake_shader addon (`zig build @@ -501,6 +502,12 @@ fn corpus(gpa: std.mem.Allocator, exe: [:0]const u8) !void { var ws: std.posix.winsize = .{ .row = 20, .col = 70, .xpixel = 0, .ypixel = 0 }; if (ioctl(d.child.master, 0x5414, &ws) != 0) return error.NoResize; // TIOCSWINSZ try k.keep(&d, 0, "12 the window resized to 70x20", false); + // A translucent addon picture (test/veil.zig, beside the snake's + // library): the addon pipeline's colour factor, which the snake's + // opaque picture never shows. + try f.write("/ctl", f.at("Addon load {s}/libveil.so\n", .{std.fs.path.dirname(snake).?})); + try f.write(f.at("/pane/{d}/exec", .{first}), "Veil\n"); + try k.keep(&d, 0, "12 a translucent addon picture over its pane", false); } // 12. The snake: an addon's GPU scene and its CRT post-process, // through the premultiplied pipeline. A window of its own: its picture @@ -519,8 +526,13 @@ fn corpus(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try f.write("/ctl", f.at("Addon load {s}\n", .{snake})); try k.keep(&d, 0, "12 the snake addon loaded", false); const from = try k.mark(&d); + const before = try f.read("/index"); try f.write(f.at("/pane/{d}/exec", .{first}), "SnakeShader\n"); try k.first(&d, from, 10, "12 SnakeShader's CRT scene, its first frames"); + // Then gone, and the window at rest: it ends having drawn as many + // frames every run (an instruction count's, perfwrap.sh). + try f.write(f.at("/pane/{d}/exec", .{try paneSince(f, before)}), "Del\n"); + _ = try k.rest(&d); } // 2. Scene 1 at a 2x display. k.pruned = 0; diff --git a/test/veil.zig b/test/veil.zig new file mode 100644 index 00000000..ed49e1c3 --- /dev/null +++ b/test/veil.zig @@ -0,0 +1,37 @@ +//! A test addon whose GPU picture is translucent: its pass draws nothing +//! and clears to a premultiplied half-alpha colour, so the window's addon +//! pipeline blends it over the pane (the frame corpus's case for the +//! pipeline's colour factor, which an opaque picture never shows). +const std = @import("std"); +const addon = @import("addon"); +const scene = @import("gpu_scene"); + +pub const Veil = extern struct { + painted: u32, + + pub const head: addon.Head = .{ .name = "veil", .version = 1, .words = &.{ + .{ .name = "Veil", .opens = true, .doc = "a translucent GPU picture over the pane (a test addon)" }, + } }; + + pub fn open(v: *Veil, _: ?[]const u8, _: ?[]const u8) void { + v.painted = 0; + } + + pub fn paint(_: *const Veil, w: addon.Window, out: addon.Paint) void { + w.put(0, 0, "veil over this", .{}); + const width: u32 = @min(4096, @max(1, @as(u32, w.cols) * w.cell_w)); + const height: u32 = @min(4096, @max(1, @as(u32, w.rows) * w.cell_h)); + var buffer: [256]u8 = undefined; + var writer: std.Io.Writer = .fixed(&buffer); + scene.encode(&writer, .{ .image = .none, .width = width, .height = height, .clear = .{ 0.30, 0.10, 0.20, 0.5 }, .pipelines = &.{}, .draws = &.{} }) catch return; + _ = out.gpu(writer.buffered()); + } + + pub const dump = addon.dumpBytes; + pub const load = addon.loadBytes; +}; + +pub const pardes_addon = addon.ops(Veil); +comptime { + addon.exportLib(&pardes_addon); +} |
