std.Build: do not expect server protocol for tests using immature backends

For instance, when running a Zig test using the self-hosted aarch64
backend, this logic was previously expecting `std.zig.Server` to be
used, but the default test runner intentionally does not do this because
the backend is too immature to handle it. On 'master', this is causing
sporadic failures; on this branch, they became consistent failures.
This commit is contained in:
mlugg 2025-09-13 16:16:11 +01:00 committed by Matthew Lugg
parent b43bb3a32a
commit d0b92a8022
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
2 changed files with 36 additions and 5 deletions

View File

@ -17,7 +17,9 @@ var fba_buffer: [8192]u8 = undefined;
var stdin_buffer: [4096]u8 = undefined; var stdin_buffer: [4096]u8 = undefined;
var stdout_buffer: [4096]u8 = undefined; var stdout_buffer: [4096]u8 = undefined;
const crippled = switch (builtin.zig_backend) { /// Keep in sync with logic in `std.Build.addRunArtifact` which decides whether
/// the test runner will communicate with the build runner via `std.zig.Server`.
const need_simple = switch (builtin.zig_backend) {
.stage2_aarch64, .stage2_aarch64,
.stage2_powerpc, .stage2_powerpc,
.stage2_riscv64, .stage2_riscv64,
@ -33,7 +35,7 @@ pub fn main() void {
return; return;
} }
if (crippled) { if (need_simple) {
return mainSimple() catch @panic("test failure\n"); return mainSimple() catch @panic("test failure\n");
} }
@ -380,7 +382,7 @@ pub fn fuzz(
// Some compiler backends are not capable of handling fuzz testing yet but // Some compiler backends are not capable of handling fuzz testing yet but
// we still want CI test coverage enabled. // we still want CI test coverage enabled.
if (crippled) return; if (need_simple) return;
// Smoke test to ensure the test did not use conditional compilation to // Smoke test to ensure the test did not use conditional compilation to
// contradict itself by making it not actually be a fuzz test when the test // contradict itself by making it not actually be a fuzz test when the test

View File

@ -956,8 +956,37 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
run_step.addArtifactArg(exe); run_step.addArtifactArg(exe);
} }
const test_server_mode = if (exe.test_runner) |r| r.mode == .server else true; const test_server_mode: bool = s: {
if (test_server_mode) run_step.enableTestRunnerMode(); if (exe.test_runner) |r| break :s r.mode == .server;
if (exe.use_llvm == false) {
// The default test runner does not use the server protocol if the selected backend
// is too immature to support it. Keep this logic in sync with `need_simple` in the
// default test runner implementation.
switch (exe.rootModuleTarget().cpu.arch) {
// stage2_aarch64
.aarch64,
.aarch64_be,
// stage2_powerpc
.powerpc,
.powerpcle,
.powerpc64,
.powerpc64le,
// stage2_riscv64
.riscv64,
=> break :s false,
else => {},
}
}
break :s true;
};
if (test_server_mode) {
run_step.enableTestRunnerMode();
} else if (exe.test_runner == null) {
// If a test runner does not use the `std.zig.Server` protocol, it can instead
// communicate failure via its exit code.
run_step.expectExitCode(0);
}
} else { } else {
run_step.addArtifactArg(exe); run_step.addArtifactArg(exe);
} }