authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-07-03 17:21:05+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-07-03 22:18:12+02:00
log9ef4bdf234ed6b58d46452f2286469925f062c39
treee4b76bd468c957ae06d7729052f5f9dbf3794786
parentaa1556156ea861e7746228bf2a1ee686d22e2e24

test: Respect various test skip options in test-cases


3 files changed, 56 insertions(+), 13 deletions(-)

build.zig+12-1
...@@ -415,7 +415,18 @@ pub fn build(b: *std.Build) !void {...@@ -415,7 +415,18 @@ pub fn build(b: *std.Build) !void {
415 test_step.dependOn(check_fmt);415 test_step.dependOn(check_fmt);
416416
417 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");417 const test_cases_step = b.step("test-cases", "Run the main compiler test cases");
418 try tests.addCases(b, test_cases_step, test_filters, test_target_filters, target, .{418 try tests.addCases(b, test_cases_step, target, .{
419 .test_filters = test_filters,
420 .test_target_filters = test_target_filters,
421 .skip_non_native = skip_non_native,
422 .skip_freebsd = skip_freebsd,
423 .skip_netbsd = skip_netbsd,
424 .skip_windows = skip_windows,
425 .skip_macos = skip_macos,
426 .skip_linux = skip_linux,
427 .skip_llvm = skip_llvm,
428 .skip_libc = skip_libc,
429 }, .{
419 .skip_translate_c = skip_translate_c,430 .skip_translate_c = skip_translate_c,
420 .skip_run_translated_c = skip_run_translated_c,431 .skip_run_translated_c = skip_run_translated_c,
421 }, .{432 }, .{
test/src/Cases.zig+33-6
...@@ -594,30 +594,57 @@ pub fn lowerToTranslateCSteps(...@@ -594,30 +594,57 @@ pub fn lowerToTranslateCSteps(
594 };594 };
595}595}
596596
597pub const CaseTestOptions = struct {
598 test_filters: []const []const u8,
599 test_target_filters: []const []const u8,
600 skip_non_native: bool,
601 skip_freebsd: bool,
602 skip_netbsd: bool,
603 skip_windows: bool,
604 skip_macos: bool,
605 skip_linux: bool,
606 skip_llvm: bool,
607 skip_libc: bool,
608};
609
597pub fn lowerToBuildSteps(610pub fn lowerToBuildSteps(
598 self: *Cases,611 self: *Cases,
599 b: *std.Build,612 b: *std.Build,
600 parent_step: *std.Build.Step,613 parent_step: *std.Build.Step,
601 test_filters: []const []const u8,614 options: CaseTestOptions,
602 test_target_filters: []const []const u8,
603) void {615) void {
604 const host = std.zig.system.resolveTargetQuery(.{}) catch |err|616 const host = std.zig.system.resolveTargetQuery(.{}) catch |err|
605 std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});617 std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});
606 const cases_dir_path = b.build_root.join(b.allocator, &.{ "test", "cases" }) catch @panic("OOM");618 const cases_dir_path = b.build_root.join(b.allocator, &.{ "test", "cases" }) catch @panic("OOM");
607619
608 for (self.cases.items) |case| {620 for (self.cases.items) |case| {
609 for (test_filters) |test_filter| {621 for (options.test_filters) |test_filter| {
610 if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;622 if (std.mem.indexOf(u8, case.name, test_filter)) |_| break;
611 } else if (test_filters.len > 0) continue;623 } else if (options.test_filters.len > 0) continue;
624
625 if (options.skip_non_native and !case.target.query.isNative())
626 continue;
627
628 if (options.skip_freebsd and case.target.query.os_tag == .freebsd) continue;
629 if (options.skip_netbsd and case.target.query.os_tag == .netbsd) continue;
630 if (options.skip_windows and case.target.query.os_tag == .windows) continue;
631 if (options.skip_macos and case.target.query.os_tag == .macos) continue;
632 if (options.skip_linux and case.target.query.os_tag == .linux) continue;
633
634 const would_use_llvm = @import("../tests.zig").wouldUseLlvm(case.backend == .llvm, case.target.query, case.optimize_mode);
635 if (options.skip_llvm and would_use_llvm) continue;
612636
613 const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM");637 const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM");
614638
615 if (test_target_filters.len > 0) {639 if (options.test_target_filters.len > 0) {
616 for (test_target_filters) |filter| {640 for (options.test_target_filters) |filter| {
617 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;641 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
618 } else continue;642 } else continue;
619 }643 }
620644
645 if (options.skip_libc and case.link_libc)
646 continue;
647
621 const writefiles = b.addWriteFiles();648 const writefiles = b.addWriteFiles();
622 var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);649 var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);
623 defer file_sources.deinit();650 defer file_sources.deinit();
test/tests.zig+11-6
...@@ -2517,7 +2517,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {...@@ -2517,7 +2517,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
2517 return step;2517 return step;
2518}2518}
25192519
2520fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool {2520pub fn wouldUseLlvm(use_llvm: ?bool, query: std.Target.Query, optimize_mode: OptimizeMode) bool {
2521 if (use_llvm) |x| return x;2521 if (use_llvm) |x| return x;
2522 if (query.ofmt == .c) return false;2522 if (query.ofmt == .c) return false;
2523 switch (optimize_mode) {2523 switch (optimize_mode) {
...@@ -2629,9 +2629,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {...@@ -2629,9 +2629,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
2629pub fn addCases(2629pub fn addCases(
2630 b: *std.Build,2630 b: *std.Build,
2631 parent_step: *Step,2631 parent_step: *Step,
2632 test_filters: []const []const u8,
2633 test_target_filters: []const []const u8,
2634 target: std.Build.ResolvedTarget,2632 target: std.Build.ResolvedTarget,
2633 case_test_options: @import("src/Cases.zig").CaseTestOptions,
2635 translate_c_options: @import("src/Cases.zig").TranslateCOptions,2634 translate_c_options: @import("src/Cases.zig").TranslateCOptions,
2636 build_options: @import("cases.zig").BuildOptions,2635 build_options: @import("cases.zig").BuildOptions,
2637) !void {2636) !void {
...@@ -2646,13 +2645,19 @@ pub fn addCases(...@@ -2646,13 +2645,19 @@ pub fn addCases(
2646 cases.addFromDir(dir, b);2645 cases.addFromDir(dir, b);
2647 try @import("cases.zig").addCases(&cases, build_options, b);2646 try @import("cases.zig").addCases(&cases, build_options, b);
26482647
2649 cases.lowerToTranslateCSteps(b, parent_step, test_filters, test_target_filters, target, translate_c_options);2648 cases.lowerToTranslateCSteps(
2649 b,
2650 parent_step,
2651 case_test_options.test_filters,
2652 case_test_options.test_target_filters,
2653 target,
2654 translate_c_options,
2655 );
26502656
2651 cases.lowerToBuildSteps(2657 cases.lowerToBuildSteps(
2652 b,2658 b,
2653 parent_step,2659 parent_step,
2654 test_filters,2660 case_test_options,
2655 test_target_filters,
2656 );2661 );
2657}2662}
26582663