//! The recording `test-together` makes (a list built by `ztrace cc`, its //! allocations told by the agent, stopped at breakpoints by the debugger), //! read back: found through the `recording` options. const std = @import("std"); const zt = @import("ztrace"); const recording = @import("recording"); test "at every stop each live allocation is there to read, with glibc's header before it" { const gpa = std.testing.allocator; var trace = try zt.Trace.open(gpa, std.testing.io, recording.together); defer trace.close(); var checked: usize = 0; for (0..trace.len) |i| { const m = try trace.moment(i); var events = try m.events(gpa); defer events.deinit(gpa); const stop = while (events.next()) |item| { if (item.ev.kind == .breakpoint) break true; } else false; if (!stop) continue; const heap = try m.heap(gpa); defer gpa.free(heap); for (heap) |a| { var bytes: [16 + 16]u8 = undefined; var known: [16 + 16]bool = undefined; try std.testing.expectEqual(@as(u64, 16), a.size); try m.read(a.ptr - 16, &bytes, &known); try std.testing.expect(std.mem.allEqual(bool, &known, true)); // A chunk of 32 bytes: the 16 asked for, 8 of header, rounded to 16. try std.testing.expectEqual(@as(u64, 32), std.mem.readInt(u64, bytes[8..16], .little) & ~@as(u64, 7)); checked += 1; } } // Five nodes, at the stops after each was made. try std.testing.expect(checked >= 5); }