diff --git a/build.zig b/build.zig index 9fff2398d95c..6c7df798cc95 100644 --- a/build.zig +++ b/build.zig @@ -550,7 +550,7 @@ pub fn build(b: *std.Build) !void { })); test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows)); test_step.dependOn(tests.addStackTraceTests(b, test_filters, optimization_modes)); - test_step.dependOn(tests.addDebugFormatStackTraceTests(b, optimization_modes)); + test_step.dependOn(tests.addDebugFormatStackTraceTests(b, optimization_modes, skip_non_native)); test_step.dependOn(tests.addCliTests(b)); test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filters, optimization_modes)); if (tests.addDebuggerTests(b, .{ diff --git a/test/src/DebugFormatStackTrace.zig b/test/src/DebugFormatStackTrace.zig index 0d7637623506..d9c8fcf0d298 100644 --- a/test/src/DebugFormatStackTrace.zig +++ b/test/src/DebugFormatStackTrace.zig @@ -1,9 +1,14 @@ b: *std.Build, step: *Step, test_index: usize, -optimize_modes: []const OptimizeMode, +targets: []const Target, check_exe: *std.Build.Step.Compile, +pub const Target = struct { + target: std.Target.Query, + optimize_mode: OptimizeMode, +}; + const Config = struct { name: []const u8, source: []const u8, @@ -33,24 +38,28 @@ fn addExpect( debug_format: std.builtin.DebugFormat, mode_config: Config.PerFormat, ) void { - for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return; - const b = this.b; const write_files = b.addWriteFiles(); const source_zig = write_files.add("source.zig", source); - for (this.optimize_modes) |mode| { - if (mem.indexOfScalar(std.builtin.OptimizeMode, mode_config.exclude_optimize_mode, mode)) |_| continue; + add_target_loop: for (this.targets) |target| { + if (mem.indexOfScalar(std.builtin.OptimizeMode, mode_config.exclude_optimize_mode, target.optimize_mode)) |_| continue :add_target_loop; - const annotated_case_name = fmt.allocPrint(b.allocator, "check {s} ({s},{s})", .{ - name, @tagName(debug_format), @tagName(mode), + const resolved_target = b.resolveTargetQuery(target.target); + for (mode_config.exclude_os) |tag| if (tag == resolved_target.result.os.tag) continue :add_target_loop; + + const annotated_case_name = fmt.allocPrint(b.allocator, "check {s}-{s}-{s}-{s}", .{ + name, + @tagName(debug_format), + @tagName(target.optimize_mode), + resolved_target.result.linuxTriple(b.allocator) catch @panic("OOM"), }) catch @panic("OOM"); const exe = b.addExecutable(.{ .name = "test", .root_source_file = source_zig, - .target = b.graph.host, - .optimize = mode, + .target = resolved_target, + .optimize = target.optimize_mode, .debuginfo = debug_format, }); @@ -60,7 +69,7 @@ fn addExpect( // make sure to add term check fist, as `expectStdOutEqual` will detect no expectation for term and make it check for exit code 0 if (mode_config.expect_panic) { - switch (builtin.os.tag) { + switch (resolved_target.result.os.tag) { // Expect exit code 3 on abort: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/abort?view=msvc-170 .windows => run.addCheck(.{ .expect_term = .{ .Exited = 3 } }), else => run.addCheck(.{ .expect_term = .{ .Signal = 6 } }), @@ -81,7 +90,6 @@ fn addExpect( } const std = @import("std"); -const builtin = @import("builtin"); const OptimizeMode = std.builtin.OptimizeMode; const Step = std.Build.Step; const fmt = std.fmt; diff --git a/test/tests.zig b/test/tests.zig index e961948546cb..a6adcecdc356 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -996,6 +996,7 @@ pub fn addStackTraceTests( pub fn addDebugFormatStackTraceTests( b: *std.Build, optimize_modes: []const OptimizeMode, + skip_non_native: bool, ) *Step { const check_exe = b.addExecutable(.{ .name = "check-debug-format-stack-trace", @@ -1004,13 +1005,32 @@ pub fn addDebugFormatStackTraceTests( .optimize = .Debug, }); + const targets = blk: { + var targets = std.ArrayListUnmanaged(DebugFormatStackTraceContext.Target){}; + for (optimize_modes) |optimize_mode| { + targets.append(b.allocator, .{ + .optimize_mode = optimize_mode, + .target = .{}, + }) catch @panic("OOM"); + + if (skip_non_native) continue; + + targets.appendSlice(b.allocator, &.{ + .{ .optimize_mode = optimize_mode, .target = .{ .os_tag = .linux } }, + .{ .optimize_mode = optimize_mode, .target = .{ .os_tag = .windows } }, + .{ .optimize_mode = optimize_mode, .target = .{ .os_tag = .macos } }, + }) catch @panic("OOM"); + } + break :blk targets.toOwnedSlice(b.allocator) catch @panic("OOM"); + }; + const cases = b.allocator.create(DebugFormatStackTraceContext) catch @panic("OOM"); cases.* = .{ .b = b, .step = b.step("test-debug-format-stack-traces", "Run the debug format stack trace tests"), .test_index = 0, .check_exe = check_exe, - .optimize_modes = optimize_modes, + .targets = targets, }; debug_format_stack_traces.addCases(cases);