authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-13 16:16:11+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-10-18 09:28:42+01:00
logd0b92a80224e1ed44434ed8546fa2ff497cc5312
tree824e3202bef34232da55fdf4fcd9e73dc32af57d
parentb43bb3a32a3b447e9b320f34e046946bcca0037f
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 36 insertions(+), 5 deletions(-)

lib/compiler/test_runner.zig+5-3
...@@ -17,7 +17,9 @@ var fba_buffer: [8192]u8 = undefined;...@@ -17,7 +17,9 @@ var fba_buffer: [8192]u8 = undefined;
17var stdin_buffer: [4096]u8 = undefined;17var stdin_buffer: [4096]u8 = undefined;
18var stdout_buffer: [4096]u8 = undefined;18var stdout_buffer: [4096]u8 = undefined;
1919
20const crippled = switch (builtin.zig_backend) {20/// Keep in sync with logic in `std.Build.addRunArtifact` which decides whether
21/// the test runner will communicate with the build runner via `std.zig.Server`.
22const need_simple = switch (builtin.zig_backend) {
21 .stage2_aarch64,23 .stage2_aarch64,
22 .stage2_powerpc,24 .stage2_powerpc,
23 .stage2_riscv64,25 .stage2_riscv64,
...@@ -33,7 +35,7 @@ pub fn main() void {...@@ -33,7 +35,7 @@ pub fn main() void {
33 return;35 return;
34 }36 }
3537
36 if (crippled) {38 if (need_simple) {
37 return mainSimple() catch @panic("test failure\n");39 return mainSimple() catch @panic("test failure\n");
38 }40 }
3941
...@@ -380,7 +382,7 @@ pub fn fuzz(...@@ -380,7 +382,7 @@ pub fn fuzz(
380382
381 // Some compiler backends are not capable of handling fuzz testing yet but383 // Some compiler backends are not capable of handling fuzz testing yet but
382 // we still want CI test coverage enabled.384 // we still want CI test coverage enabled.
383 if (crippled) return;385 if (need_simple) return;
384386
385 // Smoke test to ensure the test did not use conditional compilation to387 // Smoke test to ensure the test did not use conditional compilation to
386 // contradict itself by making it not actually be a fuzz test when the test388 // contradict itself by making it not actually be a fuzz test when the test
lib/std/Build.zig+31-2
...@@ -956,8 +956,37 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {...@@ -956,8 +956,37 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
956 run_step.addArtifactArg(exe);956 run_step.addArtifactArg(exe);
957 }957 }
958958
959 const test_server_mode = if (exe.test_runner) |r| r.mode == .server else true;959 const test_server_mode: bool = s: {
960 if (test_server_mode) run_step.enableTestRunnerMode();960 if (exe.test_runner) |r| break :s r.mode == .server;
961 if (exe.use_llvm == false) {
962 // The default test runner does not use the server protocol if the selected backend
963 // is too immature to support it. Keep this logic in sync with `need_simple` in the
964 // default test runner implementation.
965 switch (exe.rootModuleTarget().cpu.arch) {
966 // stage2_aarch64
967 .aarch64,
968 .aarch64_be,
969 // stage2_powerpc
970 .powerpc,
971 .powerpcle,
972 .powerpc64,
973 .powerpc64le,
974 // stage2_riscv64
975 .riscv64,
976 => break :s false,
977
978 else => {},
979 }
980 }
981 break :s true;
982 };
983 if (test_server_mode) {
984 run_step.enableTestRunnerMode();
985 } else if (exe.test_runner == null) {
986 // If a test runner does not use the `std.zig.Server` protocol, it can instead
987 // communicate failure via its exit code.
988 run_step.expectExitCode(0);
989 }
961 } else {990 } else {
962 run_step.addArtifactArg(exe);991 run_step.addArtifactArg(exe);
963 }992 }