diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 14:48:26 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 15:14:31 -0300 |
| commit | 7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb (patch) | |
| tree | a6add92cd4dcbbf4c31cd1ce989d99b190258353 /anim/test | |
| parent | ed46c51fe127377eb1fde8dee83da984e0f61860 (diff) | |
| download | computeranim-7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb.tar.gz computeranim-7e9bf9e6e85c6c6e7a400d4fa0b43b77133ed3cb.zip | |
canim: animations of recordings, as a debugger's whole context with a lens beside it
A package of its own (anim/), on sketchbook's anim module and pardes's
syntax. A scene opens a recording, takes a cursor into it, and declares
blocks that read the moment the cursor is at: the state column (registers
each followed as a pointer and inked by where it points, the stack
telescope, the backtrace), the program column (the whole source, the
disassembly in address order, and the scene's lens: a node-link list over
a hexdump of its heap, array cells, a call tree, a syscall crossing), and
ties between them. Motion is a step told as a sentence (the line fires,
its effects cascade a level at a time, the mark moves on last), timed by
what the step contains; walk, hurry and sprint pace a loop. Five scenes
from real recordings of fib, a linked list, a sort and syscalls.
First drafts, by the agent's own handover: the frame of the design's
second revision, the hexdump lens and the ties; no disassembly
annotations, no gallery, scenes not yet reviewed against the mocks.
Diffstat (limited to 'anim/test')
| -rw-r--r-- | anim/test/fib.script | 11 | ||||
| -rw-r--r-- | anim/test/list.script | 11 | ||||
| -rw-r--r-- | anim/test/recordings.zig | 101 | ||||
| -rw-r--r-- | anim/test/sort.script | 11 | ||||
| -rw-r--r-- | anim/test/syscalls.script | 11 | ||||
| -rw-r--r-- | anim/test/title.script | 4 | ||||
| -rw-r--r-- | anim/test/zoom.script | 11 |
7 files changed, 160 insertions, 0 deletions
diff --git a/anim/test/fib.script b/anim/test/fib.script new file mode 100644 index 0000000..a300d19 --- /dev/null +++ b/anim/test/fib.script @@ -0,0 +1,11 @@ +# The fib scene, headless: it runs to three instants of its timeline without failing. +# (The pixel assertions written for the first layout were dropped when the +# frame became the debugger's context; new ones want a settled design: see anim/README.md.) +frames 2 +console set playing false +console set t 5 +screenshot .zig-cache/canim/fib-early.png +console set t 14 +screenshot .zig-cache/canim/fib-mid.png +console set t 999 +screenshot .zig-cache/canim/fib-end.png diff --git a/anim/test/list.script b/anim/test/list.script new file mode 100644 index 0000000..7f4bcbb --- /dev/null +++ b/anim/test/list.script @@ -0,0 +1,11 @@ +# The list scene, headless: it runs to three instants of its timeline without failing. +# (The pixel assertions written for the first layout were dropped when the +# frame became the debugger's context; new ones want a settled design: see anim/README.md.) +frames 2 +console set playing false +console set t 5 +screenshot .zig-cache/canim/list-early.png +console set t 14 +screenshot .zig-cache/canim/list-mid.png +console set t 999 +screenshot .zig-cache/canim/list-end.png diff --git a/anim/test/recordings.zig b/anim/test/recordings.zig new file mode 100644 index 0000000..ef97d31 --- /dev/null +++ b/anim/test/recordings.zig @@ -0,0 +1,101 @@ +//! canim on its real recordings (made by the build, under ztrace's +//! debugger): finding moments, what a step changed, calls, pointers +//! followed, and the cursor's timetable for a step. +const std = @import("std"); +const canim = @import("canim"); +const anim = @import("anim"); +const recordings = @import("recordings"); + +const Recording = canim.Recording; +const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; + +test "steps by line stop on lines of the program's own source, and no step stands still" { + inline for (.{ recordings.steps, recordings.hello, recordings.sort, recordings.list }) |program| { + const rec = canim.open(program); + var at = rec.call("main", 0).enter; + var stops: usize = 0; + while (at < rec.end() and stops < 400) : (stops += 1) { + const next = rec.next(.line, at); + try expect(next > at); + if (next < rec.end()) try expect(rec.reached[next]); + at = next; + } + try expect(stops > 4); + } +} + +test "calls are a tree: fib(5) makes fifteen, each with what it was given and gave back" { + const rec = canim.open(recordings.steps); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const nodes = try canim.calls.layout(arena.allocator(), rec, "fib"); + try expectEqual(@as(usize, 15), nodes.len); + try expectEqual(@as(?u64, 5), rec.call("fib", 0).arg); + try expectEqual(@as(u64, 5), rec.call("fib", 0).result); + try expectEqual(@as(?u64, 1), rec.call("fib", 4).arg); + // A node is where it will always be: a parent over the middle of its children. + for (nodes) |n| if (n.parent) |p| try expect(nodes[p].level + 1 == n.level); +} + +test "an instrumented program under the debugger tells its calls, variables and stores" { + const rec = canim.open(recordings.list); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const reverse = rec.call("reverse", 0); + try expectEqual(@as(usize, 3), rec.allocations.len); + // The call begins where the debugger stopped on entering it: the line of its header. + try expectEqual(@as(u32, 17), rec.own[reverse.enter]); + // A local is not its value until its call has stored to it. + const first = rec.lineMoment(18, reverse.enter); + const cur = rec.variable(arena.allocator(), rec.moment(first), "cur").?; + try expect(!rec.assigned(cur, first)); + try expect(rec.assigned(cur, rec.lineMoment(21, reverse.enter))); + // Three nodes are reached from the program's pointers, each in the place its allocation gives it. + const things = canim.objects.reach(arena.allocator(), rec, rec.moment(rec.lineMoment(21, reverse.enter)), null); + try expectEqual(@as(usize, 3), things.len); + for (things) |o| try expect(o.slot.? < 3); +} + +test "the program's four system calls are found, with what each was given" { + const rec = canim.open(recordings.hello); + var names: [4][]const u8 = undefined; + var n: usize = 0; + for (rec.syscalls) |call| { + if (call.enter < rec.call("main", 0).enter or n == names.len) continue; + names[n] = @import("ztrace").syscalls.name(call.nr) orelse "?"; + n += 1; + } + try expectEqual(@as(usize, 4), n); + try std.testing.expectEqualStrings("open", names[0]); + try std.testing.expectEqualStrings("read", names[1]); + try std.testing.expectEqualStrings("close", names[2]); + try std.testing.expectEqualStrings("write", names[3]); +} + +test "a walked step is as long as what it changed: fire, a slot a level, the hold, the advance, the rest" { + const rec = canim.open(recordings.steps); + const scene = struct { + var at: canim.Cursor = undefined; + fn frame(s: *anim.Frame) void { + const r = canim.open(recordings.steps); + at = canim.cursor(s, r, r.lineMoment(10, r.call("main", 0).enter)); + at.levels = .{ .idea = .calls }; + } + }; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var frame: anim.Frame = .{ .t = 0, .clock = 0, .in = undefined, .pointer = .{ 0, 0 }, .arena = arena.allocator() }; + scene.frame(&frame); + const t = canim.theme.time; + // main's line calls fib(5): registers, the stack, the call. Three levels, 0.30 s apart. + const from = rec.lineMoment(10, rec.call("main", 0).enter); + const call = scene.at.reading(from, rec.next(.line, from)); + try std.testing.expectApproxEqAbs(@as(f32, 3 * t.cascade), call.at[2], 1e-4); + try expect(call.total > 2.0 and call.total < 3.0); + // A line that changes nothing shown: fire, advance, rest. + var quiet = scene.at; + quiet.levels = .{ .cpu = false, .memory = false }; + const line = quiet.reading(rec.lineMoment(4, from), rec.lineMoment(6, from)); + try std.testing.expectApproxEqAbs(t.fire + t.step + t.rest + t.step_per_row, line.total, 1e-3); +} diff --git a/anim/test/sort.script b/anim/test/sort.script new file mode 100644 index 0000000..4823051 --- /dev/null +++ b/anim/test/sort.script @@ -0,0 +1,11 @@ +# The sort scene, headless: it runs to three instants of its timeline without failing. +# (The pixel assertions written for the first layout were dropped when the +# frame became the debugger's context; new ones want a settled design: see anim/README.md.) +frames 2 +console set playing false +console set t 5 +screenshot .zig-cache/canim/sort-early.png +console set t 14 +screenshot .zig-cache/canim/sort-mid.png +console set t 999 +screenshot .zig-cache/canim/sort-end.png diff --git a/anim/test/syscalls.script b/anim/test/syscalls.script new file mode 100644 index 0000000..cb9d2f4 --- /dev/null +++ b/anim/test/syscalls.script @@ -0,0 +1,11 @@ +# The syscalls scene, headless: it runs to three instants of its timeline without failing. +# (The pixel assertions written for the first layout were dropped when the +# frame became the debugger's context; new ones want a settled design: see anim/README.md.) +frames 2 +console set playing false +console set t 5 +screenshot .zig-cache/canim/syscalls-early.png +console set t 14 +screenshot .zig-cache/canim/syscalls-mid.png +console set t 999 +screenshot .zig-cache/canim/syscalls-end.png diff --git a/anim/test/title.script b/anim/test/title.script new file mode 100644 index 0000000..9207ea6 --- /dev/null +++ b/anim/test/title.script @@ -0,0 +1,4 @@ +frames 2 +console set playing false +console set t 999 +screenshot .zig-cache/canim/title-end.png diff --git a/anim/test/zoom.script b/anim/test/zoom.script new file mode 100644 index 0000000..d508bb0 --- /dev/null +++ b/anim/test/zoom.script @@ -0,0 +1,11 @@ +# The zoom scene, headless: it runs to three instants of its timeline without failing. +# (The pixel assertions written for the first layout were dropped when the +# frame became the debugger's context; new ones want a settled design: see anim/README.md.) +frames 2 +console set playing false +console set t 5 +screenshot .zig-cache/canim/zoom-early.png +console set t 14 +screenshot .zig-cache/canim/zoom-mid.png +console set t 999 +screenshot .zig-cache/canim/zoom-end.png |
