test timeouts
This commit is contained in:
@@ -14,4 +14,7 @@
|
||||
- debug printfs: add printfs only when debugging a specific issue; when done
|
||||
debugging, remove them (or comment them if you may find them useful later). I
|
||||
prefer committing code only when `zig build` returns no output.
|
||||
- Always complete all tasks before stopping. Do not stop to ask for
|
||||
confirmation mid-task. If you have remaining work, continue without waiting
|
||||
for input.
|
||||
- remember: **mechanical copy** when porting existing stuff, no new creativity.
|
||||
|
||||
@@ -18,7 +18,12 @@ This is written with help from LLM:
|
||||
|
||||
Quick test:
|
||||
|
||||
zig build fmt && zig build
|
||||
zig build test
|
||||
|
||||
Full test with all supported compilers and valgrind (run before commit,
|
||||
takes a while):
|
||||
|
||||
zig build fmt && zig build -Dvalgrind
|
||||
|
||||
# Debugging tips
|
||||
|
||||
|
||||
11
build.zig
11
build.zig
@@ -48,6 +48,7 @@ pub fn build(b: *std.Build) !void {
|
||||
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 valgrind = b.option(bool, "valgrind", "Run tests under valgrind") orelse false;
|
||||
const test_timeout = b.option([]const u8, "test-timeout", "Test execution timeout (default: 10s, or 60s with valgrind)");
|
||||
|
||||
const target = blk: {
|
||||
var query = b.standardTargetOptionsQueryOnly(.{});
|
||||
@@ -61,7 +62,7 @@ pub fn build(b: *std.Build) !void {
|
||||
};
|
||||
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
addTestStep(b, test_step, target, optimize, cc, no_exec, valgrind);
|
||||
addTestStep(b, test_step, target, optimize, cc, no_exec, valgrind, test_timeout);
|
||||
|
||||
const fmt_step = b.step("fmt", "clang-format");
|
||||
const clang_format = b.addSystemCommand(&.{ "clang-format", "-i" });
|
||||
@@ -117,7 +118,7 @@ pub fn build(b: *std.Build) !void {
|
||||
all_step.dependOn(&fmt_check.step);
|
||||
|
||||
for (compilers) |compiler| {
|
||||
addTestStep(b, all_step, target, optimize, compiler, false, valgrind);
|
||||
addTestStep(b, all_step, target, optimize, compiler, false, valgrind, test_timeout);
|
||||
}
|
||||
|
||||
b.default_step = all_step;
|
||||
@@ -131,6 +132,7 @@ fn addTestStep(
|
||||
cc: []const u8,
|
||||
no_exec: bool,
|
||||
valgrind: bool,
|
||||
test_timeout: ?[]const u8,
|
||||
) void {
|
||||
const test_mod = b.createModule(.{
|
||||
.root_source_file = b.path("test_all.zig"),
|
||||
@@ -164,8 +166,11 @@ fn addTestStep(
|
||||
.use_llvm = false,
|
||||
.use_lld = false,
|
||||
});
|
||||
const timeout = test_timeout orelse if (valgrind) "300" else "10";
|
||||
if (valgrind) {
|
||||
test_exe.setExecCmd(&.{
|
||||
"timeout",
|
||||
timeout,
|
||||
"valgrind",
|
||||
"--error-exitcode=2",
|
||||
"--leak-check=full",
|
||||
@@ -174,6 +179,8 @@ fn addTestStep(
|
||||
"--track-fds=yes",
|
||||
null,
|
||||
});
|
||||
} else {
|
||||
test_exe.setExecCmd(&.{ "timeout", timeout, null });
|
||||
}
|
||||
if (no_exec) {
|
||||
const install = b.addInstallArtifact(test_exe, .{});
|
||||
|
||||
Reference in New Issue
Block a user