From 9a6341a23b3b3a4e7146adb6ab8dca67a927b1c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 12 Feb 2026 08:16:50 +0200 Subject: [PATCH] test timeouts --- CLAUDE.md | 3 +++ README.md | 7 ++++++- build.zig | 11 +++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index e4492224a4..befdd99901 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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. diff --git a/README.md b/README.md index 8a1f8fb053..249fdde65a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.zig b/build.zig index f8dd8c4cf6..bc13bac0a8 100644 --- a/build.zig +++ b/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, .{});