diff options
Diffstat (limited to 'anim/test/recordings.zig')
| -rw-r--r-- | anim/test/recordings.zig | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/anim/test/recordings.zig b/anim/test/recordings.zig index 7c3a26e..5f9ceb3 100644 --- a/anim/test/recordings.zig +++ b/anim/test/recordings.zig @@ -82,7 +82,8 @@ test "a walked step is as long as what it changed: fire, a slot a level, the hol 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 }; + // The cascade as it was: `whole` (`tied` is the next test's). + at.levels = .{ .idea = .calls, .annotation = .whole }; } }; var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); @@ -101,11 +102,63 @@ test "a walked step is as long as what it changed: fire, a slot a level, the hol try expect(call.total > 2.0 and call.total < 3.5); // A line that changes nothing shown: fire, advance, rest. var quiet = scene.at; - quiet.levels = .{ .cpu = false, .memory = false }; + quiet.levels = .{ .cpu = false, .memory = false, .annotation = .whole }; 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); } +test "under tied a step goes cause to effect: the touch, the word, rsp's pin, the window" { + 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.call("fib", 1).enter - 1); + } + }; + 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 f = 1.0 / 60.0; + // fib(5)'s `call fib` (by instruction): the touch to the free word over rsp 18 to 30, the return + // address armed 30 to 42 and struck at 42, rsp's pin 48 to 72 (struck as it lands), the window 78 on. + const call = rec.call("fib", 1).enter - 1; + const pushed = scene.at.reading(call, call + 1); + try std.testing.expectApproxEqAbs(@as(f32, 18 * f), pushed.touch, 1e-4); + try std.testing.expectApproxEqAbs(@as(f32, 42 * f), pushed.at[1], 1e-4); + try std.testing.expectApproxEqAbs(@as(f32, 48 * f), pushed.pins[0], 1e-4); + try std.testing.expectApproxEqAbs(@as(f32, 78 * f), pushed.follow, 1e-4); + try expect(pushed.pins[1] < 0 and pushed.advance > pushed.follow); + // `push rbp`, at the callee's entry: the same order. + const push = scene.at.reading(call + 1, call + 2); + try expect(push.touch < push.at[1] and push.at[1] < push.pins[0] and push.pins[0] < push.follow); + // `mov rbp, rsp`: no word; rbp's pin from 18 f, and no window to follow. + const frame_ptr = scene.at.reading(call + 2, call + 3); + try expect(frame_ptr.touch < 0 and frame_ptr.pins[0] < 0 and frame_ptr.follow < 0); + try std.testing.expectApproxEqAbs(@as(f32, 18 * f), frame_ptr.pins[1], 1e-4); + // A load that fills a register (`mov rax, [rbp - 0x10]`, fib(1)'s `return n`): the word read + // (its touch 18 to 30, framed at 30) before rax strikes (48). + var at = call; + var buf: [256]u8 = undefined; + while (!(std.mem.eql(u8, rec.instruction(at, rec.register(at, "rip"), &buf).?.text, "mov rax, qword ptr [rbp - 0x10]") and rec.registersChanged(at, at + 1) & 1 != 0)) at += 1; + const load = scene.at.reading(at, at + 1); + try std.testing.expectApproxEqAbs(@as(f32, 30 * f), load.read, 1e-4); + try std.testing.expectApproxEqAbs(@as(f32, 48 * f), load.at[0], 1e-4); + // With `carry = .arrow` the value's way between: carried 36 to 54, rax struck at 66. + var carrying = scene.at; + carrying.levels.carry = .arrow; + const carried = carrying.reading(at, at + 1); + try std.testing.expectApproxEqAbs(@as(f32, 36 * f), carried.carry, 1e-4); + try std.testing.expectApproxEqAbs(@as(f32, 66 * f), carried.at[0], 1e-4); + // `pop rbp`: the word read (framed at 30), then rbp's pin (it takes the word), then rsp's, then the window. + var pop = at; + while (!std.mem.eql(u8, rec.instruction(pop, rec.register(pop, "rip"), &buf).?.text, "pop rbp")) pop += 1; + const popped = scene.at.reading(pop, pop + 1); + try std.testing.expectApproxEqAbs(@as(f32, 30 * f), popped.read, 1e-4); + try expect(popped.read < popped.pins[1] and popped.pins[1] < popped.pins[0] and popped.pins[0] < popped.follow); +} + /// 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| { |
