//! 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); }