1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
//! glibc's heap: a program that mallocs and frees a step at a time,
//! recorded with `--heap` and read back.
const std = @import("std");
const Ctx = @import("../build.zig").Ctx;
pub fn add(ctx: Ctx) void {
const b = ctx.b;
const target = ctx.cTarget("heap", &.{"heap.c"});
b.getInstallStep().dependOn(&b.addInstallArtifact(target, .{ .dest_dir = .{ .override = .{ .custom = "targets" } } }).step);
const step = ctx.areaTest("test-heap", "glibc's heap, recorded at each step and read back");
// The library, driven from Zig: the reader against the live process.
const paths = b.addOptions();
paths.addOptionPath("heap", target.getEmittedBin());
step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("src/trace/heap_test.zig"),
.target = ctx.target,
.optimize = ctx.optimize,
.imports = &.{ .{ .name = "ztrace", .module = ctx.ztrace }, .{ .name = "targets", .module = paths.createModule() } },
}) })).step);
// The commands: a recording with the heap, and its last moment shown.
const record = b.addRunArtifact(ctx.exe);
record.addArgs(&.{ "record", "--by", "break", "-b", "heap_step", "--heap", "-o" });
const recording = record.addOutputFileArg("heap.ztrace");
record.addArg("--");
record.addArtifactArg(target);
record.expectStdErrMatch("heap: glibc ");
record.expectStdErrMatch("exit 0");
const show = b.addRunArtifact(ctx.exe);
show.addArg("show");
show.addFileArg(recording);
show.addArg("-1");
inline for (.{ " heap: main_arena ", " top\n", "\ntcache ", " tcache 30 [" }) |part| show.expectStdOutMatch(part);
step.dependOn(&show.step);
}
|