diff options
Diffstat (limited to 'anim/test')
| -rw-r--r-- | anim/test/gallery.script | 8 | ||||
| -rw-r--r-- | anim/test/gallery/atoms.png | bin | 104960 -> 104822 bytes | |||
| -rw-r--r-- | anim/test/gallery/graph-map.png | bin | 0 -> 158401 bytes | |||
| -rw-r--r-- | anim/test/gallery/graph.png | bin | 0 -> 76868 bytes | |||
| -rw-r--r-- | anim/test/gallery/hello.ztrace | bin | 0 -> 86647 bytes | |||
| -rw-r--r-- | anim/test/gallery/loupe.png | bin | 237245 -> 237479 bytes | |||
| -rw-r--r-- | anim/test/gallery/none.png | bin | 226785 -> 226735 bytes | |||
| -rw-r--r-- | anim/test/gallery/rest.png | bin | 233677 -> 233721 bytes | |||
| -rw-r--r-- | anim/test/gallery/rows.png | bin | 140384 -> 140530 bytes | |||
| -rw-r--r-- | anim/test/gallery/sort.ztrace | bin | 0 -> 775616 bytes | |||
| -rw-r--r-- | anim/test/gallery/step.png | bin | 232337 -> 232385 bytes | |||
| -rw-r--r-- | anim/test/gallery/subject.png | bin | 209937 -> 210007 bytes | |||
| -rw-r--r-- | anim/test/recordings.zig | 105 |
13 files changed, 113 insertions, 0 deletions
diff --git a/anim/test/gallery.script b/anim/test/gallery.script index 993ff7e..461f100 100644 --- a/anim/test/gallery.script +++ b/anim/test/gallery.script @@ -31,3 +31,11 @@ console set t 19.8 screenshot {dir}/loupe.png frames 1 expect-same-screenshot {dir}/loupe.png test/gallery/loupe.png 24 0 0 1920 1040 +console set t 21.8 +screenshot {dir}/graph.png +frames 1 +expect-same-screenshot {dir}/graph.png test/gallery/graph.png 24 0 0 1920 1040 +console set t 25.5 +screenshot {dir}/graph-map.png +frames 1 +expect-same-screenshot {dir}/graph-map.png test/gallery/graph-map.png 24 0 0 1920 1040 diff --git a/anim/test/gallery/atoms.png b/anim/test/gallery/atoms.png Binary files differindex 6e64609..8da5c01 100644 --- a/anim/test/gallery/atoms.png +++ b/anim/test/gallery/atoms.png diff --git a/anim/test/gallery/graph-map.png b/anim/test/gallery/graph-map.png Binary files differnew file mode 100644 index 0000000..b16caf6 --- /dev/null +++ b/anim/test/gallery/graph-map.png diff --git a/anim/test/gallery/graph.png b/anim/test/gallery/graph.png Binary files differnew file mode 100644 index 0000000..ea9695e --- /dev/null +++ b/anim/test/gallery/graph.png diff --git a/anim/test/gallery/hello.ztrace b/anim/test/gallery/hello.ztrace Binary files differnew file mode 100644 index 0000000..2ea1f5c --- /dev/null +++ b/anim/test/gallery/hello.ztrace diff --git a/anim/test/gallery/loupe.png b/anim/test/gallery/loupe.png Binary files differindex 346bd44..7f07d94 100644 --- a/anim/test/gallery/loupe.png +++ b/anim/test/gallery/loupe.png diff --git a/anim/test/gallery/none.png b/anim/test/gallery/none.png Binary files differindex 39f0206..bac000d 100644 --- a/anim/test/gallery/none.png +++ b/anim/test/gallery/none.png diff --git a/anim/test/gallery/rest.png b/anim/test/gallery/rest.png Binary files differindex 9dfdbe2..c368a30 100644 --- a/anim/test/gallery/rest.png +++ b/anim/test/gallery/rest.png diff --git a/anim/test/gallery/rows.png b/anim/test/gallery/rows.png Binary files differindex 7e6ba84..dd85690 100644 --- a/anim/test/gallery/rows.png +++ b/anim/test/gallery/rows.png diff --git a/anim/test/gallery/sort.ztrace b/anim/test/gallery/sort.ztrace Binary files differnew file mode 100644 index 0000000..a7aced1 --- /dev/null +++ b/anim/test/gallery/sort.ztrace diff --git a/anim/test/gallery/step.png b/anim/test/gallery/step.png Binary files differindex b85cba0..19ffc00 100644 --- a/anim/test/gallery/step.png +++ b/anim/test/gallery/step.png diff --git a/anim/test/gallery/subject.png b/anim/test/gallery/subject.png Binary files differindex d912474..182f8ba 100644 --- a/anim/test/gallery/subject.png +++ b/anim/test/gallery/subject.png diff --git a/anim/test/recordings.zig b/anim/test/recordings.zig index 38798af..ce5a9db 100644 --- a/anim/test/recordings.zig +++ b/anim/test/recordings.zig @@ -105,3 +105,108 @@ test "a walked step is as long as what it changed: fire, a slot a level, the hol 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); } + +/// The first moment whose pc is in the function named `name` (as the recording names it: `libc.so.6!open`). +fn firstIn(rec: *const Recording, name: []const u8) u64 { + for (rec.registers, 0..) |regs, i| { + const at = rec.strings.get(regs.rip) orelse continue; + if (std.mem.startsWith(u8, at, name) and at.len > name.len and at[name.len] == '+') return i; + } + unreachable; +} + +test "sort's graph: two loops in their lanes, the hot path straight down, the jle never taken" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const graph = canim.graph; + const rec = canim.open(recordings.sort); + const at = firstIn(rec, "sort"); + var g = graph.read(arena.allocator(), rec, rec.end(), rec.registers[at].rip).?; + try expect(g.exact and g.text); + try expectEqual(@as(usize, 11), g.nodes.len); + for (g.nodes) |n| try expect(n.reached); + // The inner loop's `j > 0` is never false: its jle never taken. + const jle = g.edgeOf(g.nodeOf(g.start + 0x8a).?, g.nodeOf(g.start + 0xbc).?).?; + try expect(g.edges[jle].kind == .taken and g.edges[jle].total == 0); + // The compare's jne to the swap, ten times; the swap entered as often. + const swap = g.nodeOf(g.start + 0xc5).?; + try expectEqual(@as(u32, 10), g.edges[g.edgeOf(g.nodeOf(g.start + 0xbc).?, swap).?].count); + try expectEqual(@as(u32, 10), g.nodes[swap].visits); + graph.sizes(rec, rec.end(), &g, .map); + graph.place(&g, graph.metricOf(.map)); + var backs: usize = 0; + for (g.edges) |e| backs += @intFromBool(e.back); + try expectEqual(@as(usize, 2), backs); + // The outer loop (i++ back to the test) outermost, the inner (the swap back to `j > 0`) inside it. + const outer = g.edges[g.edgeOf(g.nodeOf(g.start + 0xff).?, g.nodeOf(g.start + 0x78).?).?]; + const inner = g.edges[g.edgeOf(swap, g.nodeOf(g.start + 0x8a).?).?]; + try expect(outer.back and inner.back and outer.lane == 0 and inner.lane == 1); + // The swap straight under the compare that goes to it ten times in ten; the way on beside it. + try expectEqual(g.nodes[g.nodeOf(g.start + 0xbc).?].col, g.nodes[swap].col); + try expect(g.nodes[g.nodeOf(g.start + 0xc3).?].col > g.nodes[swap].col); + // The jle and the loop's exit would cross blocks: the right channel. + try expectEqual(@as(u8, 6), g.edges[jle].n); + try expectEqual(g.channel, g.edges[jle].points[2][0]); + // On the map (1688 high): too tall; the long prologue folds, and the outer loop is panned into view whole. + var buf: [1 << 20]u8 = undefined; + var fba = std.heap.FixedBufferAllocator.init(&buf); + const room = 1688 - 24; + const in_loop = rec.lineMoment(12, at); + const laid = graph.layout(fba.allocator(), rec, in_loop, rec.registers[in_loop].rip, .map, room).?; + try expectEqual(@as(u32, 9), laid.nodes[0].shown); + const off = graph.pan(laid, room, graph.metricOf(.map)); + for (laid.nodes[1 .. laid.nodes.len - 1]) |n| try expect(n.y >= off and n.y + n.h <= off + room); +} + +test "reverse's graph: one loop, its exit in the right channel" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const graph = canim.graph; + const rec = canim.open(recordings.list); + const at = firstIn(rec, "reverse"); + var g = graph.read(arena.allocator(), rec, rec.end(), rec.registers[at].rip).?; + try expectEqual(@as(usize, 4), g.nodes.len); + graph.sizes(rec, rec.end(), &g, .map); + graph.place(&g, graph.metricOf(.map)); + const layers = [_]u32{ 0, 1, 2, 3 }; + for (g.nodes, layers) |n, l| try expect(n.layer == l and n.col == 0); + // The body's jmp back to the test: the one edge that climbs, three turns. + const turn = g.edges[g.edgeOf(2, 1).?]; + try expect(turn.back and turn.count == 3); + try expectEqual(@as(u8, 6), g.edges[g.edgeOf(1, 3).?].n); + // The recording begins inside it: its first block was entered once. + try expectEqual(@as(u32, 1), g.nodes[0].visits); + try expect(g.h <= 1688 - 24); +} + +test "libc's open at its syscall: the blocks never reached folded, no loop made by folding" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const graph = canim.graph; + const rec = canim.open(recordings.hello); + var at = firstIn(rec, "libc.so.6!open"); + var buf: [256]u8 = undefined; + while (!std.mem.eql(u8, rec.instruction(at, rec.registers[at].rip, &buf).?.text, "syscall")) at += 1; + const g = graph.layout(arena.allocator(), rec, at, rec.registers[at].rip, .map, 1688 - 24).?; + // Twenty blocks (two of `nop` padding left out), eight of them reached. + try expectEqual(@as(usize, 20), g.blocks); + var reached: usize = 0; + var folds: usize = 0; + for (g.nodes) |n| { + reached += @intFromBool(n.reached); + folds += @intFromBool(n.folded > 0); + } + try expectEqual(@as(usize, 8), reached); + try expectEqual(@as(usize, 12), g.foldedBlocks()); + try expect(folds >= 4 and folds < 12); + // open has no loop, and the folds make none. + for (g.edges) |e| try expect(!e.back); + // At its syscall: the blocks before entered once, those after not yet. + try expectEqual(g.nodeOf(rec.registers[at].rip).?, g.here.?); + for (g.nodes) |n| if (n.reached) try expectEqual(@as(u32, @intFromBool(n.start <= rec.registers[at].rip)), n.visits); + // Still taller than the map: it pans, the pc's block in view; as wide as two columns at most. + const room = 1688 - 24; + const off = graph.pan(g, room, graph.metricOf(.map)); + const here = g.nodes[g.here.?]; + try expect(here.y >= off and here.y + here.h <= off + room and g.w <= 1792); +} |
