authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-31 02:04:59+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-31 02:04:59+02:00
log079f9e65d282781646bdf47b690cf9e0d179c198
tree6810e6b6a02e8140932777219f2ca827b437d48d
parentfbdf84138ee8320c3edcd396f229e152307baebf
parent6534993573f184c78733ab5a05c61b4860c71d87

Merge pull request 'test: improve skip checks' (#36693) from alexrp/zig:better-test-skips into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36693

2 files changed, 130 insertions(+), 22 deletions(-)

build.zig+19-1
...@@ -656,8 +656,14 @@ pub fn build(b: *std.Build) !void {...@@ -656,8 +656,14 @@ pub fn build(b: *std.Build) !void {
656 .test_filters = test_filters,656 .test_filters = test_filters,
657 .optimize_modes = optimize_modes,657 .optimize_modes = optimize_modes,
658 .skip_non_native = skip_non_native,658 .skip_non_native = skip_non_native,
659 .skip_freebsd = skip_freebsd,
660 .skip_netbsd = skip_netbsd,
661 .skip_openbsd = skip_openbsd,
659 .skip_windows = skip_windows,662 .skip_windows = skip_windows,
663 .skip_darwin = skip_darwin,
664 .skip_linux = skip_linux,
660 .skip_llvm = skip_llvm,665 .skip_llvm = skip_llvm,
666 .skip_libc = skip_libc,
661 .max_rss = 100_000_000,667 .max_rss = 100_000_000,
662 }));668 }));
663 test_step.dependOn(tests.addStackTraceTests(b, .{669 test_step.dependOn(tests.addStackTraceTests(b, .{
...@@ -772,7 +778,19 @@ pub fn build(b: *std.Build) !void {...@@ -772,7 +778,19 @@ pub fn build(b: *std.Build) !void {
772 }778 }
773779
774 const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases");780 const test_incremental_step = b.step("test-incremental", "Run the incremental compilation test cases");
775 try tests.addIncrementalTests(b, test_incremental_step, test_filters, test_target_filters);781 try tests.addIncrementalTests(b, test_incremental_step, .{
782 .test_filters = test_filters,
783 .test_target_filters = test_target_filters,
784 .skip_non_native = skip_non_native,
785 .skip_wasm = skip_wasm,
786 .skip_freebsd = skip_freebsd,
787 .skip_netbsd = skip_netbsd,
788 .skip_openbsd = skip_openbsd,
789 .skip_windows = skip_windows,
790 .skip_darwin = skip_darwin,
791 .skip_linux = skip_linux,
792 .skip_llvm = skip_llvm,
793 });
776 if (!skip_test_incremental) test_step.dependOn(test_incremental_step);794 if (!skip_test_incremental) test_step.dependOn(test_incremental_step);
777795
778 if (tests.addLibcTestNszTests(b, .{796 if (tests.addLibcTestNszTests(b, .{
test/tests.zig+111-21
...@@ -2250,23 +2250,57 @@ const link_targets = blk: {...@@ -2250,23 +2250,57 @@ const link_targets = blk: {
2250 };2250 };
2251};2251};
22522252
2253/// Unlike `test_targets` and `c_abi_targets`, these targets are just simple strings which we pass2253const IncrementalTarget = struct {
2254/// directly to `incr-check`. They include the target triple and the compiler backend.2254 target: std.Target.Query,
2255 backend: enum { selfhosted, llvm, cbe },
2256};
2257
2258/// These are passed to `incr-check` as `<target>-<backend>` strings.
2255///2259///
2256/// If only one specific test is failing on a target, instead of entirely disabling the target here,2260/// If only one specific test is failing on a target, instead of entirely disabling the target here,
2257/// you can skip the target for that specific test only by adding a line like this to the manifest:2261/// you can skip the target for that specific test only by adding a line like this to the manifest:
2258/// #skip_target=x86_64-linux-selfhosted2262/// #skip_target=x86_64-linux-selfhosted
2259const incremental_targets: []const []const u8 = &.{2263const incremental_targets = &[_]IncrementalTarget{
2260 // Avoid adding more CBE or LLVM targets without good reason: they're a lot slower than others2264 // Avoid adding more CBE or LLVM targets without good reason: they're a lot slower than others
2261 // to run due to the output (C source code or LLVM IR) being built non-incrementally (by Clang2265 // to run due to the output (C source code or LLVM IR) being built non-incrementally (by Clang
2262 // or LLVM). We just have a couple here to make sure that it works.2266 // or LLVM). We just have a couple here to make sure that it works.
2263 "x86_64-linux-cbe",2267 .{
2264 "x86_64-linux-llvm",2268 .target = .{
2269 .cpu_arch = .x86_64,
2270 .os_tag = .linux,
2271 },
2272 .backend = .cbe,
2273 },
2274 .{
2275 .target = .{
2276 .cpu_arch = .x86_64,
2277 .os_tag = .linux,
2278 },
2279 .backend = .llvm,
2280 },
22652281
2266 "x86_64-linux-selfhosted",2282 .{
2283 .target = .{
2284 .cpu_arch = .x86_64,
2285 .os_tag = .linux,
2286 },
2287 .backend = .selfhosted,
2288 },
2267 // https://codeberg.org/ziglang/zig/issues/317732289 // https://codeberg.org/ziglang/zig/issues/31773
2268 //"x86_64-windows-selfhosted",2290 // .{
2269 "wasm32-wasi-selfhosted",2291 // .target = .{
2292 // .cpu_arch = .x86_64,
2293 // .os_tag = .windows,
2294 // },
2295 // .backend = .selfhosted,
2296 // },
2297 .{
2298 .target = .{
2299 .cpu_arch = .wasm32,
2300 .os_tag = .wasi,
2301 },
2302 .backend = .selfhosted,
2303 },
2270};2304};
22712305
2272fn compatible32bitArch(host: *const std.Target) ?std.Target.Cpu.Arch {2306fn compatible32bitArch(host: *const std.Target) ?std.Target.Cpu.Arch {
...@@ -3164,8 +3198,14 @@ const LinkTestOptions = struct {...@@ -3164,8 +3198,14 @@ const LinkTestOptions = struct {
3164 test_filters: []const []const u8,3198 test_filters: []const []const u8,
3165 optimize_modes: []const OptimizeMode,3199 optimize_modes: []const OptimizeMode,
3166 skip_non_native: bool,3200 skip_non_native: bool,
3201 skip_freebsd: bool,
3202 skip_netbsd: bool,
3203 skip_openbsd: bool,
3167 skip_windows: bool,3204 skip_windows: bool,
3205 skip_darwin: bool,
3206 skip_linux: bool,
3168 skip_llvm: bool,3207 skip_llvm: bool,
3208 skip_libc: bool,
3169 max_rss: usize,3209 max_rss: usize,
3170};3210};
31713211
...@@ -3178,22 +3218,37 @@ pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step {...@@ -3178,22 +3218,37 @@ pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step {
3178 ) orelse false;3218 ) orelse false;
31793219
3180 for (link_targets) |link_target| {3220 for (link_targets) |link_target| {
3181 if (options.skip_non_native and !link_target.target.isNative()) continue;
3182 if (options.skip_windows and link_target.target.os_tag == .windows) continue;
3183
3184 const resolved_target = b.resolveTargetQuery(link_target.target);3221 const resolved_target = b.resolveTargetQuery(link_target.target);
3185 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");3222
3223 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
3224 continue;
3225
3186 const target = &resolved_target.result;3226 const target = &resolved_target.result;
31873227
3228 if (options.skip_freebsd and target.os.tag == .freebsd) continue;
3229 if (options.skip_netbsd and target.os.tag == .netbsd) continue;
3230 if (options.skip_openbsd and target.os.tag == .openbsd) continue;
3231 if (options.skip_windows and target.os.tag == .windows) continue;
3232 if (options.skip_darwin and target.os.tag.isDarwin()) continue;
3233 if (options.skip_linux and target.os.tag == .linux) continue;
3234
3235 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
3236
3188 if (options.test_target_filters.len > 0) {3237 if (options.test_target_filters.len > 0) {
3189 for (options.test_target_filters) |filter| {3238 for (options.test_target_filters) |filter| {
3190 if (std.mem.find(u8, triple_txt, filter) != null) break;3239 if (std.mem.find(u8, triple_txt, filter) != null) break;
3191 } else continue;3240 } else continue;
3192 }3241 }
31933242
3243 if (options.skip_libc and (link_target.link_libc == true or std.os.targetRequiresLibC(target)))
3244 continue;
3245
3246 // We can't provide MSVC libc when cross-compiling.
3247 if (target.abi == .msvc and link_target.link_libc == true and builtin.os.tag != .windows)
3248 continue;
3249
3194 for (options.optimize_modes) |optimize_mode| {3250 for (options.optimize_modes) |optimize_mode| {
3195 if (link_target.optimize_mode != optimize_mode) continue;3251 if (link_target.optimize_mode != optimize_mode) continue;
3196 if (link_target.link_libc and target.abi == .msvc and b.graph.host.result.os.tag != .windows) continue;
3197 const would_use_llvm = wouldUseLlvm(link_target.use_llvm, link_target.target, optimize_mode);3252 const would_use_llvm = wouldUseLlvm(link_target.use_llvm, link_target.target, optimize_mode);
3198 if (options.skip_llvm and would_use_llvm) continue;3253 if (options.skip_llvm and would_use_llvm) continue;
31993254
...@@ -3290,11 +3345,24 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step...@@ -3290,11 +3345,24 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
3290 return step;3345 return step;
3291}3346}
32923347
3348const IncrementalTestOptions = struct {
3349 test_filters: []const []const u8,
3350 test_target_filters: []const []const u8,
3351 skip_non_native: bool,
3352 skip_wasm: bool,
3353 skip_freebsd: bool,
3354 skip_netbsd: bool,
3355 skip_openbsd: bool,
3356 skip_windows: bool,
3357 skip_darwin: bool,
3358 skip_linux: bool,
3359 skip_llvm: bool,
3360};
3361
3293pub fn addIncrementalTests(3362pub fn addIncrementalTests(
3294 b: *std.Build,3363 b: *std.Build,
3295 test_step: *Step,3364 test_step: *Step,
3296 test_filters: []const []const u8,3365 options: IncrementalTestOptions,
3297 test_target_filters: []const []const u8,
3298) !void {3366) !void {
3299 const io = b.graph.io;3367 const io = b.graph.io;
33003368
...@@ -3316,9 +3384,9 @@ pub fn addIncrementalTests(...@@ -3316,9 +3384,9 @@ pub fn addIncrementalTests(
3316 while (try it.next(io)) |entry| {3384 while (try it.next(io)) |entry| {
3317 if (std.mem.endsWith(u8, entry.basename, ".swp")) continue;3385 if (std.mem.endsWith(u8, entry.basename, ".swp")) continue;
33183386
3319 for (test_filters) |test_filter| {3387 for (options.test_filters) |test_filter| {
3320 if (std.mem.find(u8, entry.path, test_filter)) |_| break;3388 if (std.mem.find(u8, entry.path, test_filter)) |_| break;
3321 } else if (test_filters.len > 0) continue;3389 } else if (options.test_filters.len > 0) continue;
33223390
3323 switch (entry.kind) {3391 switch (entry.kind) {
3324 .file => {},3392 .file => {},
...@@ -3329,13 +3397,35 @@ pub fn addIncrementalTests(...@@ -3329,13 +3397,35 @@ pub fn addIncrementalTests(
3329 }3397 }
3330 b.dependOnFileContents(b.path(b.pathJoin(&.{ "test", "incremental", entry.path })));3398 b.dependOnFileContents(b.path(b.pathJoin(&.{ "test", "incremental", entry.path })));
33313399
3332 for (incremental_targets) |target_str| {3400 for (incremental_targets) |test_target| {
3333 if (test_target_filters.len > 0) {3401 const resolved_target = b.resolveTargetQuery(test_target.target);
3334 for (test_target_filters) |filter| {3402
3335 if (std.mem.find(u8, target_str, filter) != null) break;3403 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result))
3404 continue;
3405
3406 const target = &resolved_target.result;
3407
3408 if (options.skip_wasm and target.cpu.arch.isWasm()) continue;
3409
3410 if (options.skip_freebsd and target.os.tag == .freebsd) continue;
3411 if (options.skip_netbsd and target.os.tag == .netbsd) continue;
3412 if (options.skip_openbsd and target.os.tag == .openbsd) continue;
3413 if (options.skip_windows and target.os.tag == .windows) continue;
3414 if (options.skip_darwin and target.os.tag.isDarwin()) continue;
3415 if (options.skip_linux and target.os.tag == .linux) continue;
3416
3417 if (options.skip_llvm and test_target.backend == .llvm) continue;
3418
3419 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM");
3420
3421 if (options.test_target_filters.len > 0) {
3422 for (options.test_target_filters) |filter| {
3423 if (std.mem.find(u8, triple_txt, filter) != null) break;
3336 } else continue;3424 } else continue;
3337 }3425 }
33383426
3427 const target_str = b.fmt("{s}-{t}", .{ triple_txt, test_target.backend });
3428
3339 const run = b.addRunArtifact(incr_check);3429 const run = b.addRunArtifact(incr_check);
3340 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename }));3430 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename }));
33413431