From 50056a5b3ad29695c795534cebbd031408633813 Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Tue, 14 Oct 2025 23:01:13 +0100 Subject: [PATCH] compiler: rename `--test-timeout-ms` to `--test-timeout` The unit can now be specified in the argument. --- ci/aarch64-linux-debug.sh | 2 +- ci/aarch64-linux-release.sh | 2 +- ci/aarch64-macos-debug.sh | 2 +- ci/aarch64-macos-release.sh | 2 +- ci/aarch64-windows.ps1 | 2 +- ci/loongarch64-linux-debug.sh | 2 +- ci/loongarch64-linux-release.sh | 2 +- ci/riscv64-linux-debug.sh | 2 +- ci/riscv64-linux-release.sh | 2 +- ci/x86_64-freebsd-debug.sh | 2 +- ci/x86_64-freebsd-release.sh | 2 +- ci/x86_64-linux-debug-llvm.sh | 2 +- ci/x86_64-linux-debug.sh | 2 +- ci/x86_64-linux-release.sh | 2 +- ci/x86_64-windows-debug.ps1 | 2 +- ci/x86_64-windows-release.ps1 | 2 +- lib/compiler/build_runner.zig | 51 ++++++++++++++++++++++++--------- lib/std/Build/Step/Run.zig | 2 +- 18 files changed, 55 insertions(+), 30 deletions(-) diff --git a/ci/aarch64-linux-debug.sh b/ci/aarch64-linux-debug.sh index 00cf48f5130f8509e7d33569f78d301f85fc376f..29c815e8166822c75ddd150199aa1c0c35c09e38 100755 --- a/ci/aarch64-linux-debug.sh +++ b/ci/aarch64-linux-debug.sh @@ -51,7 +51,7 @@ stage3-debug/bin/zig build test docs \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ -Denable-superhtml \ - --test-timeout-ms 60_000 + --test-timeout 60s stage3-debug/bin/zig build \ --prefix stage4-debug \ diff --git a/ci/aarch64-linux-release.sh b/ci/aarch64-linux-release.sh index f0a341d9623dc22d6a25f9200ee5e66c1d5506cb..26547d8b41cb3231c41ea7fbc02ba3b26f91b9b9 100755 --- a/ci/aarch64-linux-release.sh +++ b/ci/aarch64-linux-release.sh @@ -51,7 +51,7 @@ stage3-release/bin/zig build test docs \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ -Denable-superhtml \ - --test-timeout-ms 60_000 + --test-timeout 60s # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/aarch64-macos-debug.sh b/ci/aarch64-macos-debug.sh index 787df10de4151fcdc375879826035d0925e03c71..4afff422694726a52c07bbb22540c385ebe18b4f 100755 --- a/ci/aarch64-macos-debug.sh +++ b/ci/aarch64-macos-debug.sh @@ -47,4 +47,4 @@ stage3-debug/bin/zig build test docs \ -Dstatic-llvm \ -Dskip-non-native \ --search-prefix "$PREFIX" \ - --test-timeout-ms 60_000 + --test-timeout 60s diff --git a/ci/aarch64-macos-release.sh b/ci/aarch64-macos-release.sh index 872a2f4ee73b897f5eb0bf0a4948088793ffdf40..8ddbe9773d4b804859ed7f1340861e17aec9cb60 100755 --- a/ci/aarch64-macos-release.sh +++ b/ci/aarch64-macos-release.sh @@ -47,7 +47,7 @@ stage3-release/bin/zig build test docs \ -Dstatic-llvm \ -Dskip-non-native \ --search-prefix "$PREFIX" \ - --test-timeout-ms 60_000 + --test-timeout 60s # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/aarch64-windows.ps1 b/ci/aarch64-windows.ps1 index 4f52bd3f81ae5fd13890a641305f4af95c348aa1..8720c7004d93e0b1388f12307270f2c366a4ba66 100644 --- a/ci/aarch64-windows.ps1 +++ b/ci/aarch64-windows.ps1 @@ -59,7 +59,7 @@ Write-Output "Main test suite..." -Dstatic-llvm ` -Dskip-non-native ` -Denable-symlinks-windows ` - --test-timeout-ms 60_000 + --test-timeout 60s CheckLastExitCode # Ensure that stage3 and stage4 are byte-for-byte identical. diff --git a/ci/loongarch64-linux-debug.sh b/ci/loongarch64-linux-debug.sh index 47312bbde25924f3fd72d7eb31e5b049379a40b2..a2f1126f4f5459f7cbd0cbdecae8b25c03cb8a6a 100755 --- a/ci/loongarch64-linux-debug.sh +++ b/ci/loongarch64-linux-debug.sh @@ -51,7 +51,7 @@ stage3-debug/bin/zig build test docs \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - --test-timeout-ms 120_000 + --test-timeout 2m stage3-debug/bin/zig build \ --prefix stage4-debug \ diff --git a/ci/loongarch64-linux-release.sh b/ci/loongarch64-linux-release.sh index 62a535028503d1de724b6e4bb19965b38b762d1f..2cb6229d9b3d5adf7fd77605e8fb0b0b5758d018 100755 --- a/ci/loongarch64-linux-release.sh +++ b/ci/loongarch64-linux-release.sh @@ -51,7 +51,7 @@ stage3-release/bin/zig build test docs \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - --test-timeout-ms 120_000 + --test-timeout 2m # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/riscv64-linux-debug.sh b/ci/riscv64-linux-debug.sh index 98bc72a4397daf5cc2144e9dedb491fa7137793d..84a82be8dc73ac3ac4a450ea0f2429fad9bbb0d1 100755 --- a/ci/riscv64-linux-debug.sh +++ b/ci/riscv64-linux-debug.sh @@ -52,4 +52,4 @@ stage3-debug/bin/zig build test-cases test-modules test-unit test-c-abi test-sta -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - --test-timeout-ms 120_000 + --test-timeout 2m diff --git a/ci/riscv64-linux-release.sh b/ci/riscv64-linux-release.sh index 4622277699284bacfc68293b333c82b39fa41b9d..1aa31a6f8a811016058355c813c7d6a79e220463 100755 --- a/ci/riscv64-linux-release.sh +++ b/ci/riscv64-linux-release.sh @@ -52,4 +52,4 @@ stage3-release/bin/zig build test-cases test-modules test-unit test-c-abi test-s -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - --test-timeout-ms 120_000 + --test-timeout 2m diff --git a/ci/x86_64-freebsd-debug.sh b/ci/x86_64-freebsd-debug.sh index ffc6d552261aaa5cfbbab1b6816097d76586d3f3..9440af5e029a3c20a24462715c3f684c402823d8 100755 --- a/ci/x86_64-freebsd-debug.sh +++ b/ci/x86_64-freebsd-debug.sh @@ -52,7 +52,7 @@ stage3-debug/bin/zig build test docs \ -Dskip-macos \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - --test-timeout-ms 60_000 + --test-timeout 60s stage3-debug/bin/zig build \ --prefix stage4-debug \ diff --git a/ci/x86_64-freebsd-release.sh b/ci/x86_64-freebsd-release.sh index 09048d1e22434363f4354994b6f905b68561c396..7f67e757ba5198d6a76c92824c45c376e07cef47 100755 --- a/ci/x86_64-freebsd-release.sh +++ b/ci/x86_64-freebsd-release.sh @@ -52,7 +52,7 @@ stage3-release/bin/zig build test docs \ -Dskip-macos \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ - --test-timeout-ms 60_000 + --test-timeout 60s # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/x86_64-linux-debug-llvm.sh b/ci/x86_64-linux-debug-llvm.sh index 560ca74eada583e335d1c94e6ebb05cd63801caf..7eae6a355f94590d23450a328ad29bbc3f16d356 100755 --- a/ci/x86_64-linux-debug-llvm.sh +++ b/ci/x86_64-linux-debug-llvm.sh @@ -62,4 +62,4 @@ stage3-debug/bin/zig build test docs \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ -Denable-superhtml \ - --test-timeout-ms 240_000 + --test-timeout 4m diff --git a/ci/x86_64-linux-debug.sh b/ci/x86_64-linux-debug.sh index 663c8f834a6323c603c1af6fe64777299572a74d..c9693bc1a7b67c67fab5d25d459737acce1d0d9d 100755 --- a/ci/x86_64-linux-debug.sh +++ b/ci/x86_64-linux-debug.sh @@ -62,4 +62,4 @@ stage3-debug/bin/zig build test docs \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ -Denable-superhtml \ - --test-timeout-ms 240_000 + --test-timeout 4m diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index fb91d693306a3feabcd4a185bf7c3c08cbc7d6e8..725bae0510eb73aab53cb233d8598e17e261b75b 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -64,7 +64,7 @@ stage3-release/bin/zig build test docs \ --search-prefix "$PREFIX" \ --zig-lib-dir "$PWD/../lib" \ -Denable-superhtml \ - --test-timeout-ms 240_000 + --test-timeout 4m # Ensure that stage3 and stage4 are byte-for-byte identical. stage3-release/bin/zig build \ diff --git a/ci/x86_64-windows-debug.ps1 b/ci/x86_64-windows-debug.ps1 index 516a8e3444ccbe36a9d12e2dc9f1fcba3cf46bab..873d3d5ff1b1472eed1d6d0e222f46b2af943289 100644 --- a/ci/x86_64-windows-debug.ps1 +++ b/ci/x86_64-windows-debug.ps1 @@ -60,7 +60,7 @@ Write-Output "Main test suite..." -Dskip-non-native ` -Dskip-release ` -Denable-symlinks-windows ` - --test-timeout-ms 240_000 + --test-timeout 4m CheckLastExitCode Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." diff --git a/ci/x86_64-windows-release.ps1 b/ci/x86_64-windows-release.ps1 index 80568eeb376995978ad07cfcdde5035cd91570eb..f9258941384a18c7e96fac84fe969ee469e9233d 100644 --- a/ci/x86_64-windows-release.ps1 +++ b/ci/x86_64-windows-release.ps1 @@ -59,7 +59,7 @@ Write-Output "Main test suite..." -Dstatic-llvm ` -Dskip-non-native ` -Denable-symlinks-windows ` - --test-timeout-ms 240_000 + --test-timeout 4m CheckLastExitCode # Ensure that stage3 and stage4 are byte-for-byte identical. diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 90bc5914697e80f35940568506924d0a68a2f218..374bfa6ed3587815ad2d4da1aed6c53f4d798c92 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -108,7 +108,7 @@ pub fn main() !void { var summary: ?Summary = null; var max_rss: u64 = 0; var skip_oom_steps = false; - var test_timeout_ms: ?u64 = null; + var test_timeout_ns: ?u64 = null; var color: Color = .auto; var help_menu = false; var steps_menu = false; @@ -189,14 +189,41 @@ pub fn main() !void { }; } else if (mem.eql(u8, arg, "--skip-oom-steps")) { skip_oom_steps = true; - } else if (mem.eql(u8, arg, "--test-timeout-ms")) { - const millis_str = nextArgOrFatal(args, &arg_idx); - test_timeout_ms = std.fmt.parseInt(u64, millis_str, 10) catch |err| { - std.debug.print("invalid millisecond count: '{s}': {s}\n", .{ - millis_str, @errorName(err), - }); - process.exit(1); + } else if (mem.eql(u8, arg, "--test-timeout")) { + const units: []const struct { []const u8, u64 } = &.{ + .{ "ns", 1 }, + .{ "nanosecond", 1 }, + .{ "us", std.time.ns_per_us }, + .{ "microsecond", std.time.ns_per_us }, + .{ "ms", std.time.ns_per_ms }, + .{ "millisecond", std.time.ns_per_ms }, + .{ "s", std.time.ns_per_s }, + .{ "second", std.time.ns_per_s }, + .{ "m", std.time.ns_per_min }, + .{ "minute", std.time.ns_per_min }, + .{ "h", std.time.ns_per_hour }, + .{ "hour", std.time.ns_per_hour }, }; + const timeout_str = nextArgOrFatal(args, &arg_idx); + const num_end_idx = std.mem.findLastNone(u8, timeout_str, "abcdefghijklmnopqrstuvwxyz") orelse fatal( + "invalid timeout '{s}': expected unit (ns, us, ms, s, m, h)", + .{timeout_str}, + ); + const num_str = timeout_str[0 .. num_end_idx + 1]; + const unit_str = timeout_str[num_end_idx + 1 ..]; + const unit_factor: f64 = for (units) |unit_and_factor| { + if (std.mem.eql(u8, unit_str, unit_and_factor[0])) { + break @floatFromInt(unit_and_factor[1]); + } + } else fatal( + "invalid timeout '{s}': invalid unit '{s}' (expected ns, us, ms, s, m, h)", + .{ timeout_str, unit_str }, + ); + const num_parsed = std.fmt.parseFloat(f64, num_str) catch |err| fatal( + "invalid timeout '{s}': invalid number '{s}' ({t})", + .{ timeout_str, num_str, err }, + ); + test_timeout_ns = std.math.lossyCast(u64, unit_factor * num_parsed); } else if (mem.eql(u8, arg, "--search-prefix")) { const search_prefix = nextArgOrFatal(args, &arg_idx); builder.addSearchPrefix(search_prefix); @@ -480,10 +507,7 @@ pub fn main() !void { .max_rss_is_default = false, .max_rss_mutex = .{}, .skip_oom_steps = skip_oom_steps, - .unit_test_timeout_ns = ns: { - const ms = test_timeout_ms orelse break :ns null; - break :ns std.math.mul(u64, ms, std.time.ns_per_ms) catch null; - }, + .unit_test_timeout_ns = test_timeout_ns, .watch = watch, .web_server = undefined, // set after `prepare` @@ -1584,7 +1608,8 @@ fn printUsage(b: *std.Build, w: *Writer) !void { \\ -j Limit concurrent jobs (default is to use all CPU cores) \\ --maxrss Limit memory usage (default is to use available memory) \\ --skip-oom-steps Instead of failing, skip steps that would exceed --maxrss - \\ --test-timeout-ms Limit execution time of unit tests, terminating if exceeded + \\ --test-timeout Limit execution time of unit tests, terminating if exceeded. + \\ The timeout must include a unit: ns, us, ms, s, m, h \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit \\ needed (Default) Lazy dependencies are fetched as needed \\ all Lazy dependencies are always fetched diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 9a3c1f790636c2750402ce2cf47cee293da9e3f7..cd29262612fbc8ba6b609d99c4e56e1a05f8de32 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1814,7 +1814,7 @@ fn pollZigTest( // test. For instance, if the test runner leaves this much time between us requesting a test to // start and it acknowledging the test starting, we terminate the child and raise an error. This // *should* never happen, but could in theory be caused by some very unlucky IB in a test. - const response_timeout_ns = options.unit_test_timeout_ns orelse 60 * std.time.ns_per_s; + const response_timeout_ns = @max(options.unit_test_timeout_ns orelse 0, 60 * std.time.ns_per_s); const stdout = poller.reader(.stdout); const stderr = poller.reader(.stderr); -- 2.54.0