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 {
415415 test_step.dependOn(check_fmt);
416416
417417 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 }, .{
419430 .skip_translate_c = skip_translate_c,
420431 .skip_run_translated_c = skip_run_translated_c,
421432 }, .{
test/src/Cases.zig+33-6
......@@ -594,30 +594,57 @@ pub fn lowerToTranslateCSteps(
594594 };
595595}
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
597610pub fn lowerToBuildSteps(
598611 self: *Cases,
599612 b: *std.Build,
600613 parent_step: *std.Build.Step,
601 test_filters: []const []const u8,
602 test_target_filters: []const []const u8,
614 options: CaseTestOptions,
603615) void {
604616 const host = std.zig.system.resolveTargetQuery(.{}) catch |err|
605617 std.debug.panic("unable to detect native host: {s}\n", .{@errorName(err)});
606618 const cases_dir_path = b.build_root.join(b.allocator, &.{ "test", "cases" }) catch @panic("OOM");
607619
608620 for (self.cases.items) |case| {
609 for (test_filters) |test_filter| {
621 for (options.test_filters) |test_filter| {
610622 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
613637 const triple_txt = case.target.query.zigTriple(b.allocator) catch @panic("OOM");
614638
615 if (test_target_filters.len > 0) {
616 for (test_target_filters) |filter| {
639 if (options.test_target_filters.len > 0) {
640 for (options.test_target_filters) |filter| {
617641 if (std.mem.indexOf(u8, triple_txt, filter) != null) break;
618642 } else continue;
619643 }
620644
645 if (options.skip_libc and case.link_libc)
646 continue;
647
621648 const writefiles = b.addWriteFiles();
622649 var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);
623650 defer file_sources.deinit();
test/tests.zig+11-6
......@@ -2517,7 +2517,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
25172517 return step;
25182518}
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 {
25212521 if (use_llvm) |x| return x;
25222522 if (query.ofmt == .c) return false;
25232523 switch (optimize_mode) {
......@@ -2629,9 +2629,8 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step {
26292629pub fn addCases(
26302630 b: *std.Build,
26312631 parent_step: *Step,
2632 test_filters: []const []const u8,
2633 test_target_filters: []const []const u8,
26342632 target: std.Build.ResolvedTarget,
2633 case_test_options: @import("src/Cases.zig").CaseTestOptions,
26352634 translate_c_options: @import("src/Cases.zig").TranslateCOptions,
26362635 build_options: @import("cases.zig").BuildOptions,
26372636) !void {
......@@ -2646,13 +2645,19 @@ pub fn addCases(
26462645 cases.addFromDir(dir, b);
26472646 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
26512657 cases.lowerToBuildSteps(
26522658 b,
26532659 parent_step,
2654 test_filters,
2655 test_target_filters,
2660 case_test_options,
26562661 );
26572662}
26582663