diff --git a/build.zig b/build.zig index 3c019d38171015207279d3fd6a535e77ea99f6b0..e6e6a4dcbb5ecf31d5f778e84980a21339db4900 100644 --- a/build.zig +++ b/build.zig @@ -660,8 +660,36 @@ pub fn build(b: *std.Build) !void { .skip_llvm = skip_llvm, .max_rss = 100_000_000, })); - test_step.dependOn(tests.addStackTraceTests(b, test_filters, skip_non_native)); - test_step.dependOn(tests.addErrorTraceTests(b, test_filters, optimize_modes, skip_non_native)); + test_step.dependOn(tests.addStackTraceTests(b, .{ + .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_extra_targets = test_extra_targets, + .optimize_modes = optimize_modes, + .skip_non_native = skip_non_native, + .skip_freebsd = skip_freebsd, + .skip_netbsd = skip_netbsd, + .skip_openbsd = skip_openbsd, + .skip_windows = skip_windows, + .skip_darwin = skip_darwin, + .skip_linux = skip_linux, + .skip_llvm = skip_llvm, + .skip_libc = skip_libc, + })); + test_step.dependOn(tests.addErrorTraceTests(b, .{ + .test_filters = test_filters, + .test_target_filters = test_target_filters, + .test_extra_targets = test_extra_targets, + .optimize_modes = optimize_modes, + .skip_non_native = skip_non_native, + .skip_freebsd = skip_freebsd, + .skip_netbsd = skip_netbsd, + .skip_openbsd = skip_openbsd, + .skip_windows = skip_windows, + .skip_darwin = skip_darwin, + .skip_linux = skip_linux, + .skip_llvm = skip_llvm, + .skip_libc = skip_libc, + })); test_step.dependOn(tests.addCliTests(b)); if (tests.addDebuggerTests(b, .{ .test_filters = test_filters, diff --git a/test/src/ErrorTrace.zig b/test/src/ErrorTrace.zig index 7fda389dc6c295a6c950f95a6551945eab878643..edaa5bbb0c2043fad31925dd6b58f4fac869403f 100644 --- a/test/src/ErrorTrace.zig +++ b/test/src/ErrorTrace.zig @@ -7,29 +7,292 @@ const Step = std.Build.Step; const OptimizeMode = std.lang.Optimize; const mem = std.mem; +const tests = @import("../tests.zig"); const error_traces_cases = @import("../error_traces.zig"); b: *std.Build, step: *Step, -test_filters: []const []const u8, -skip_non_native: bool, -optimize_modes: []const OptimizeMode, +options: Options, convert_exe: *std.Build.Step.Compile, -pub const CaseParameters = @import("StackTrace.zig").CaseParameters; +pub const Options = struct { + test_filters: []const []const u8, + test_target_filters: []const []const u8, + test_extra_targets: bool, + optimize_modes: []const OptimizeMode, + skip_non_native: bool, + skip_freebsd: bool, + skip_netbsd: bool, + skip_openbsd: bool, + skip_windows: bool, + skip_darwin: bool, + skip_linux: bool, + skip_llvm: bool, + skip_libc: bool, +}; -const param_sets = [_]CaseParameters{ +pub const CaseParameters = struct { + target: std.Target.Query = .{}, + optimize: std.builtin.OptimizeMode = .debug, + use_llvm: ?bool = null, + use_lld: ?bool = null, + + // This is intended for targets that, for any reason, shouldn't be run as part of a normal test + // invocation. This could be because of a slow backend, requiring a newer LLVM version, being + // too niche, etc. + extra_target: bool = false, +}; + +/// See the comment in `StackTrace.zig`. +pub const param_sets = [_]CaseParameters{ .{}, + + // FreeBSD Targets + .{ - .link_libc = true, + .target = .{ + .cpu_arch = .arm, + .os_tag = .freebsd, + .abi = .eabihf, + }, }, + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .freebsd, + .abi = .none, + }, + }, + + // Linux Targets + + .{ + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .aarch64_be, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .arm, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .armeb, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .hexagon, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .loongarch32, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .loongarch64, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .mipsel, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .abin32, + }, + }, + + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .abin32, + }, + }, + + .{ + .target = .{ + .cpu_arch = .powerpc, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .powerpc64, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .powerpc64le, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .s390x, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .sparc64, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .thumbeb, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .linux, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .none, + }, .use_llvm = true, .use_lld = true, }, .{ - .pie = true, + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .x32, + }, + }, + + // NetBSD Targets + + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .netbsd, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .netbsd, + .abi = .none, + }, }, + + // Windows Targets + .{ .target = .{ .cpu_arch = .aarch64, @@ -39,11 +302,27 @@ const param_sets = [_]CaseParameters{ }, .{ .target = .{ - .cpu_arch = .x86_64, + .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu, }, }, + + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .windows, + .abi = .msvc, + }, + }, + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .windows, + .abi = .gnu, + }, + }, + .{ .target = .{ .cpu_arch = .x86, @@ -53,22 +332,24 @@ const param_sets = [_]CaseParameters{ }, .{ .target = .{ - .cpu_arch = .aarch64, - .os_tag = .macos, + .cpu_arch = .x86, + .os_tag = .windows, + .abi = .gnu, }, }, + .{ .target = .{ - .cpu_arch = .s390x, - .os_tag = .linux, - .abi = .none, + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .msvc, }, }, .{ .target = .{ - .cpu_arch = .loongarch32, - .os_tag = .linux, - .abi = .none, + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .gnu, }, }, }; @@ -97,17 +378,34 @@ pub fn addCases(self: *ErrorTrace) void { for (¶m_sets) |*params| { const resolved_target = b.resolveTargetQuery(params.target); + const target = &resolved_target.result; - if (self.skip_non_native and !resolved_target.query.isNative()) continue; + if (!self.options.test_extra_targets and params.extra_target) continue; - // To avoid redundant testing, skip cross-compilation targets matching the host. - if (resolved_target.result.os.tag == builtin.target.os.tag and - resolved_target.result.cpu.arch == builtin.target.cpu.arch) - { + if (self.options.skip_non_native and !tests.isNative(&resolved_target, &b.graph.host.result)) continue; + + if (self.options.skip_freebsd and target.os.tag == .freebsd) continue; + if (self.options.skip_netbsd and target.os.tag == .netbsd) continue; + if (self.options.skip_openbsd and target.os.tag == .openbsd) continue; + if (self.options.skip_windows and target.os.tag == .windows) continue; + if (self.options.skip_darwin and target.os.tag.isDarwin()) continue; + if (self.options.skip_linux and target.os.tag == .linux) continue; + + const would_use_llvm = tests.wouldUseLlvm(params.use_llvm, params.target, params.optimize); + if (self.options.skip_llvm and would_use_llvm) continue; + + const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); + + if (self.options.test_target_filters.len > 0) { + for (self.options.test_target_filters) |filter| { + if (std.mem.find(u8, triple_txt, filter) != null) break; + } else continue; + } + + if (self.options.skip_libc and std.os.targetRequiresLibC(target)) continue; - } - for (self.optimize_modes) |optimize| { + for (self.options.optimize_modes) |optimize| { if (optimize == params.optimize) break; } else return; @@ -154,8 +452,8 @@ pub fn addCase(self: *ErrorTrace, case: Case) void { params.optimize, backend_string, }); - if (self.test_filters.len > 0) { - for (self.test_filters) |test_filter| { + if (self.options.test_filters.len > 0) { + for (self.options.test_filters) |test_filter| { if (mem.find(u8, annotated_case_name, test_filter)) |_| break; } else return; } diff --git a/test/src/StackTrace.zig b/test/src/StackTrace.zig index c4e4a5fe391a4141fe167681183b761c8fbf806b..523eadab53f0f1e20b5d013203db3ef58a54e84a 100644 --- a/test/src/StackTrace.zig +++ b/test/src/StackTrace.zig @@ -7,15 +7,32 @@ const Step = std.Build.Step; const OptimizeMode = std.lang.Optimize; const mem = std.mem; +const tests = @import("../tests.zig"); const stack_traces_cases = @import("../stack_traces.zig"); b: *std.Build, step: *Step, -test_filters: []const []const u8, -skip_non_native: bool, +options: Options, convert_exe: *std.Build.Step.Compile, +pub const Options = struct { + test_filters: []const []const u8, + test_target_filters: []const []const u8, + test_extra_targets: bool, + optimize_modes: []const OptimizeMode, + skip_non_native: bool, + skip_freebsd: bool, + skip_netbsd: bool, + skip_openbsd: bool, + skip_windows: bool, + skip_darwin: bool, + skip_linux: bool, + skip_llvm: bool, + skip_libc: bool, +}; + pub const CaseParameters = struct { + linkage: ?std.builtin.LinkMode = null, target: std.Target.Query = .{}, optimize: std.builtin.OptimizeMode = .debug, link_libc: ?bool = null, @@ -26,20 +43,814 @@ pub const CaseParameters = struct { /// * The compiler needs to gain the ability to strip only debug info (not symbols) /// * `std.Build.Step.ObjCopy` needs to be un-regressed strip: ?bool = false, + + // This is intended for targets that, for any reason, shouldn't be run as part of a normal test + // invocation. This could be because of a slow backend, requiring a newer LLVM version, being + // too niche, etc. + extra_target: bool = false, }; -const param_sets = [_]CaseParameters{ +/// Only add a non-native target to this set if there's a way to emulate it, or if it can built on a +/// platform with the same arch/OS but has a different ABI. For example, it makes little sense to +/// add `riscv64-netbsd` here because there's no QEMU user-mode emulation for it anyway, and it'll +/// still be covered by the native entries when run on a real `riscv64-netbsd` system. But adding +/// `aarch64-windows-msvc` is valuable because the native entries will default to `gnu` on Windows. +pub const param_sets = [_]CaseParameters{ .{}, .{ .link_libc = true, }, .{ + .pie = true, + }, + .{ + .link_libc = true, + .pie = true, + }, + + // FreeBSD Targets + + .{ + .target = .{ + .cpu_arch = .arm, + .os_tag = .freebsd, + .abi = .eabihf, + }, + }, + + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .freebsd, + .abi = .none, + }, + }, + + // Linux Targets + + .{ + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .aarch64_be, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .aarch64_be, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .aarch64_be, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .aarch64_be, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .arm, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + .{ + .target = .{ + .cpu_arch = .arm, + .os_tag = .linux, + .abi = .musleabihf, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .arm, + .os_tag = .linux, + .abi = .musleabihf, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .arm, + .os_tag = .linux, + .abi = .gnueabihf, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .armeb, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + .{ + .target = .{ + .cpu_arch = .armeb, + .os_tag = .linux, + .abi = .musleabihf, + }, + .link_libc = true, + }, + // Crashes in weird ways when applying relocations. + // .{ + // .target = .{ + // .cpu_arch = .armeb, + // .os_tag = .linux, + // .abi = .musleabihf, + // }, + // .linkage = .dynamic, + // .link_libc = true, + // .extra_target = true, + // }, + .{ + .target = .{ + .cpu_arch = .armeb, + .os_tag = .linux, + .abi = .gnueabihf, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .hexagon, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .hexagon, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .hexagon, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + + .{ + .target = .{ + .cpu_arch = .loongarch32, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .loongarch32, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .loongarch64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .loongarch64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .loongarch64, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .loongarch64, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .musleabihf, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .musleabihf, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mips, + .os_tag = .linux, + .abi = .gnueabihf, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .mipsel, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + .{ + .target = .{ + .cpu_arch = .mipsel, + .os_tag = .linux, + .abi = .musleabihf, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mipsel, + .os_tag = .linux, + .abi = .musleabihf, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mipsel, + .os_tag = .linux, + .abi = .gnueabihf, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .abin32, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .muslabi64, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .muslabi64, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .muslabin32, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .muslabin32, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .gnuabi64, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64, + .os_tag = .linux, + .abi = .gnuabin32, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .abin32, + }, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .muslabi64, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .muslabi64, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .muslabin32, + }, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .muslabin32, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .gnuabi64, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .mips64el, + .os_tag = .linux, + .abi = .gnuabin32, + }, + .link_libc = true, + .extra_target = true, + }, + + .{ + .target = .{ + .cpu_arch = .powerpc, + .os_tag = .linux, + .abi = .eabihf, + }, + }, + .{ + .target = .{ + .cpu_arch = .powerpc, + .os_tag = .linux, + .abi = .musleabihf, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .powerpc, + .os_tag = .linux, + .abi = .musleabihf, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + + .{ + .target = .{ + .cpu_arch = .powerpc64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + + .{ + .target = .{ + .cpu_arch = .powerpc64le, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64le, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64le, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64le, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .riscv64, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .s390x, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .s390x, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + // Currently hangs in qemu-s390x. + // .{ + // .target = .{ + // .cpu_arch = .s390x, + // .os_tag = .linux, + // .abi = .musl, + // }, + // .linkage = .dynamic, + // .link_libc = true, + // .extra_target = true, + // }, + .{ + .target = .{ + .cpu_arch = .s390x, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .sparc64, + .os_tag = .linux, + .abi = .none, + }, + }, + // SPARC linking support is currently incomplete. + // .{ + // .target = .{ + // .cpu_arch = .sparc64, + // .os_tag = .linux, + // .abi = .gnu, + // }, + // .link_libc = true, + // }, + + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .none, + }, .use_llvm = true, .use_lld = true, }, .{ - .pie = true, + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .x32, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .musl, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + .use_llvm = true, + .use_lld = false, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .muslx32, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .muslx32, + }, + .linkage = .dynamic, + .link_libc = true, + .extra_target = true, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .gnu, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .linux, + .abi = .gnux32, + }, + .link_libc = true, }, + + // NetBSD Targets + + .{ + .target = .{ + .cpu_arch = .riscv32, + .os_tag = .netbsd, + .abi = .none, + }, + }, + + .{ + .target = .{ + .cpu_arch = .x86, + .os_tag = .netbsd, + .abi = .none, + }, + }, + + // Windows Targets + .{ .target = .{ .cpu_arch = .aarch64, @@ -49,11 +860,59 @@ const param_sets = [_]CaseParameters{ }, .{ .target = .{ - .cpu_arch = .x86_64, + .cpu_arch = .aarch64, + .os_tag = .windows, + .abi = .msvc, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .aarch64, + .os_tag = .windows, + .abi = .gnu, + }, + }, + .{ + .target = .{ + .cpu_arch = .aarch64, .os_tag = .windows, .abi = .gnu, }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .windows, + .abi = .msvc, + }, }, + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .windows, + .abi = .msvc, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .windows, + .abi = .gnu, + }, + }, + .{ + .target = .{ + .cpu_arch = .thumb, + .os_tag = .windows, + .abi = .gnu, + }, + .link_libc = true, + }, + .{ .target = .{ .cpu_arch = .x86, @@ -63,23 +922,57 @@ const param_sets = [_]CaseParameters{ }, .{ .target = .{ - .cpu_arch = .aarch64, - .os_tag = .macos, + .cpu_arch = .x86, + .os_tag = .windows, + .abi = .msvc, }, + .link_libc = true, }, .{ .target = .{ - .cpu_arch = .s390x, - .os_tag = .linux, - .abi = .none, + .cpu_arch = .x86, + .os_tag = .windows, + .abi = .gnu, }, }, .{ .target = .{ - .cpu_arch = .loongarch32, - .os_tag = .linux, - .abi = .none, + .cpu_arch = .x86, + .os_tag = .windows, + .abi = .gnu, + }, + .link_libc = true, + }, + + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .msvc, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .msvc, + }, + .link_libc = true, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .gnu, + }, + }, + .{ + .target = .{ + .cpu_arch = .x86_64, + .os_tag = .windows, + .abi = .gnu, }, + .link_libc = true, }, }; @@ -112,16 +1005,41 @@ pub fn addCases(self: *StackTrace) void { for (¶m_sets) |*params| { const resolved_target = b.resolveTargetQuery(params.target); + const target = &resolved_target.result; - if (self.skip_non_native and !resolved_target.query.isNative()) continue; + if (!self.options.test_extra_targets and params.extra_target) continue; - // To avoid redundant testing, skip cross-compilation targets matching the host. - if (resolved_target.result.os.tag == builtin.target.os.tag and - resolved_target.result.cpu.arch == builtin.target.cpu.arch) - { - continue; + if (self.options.skip_non_native and !tests.isNative(&resolved_target, &b.graph.host.result)) continue; + + if (self.options.skip_freebsd and target.os.tag == .freebsd) continue; + if (self.options.skip_netbsd and target.os.tag == .netbsd) continue; + if (self.options.skip_openbsd and target.os.tag == .openbsd) continue; + if (self.options.skip_windows and target.os.tag == .windows) continue; + if (self.options.skip_darwin and target.os.tag.isDarwin()) continue; + if (self.options.skip_linux and target.os.tag == .linux) continue; + + const would_use_llvm = tests.wouldUseLlvm(params.use_llvm, params.target, params.optimize); + if (self.options.skip_llvm and would_use_llvm) continue; + + const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); + + if (self.options.test_target_filters.len > 0) { + for (self.options.test_target_filters) |filter| { + if (std.mem.find(u8, triple_txt, filter) != null) break; + } else continue; } + if (self.options.skip_libc and (params.link_libc == true or std.os.targetRequiresLibC(target))) + continue; + + // We can't provide MSVC libc when cross-compiling. + if (target.abi == .msvc and params.link_libc == true and builtin.os.tag != .windows) + continue; + + for (self.options.optimize_modes) |optimize| { + if (optimize == params.optimize) break; + } else return; + stack_traces_cases.addCases(self, params, &resolved_target.result); } } @@ -163,7 +1081,7 @@ pub fn addCase(self: *StackTrace, config: Config) void { else => .unsafe, }; const supports_unwind_tables = switch (target.os.tag) { - // x86-windows just has no way to do stack unwinding other then using frame pointers. + // x86-windows just has no way to do stack unwinding other than using frame pointers. .windows => target.cpu.arch != .x86, else => true, }; @@ -255,19 +1173,22 @@ fn addCaseInstance( else ""; - const annotated_case_name = b.fmt("check {s} ({s}{s}{s}{s}{s}{s}{s}{s})", .{ + const annotated_case_name = b.fmt("check {s} ({s}{s}{s}{s}{s}{s}{s}{s}{s})", .{ name, triple orelse "", if (triple != null) " " else "", backend_string, if (params.pie == true) " pie" else "", if (params.link_libc == true) " libc" else "", + if (params.linkage) |linkage| switch (linkage) { + inline else => |t| " " ++ @tagName(t), + } else "", strip_string, if (strip_unwind) " no_unwind" else "", if (omit_frame_pointer) " no_fp" else "", }); - if (self.test_filters.len > 0) { - for (self.test_filters) |test_filter| { + if (self.options.test_filters.len > 0) { + for (self.options.test_filters) |test_filter| { if (mem.find(u8, annotated_case_name, test_filter)) |_| break; } else return; } @@ -278,7 +1199,7 @@ fn addCaseInstance( .name = "test", .root_module = b.createModule(.{ .root_source_file = source_zig, - .optimize = .Debug, + .optimize = params.optimize, .target = resolved_target, .omit_frame_pointer = omit_frame_pointer, .link_libc = params.link_libc, @@ -289,6 +1210,7 @@ fn addCaseInstance( .use_llvm = params.use_llvm, .use_lld = params.use_lld, }); + exe.linkage = params.linkage; exe.pie = params.pie; exe.bundle_ubsan_rt = false; @@ -296,11 +1218,13 @@ fn addCaseInstance( run.skip_foreign_checks = true; run.removeEnvironmentVariable("CLICOLOR_FORCE"); run.setEnvironmentVariable("NO_COLOR", "1"); - run.addCheck(.{ .expect_term = term: { - if (!expect_panic) break :term .{ .exited = 0 }; - if (resolved_target.result.os.tag == .windows) break :term .{ .exited = 3 }; - break :term .{ .signal = @fromBackingInt(@intCast(6)) }; - } }); + run.addCheck(.{ + .expect_term = term: { + if (!expect_panic) break :term .{ .exited = 0 }; + if (resolved_target.result.os.tag == .windows) break :term .{ .exited = 3 }; + break :term .{ .signal = @fromBackingInt(@intCast(6)) }; // SIGABRT + }, + }); run.expectStdOutEqual(""); const check_run = b.addRunArtifact(self.convert_exe); diff --git a/test/tests.zig b/test/tests.zig index fbb16c5a2fe759dd4840d4670670983898985276..302570d313b69de36c2893104f9ccf3cf925d88e 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -747,7 +747,6 @@ const module_test_targets = blk: { .os_tag = .linux, .abi = .abin32, }, - .extra_target = true, }, .{ .target = .{ @@ -2379,7 +2378,7 @@ pub fn isNative(actual_target: *const std.Build.ResolvedTarget, host: *const std return true; } -pub fn addStackTraceTests(b: *std.Build, test_filters: []const []const u8, skip_non_native: bool) *Step { +pub fn addStackTraceTests(b: *std.Build, options: StackTracesContext.Options) *Step { const step = b.step("test-stack-traces", "Run the stack trace tests"); const convert_exe = b.addExecutable(.{ @@ -2395,8 +2394,7 @@ pub fn addStackTraceTests(b: *std.Build, test_filters: []const []const u8, skip_ stack_traces_context.* = .{ .b = b, .step = step, - .test_filters = test_filters, - .skip_non_native = skip_non_native, + .options = options, .convert_exe = convert_exe, }; stack_traces_context.addCases(); @@ -2404,12 +2402,7 @@ pub fn addStackTraceTests(b: *std.Build, test_filters: []const []const u8, skip_ return step; } -pub fn addErrorTraceTests( - b: *std.Build, - test_filters: []const []const u8, - optimize_modes: []const OptimizeMode, - skip_non_native: bool, -) *Step { +pub fn addErrorTraceTests(b: *std.Build, options: ErrorTracesContext.Options) *Step { const step = b.step("test-error-traces", "Run the error trace tests"); const convert_exe = b.addExecutable(.{ @@ -2425,9 +2418,7 @@ pub fn addErrorTraceTests( error_traces_context.* = .{ .b = b, .step = step, - .test_filters = test_filters, - .skip_non_native = skip_non_native, - .optimize_modes = optimize_modes, + .options = options, .convert_exe = convert_exe, }; error_traces_context.addCases();