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 {
656656 .test_filters = test_filters,
657657 .optimize_modes = optimize_modes,
658658 .skip_non_native = skip_non_native,
659 .skip_freebsd = skip_freebsd,
660 .skip_netbsd = skip_netbsd,
661 .skip_openbsd = skip_openbsd,
659662 .skip_windows = skip_windows,
663 .skip_darwin = skip_darwin,
664 .skip_linux = skip_linux,
660665 .skip_llvm = skip_llvm,
666 .skip_libc = skip_libc,
661667 .max_rss = 100_000_000,
662668 }));
663669 test_step.dependOn(tests.addStackTraceTests(b, .{
......@@ -772,7 +778,19 @@ pub fn build(b: *std.Build) !void {
772778 }
773779
774780 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 });
776794 if (!skip_test_incremental) test_step.dependOn(test_incremental_step);
777795
778796 if (tests.addLibcTestNszTests(b, .{
test/tests.zig+111-21
......@@ -2250,23 +2250,57 @@ const link_targets = blk: {
22502250 };
22512251};
22522252
2253/// Unlike `test_targets` and `c_abi_targets`, these targets are just simple strings which we pass
2254/// directly to `incr-check`. They include the target triple and the compiler backend.
2253const IncrementalTarget = struct {
2254 target: std.Target.Query,
2255 backend: enum { selfhosted, llvm, cbe },
2256};
2257
2258/// These are passed to `incr-check` as `<target>-<backend>` strings.
22552259///
22562260/// If only one specific test is failing on a target, instead of entirely disabling the target here,
22572261/// you can skip the target for that specific test only by adding a line like this to the manifest:
22582262/// #skip_target=x86_64-linux-selfhosted
2259const incremental_targets: []const []const u8 = &.{
2263const incremental_targets = &[_]IncrementalTarget{
22602264 // Avoid adding more CBE or LLVM targets without good reason: they're a lot slower than others
22612265 // to run due to the output (C source code or LLVM IR) being built non-incrementally (by Clang
22622266 // or LLVM). We just have a couple here to make sure that it works.
2263 "x86_64-linux-cbe",
2264 "x86_64-linux-llvm",
2267 .{
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 },
22672289 // https://codeberg.org/ziglang/zig/issues/31773
2268 //"x86_64-windows-selfhosted",
2269 "wasm32-wasi-selfhosted",
2290 // .{
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 },
22702304};
22712305
22722306fn compatible32bitArch(host: *const std.Target) ?std.Target.Cpu.Arch {
......@@ -3164,8 +3198,14 @@ const LinkTestOptions = struct {
31643198 test_filters: []const []const u8,
31653199 optimize_modes: []const OptimizeMode,
31663200 skip_non_native: bool,
3201 skip_freebsd: bool,
3202 skip_netbsd: bool,
3203 skip_openbsd: bool,
31673204 skip_windows: bool,
3205 skip_darwin: bool,
3206 skip_linux: bool,
31683207 skip_llvm: bool,
3208 skip_libc: bool,
31693209 max_rss: usize,
31703210};
31713211
......@@ -3178,22 +3218,37 @@ pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step {
31783218 ) orelse false;
31793219
31803220 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
31843221 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
31863226 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
31883237 if (options.test_target_filters.len > 0) {
31893238 for (options.test_target_filters) |filter| {
31903239 if (std.mem.find(u8, triple_txt, filter) != null) break;
31913240 } else continue;
31923241 }
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
31943250 for (options.optimize_modes) |optimize_mode| {
31953251 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;
31973252 const would_use_llvm = wouldUseLlvm(link_target.use_llvm, link_target.target, optimize_mode);
31983253 if (options.skip_llvm and would_use_llvm) continue;
31993254
......@@ -3290,11 +3345,24 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step
32903345 return step;
32913346}
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
32933362pub fn addIncrementalTests(
32943363 b: *std.Build,
32953364 test_step: *Step,
3296 test_filters: []const []const u8,
3297 test_target_filters: []const []const u8,
3365 options: IncrementalTestOptions,
32983366) !void {
32993367 const io = b.graph.io;
33003368
......@@ -3316,9 +3384,9 @@ pub fn addIncrementalTests(
33163384 while (try it.next(io)) |entry| {
33173385 if (std.mem.endsWith(u8, entry.basename, ".swp")) continue;
33183386
3319 for (test_filters) |test_filter| {
3387 for (options.test_filters) |test_filter| {
33203388 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
33233391 switch (entry.kind) {
33243392 .file => {},
......@@ -3329,13 +3397,35 @@ pub fn addIncrementalTests(
33293397 }
33303398 b.dependOnFileContents(b.path(b.pathJoin(&.{ "test", "incremental", entry.path })));
33313399
3332 for (incremental_targets) |target_str| {
3333 if (test_target_filters.len > 0) {
3334 for (test_target_filters) |filter| {
3335 if (std.mem.find(u8, target_str, filter) != null) break;
3400 for (incremental_targets) |test_target| {
3401 const resolved_target = b.resolveTargetQuery(test_target.target);
3402
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;
33363424 } else continue;
33373425 }
33383426
3427 const target_str = b.fmt("{s}-{t}", .{ triple_txt, test_target.backend });
3428
33393429 const run = b.addRunArtifact(incr_check);
33403430 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename }));
33413431