valgrind
This commit is contained in:
17
build.zig
17
build.zig
@@ -44,9 +44,10 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
const cc = b.option([]const u8, "cc", "C compiler") orelse "zig";
|
const cc = b.option([]const u8, "cc", "C compiler") orelse "zig";
|
||||||
const no_exec = b.option(bool, "no-exec", "Compile test binary without running it") orelse false;
|
const no_exec = b.option(bool, "no-exec", "Compile test binary without running it") orelse false;
|
||||||
|
const valgrind = b.option(bool, "valgrind", "Run tests under valgrind") orelse false;
|
||||||
|
|
||||||
const test_step = b.step("test", "Run unit tests");
|
const test_step = b.step("test", "Run unit tests");
|
||||||
addTestStep(b, test_step, target, optimize, cc, no_exec);
|
addTestStep(b, test_step, target, optimize, cc, no_exec, valgrind);
|
||||||
|
|
||||||
const fmt_step = b.step("fmt", "clang-format");
|
const fmt_step = b.step("fmt", "clang-format");
|
||||||
const clang_format = b.addSystemCommand(&.{ "clang-format", "-i" });
|
const clang_format = b.addSystemCommand(&.{ "clang-format", "-i" });
|
||||||
@@ -102,7 +103,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
all_step.dependOn(&fmt_check.step);
|
all_step.dependOn(&fmt_check.step);
|
||||||
|
|
||||||
for (compilers) |compiler| {
|
for (compilers) |compiler| {
|
||||||
addTestStep(b, all_step, target, optimize, compiler, false);
|
addTestStep(b, all_step, target, optimize, compiler, false, valgrind);
|
||||||
}
|
}
|
||||||
|
|
||||||
b.default_step = all_step;
|
b.default_step = all_step;
|
||||||
@@ -115,6 +116,7 @@ fn addTestStep(
|
|||||||
optimize: std.builtin.OptimizeMode,
|
optimize: std.builtin.OptimizeMode,
|
||||||
cc: []const u8,
|
cc: []const u8,
|
||||||
no_exec: bool,
|
no_exec: bool,
|
||||||
|
valgrind: bool,
|
||||||
) void {
|
) void {
|
||||||
const test_mod = b.createModule(.{
|
const test_mod = b.createModule(.{
|
||||||
.root_source_file = b.path("test_all.zig"),
|
.root_source_file = b.path("test_all.zig"),
|
||||||
@@ -144,6 +146,17 @@ fn addTestStep(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const test_exe = b.addTest(.{ .root_module = test_mod });
|
const test_exe = b.addTest(.{ .root_module = test_mod });
|
||||||
|
if (valgrind) {
|
||||||
|
test_exe.setExecCmd(&.{
|
||||||
|
"valgrind",
|
||||||
|
"--error-exitcode=2",
|
||||||
|
"--leak-check=full",
|
||||||
|
"--show-leak-kinds=all",
|
||||||
|
"--errors-for-leak-kinds=all",
|
||||||
|
"--track-fds=yes",
|
||||||
|
null,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (no_exec) {
|
if (no_exec) {
|
||||||
const install = b.addInstallArtifact(test_exe, .{});
|
const install = b.addInstallArtifact(test_exe, .{});
|
||||||
step.dependOn(&install.step);
|
step.dependOn(&install.step);
|
||||||
|
|||||||
Reference in New Issue
Block a user