summaryrefslogtreecommitdiff
path: root/src/trace/together_test.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/trace/together_test.zig')
-rw-r--r--src/trace/together_test.zig36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/trace/together_test.zig b/src/trace/together_test.zig
new file mode 100644
index 0000000..09abb7b
--- /dev/null
+++ b/src/trace/together_test.zig
@@ -0,0 +1,36 @@
+//! 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);
+}