test/link/macho: add some smoke tests for self-hosted MachO

This commit is contained in:
Jakub Konka 2024-02-03 17:57:35 +01:00
parent 7641561f2d
commit 4ebd0036fd
2 changed files with 24 additions and 4 deletions

View File

@ -27,14 +27,23 @@ pub const Options = struct {
optimize: std.builtin.OptimizeMode = .Debug,
use_llvm: bool = true,
use_lld: bool = false,
strip: ?bool = null,
};
pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step {
const target = opts.target.result.zigTriple(b.allocator) catch @panic("OOM");
const optimize = @tagName(opts.optimize);
const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm";
const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}", .{
prefix, target, optimize, use_llvm,
const use_lld = if (opts.use_lld) "lld" else "no-lld";
if (opts.strip) |strip| {
const s = if (strip) "strip" else "no-strip";
const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}-{s}-{s}", .{
prefix, target, optimize, use_llvm, use_lld, s,
}) catch @panic("OOM");
return b.step(name, "");
}
const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}-{s}", .{
prefix, target, optimize, use_llvm, use_lld,
}) catch @panic("OOM");
return b.step(name, "");
}
@ -87,7 +96,7 @@ fn addCompileStep(
break :rsf b.addWriteFiles().add("a.zig", bytes);
},
.pic = overlay.pic,
.strip = overlay.strip,
.strip = if (base.strip) |s| s else overlay.strip,
},
.use_llvm = base.use_llvm,
.use_lld = base.use_lld,

View File

@ -15,6 +15,11 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
.os_tag = .macos,
});
// Exercise linker with self-hosted backend (no LLVM)
macho_step.dependOn(testHelloZig(b, .{ .use_llvm = false, .target = x86_64_target }));
macho_step.dependOn(testRelocatableZig(b, .{ .use_llvm = false, .strip = true, .target = x86_64_target }));
// Exercise linker with LLVM backend
macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
macho_step.dependOn(testEmptyObject(b, .{ .target = default_target }));
macho_step.dependOn(testEmptyZig(b, .{ .target = default_target }));
@ -1234,7 +1239,13 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step {
const run = addRunArtifact(exe);
run.addCheck(.{ .expect_stderr_match = b.dupe("incrFoo=1") });
run.addCheck(.{ .expect_stderr_match = b.dupe("decrFoo=0") });
run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
if (opts.use_llvm) {
// TODO: enable this once self-hosted can print panics and stack traces
run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
run.addCheck(.{ .expect_term = .{ .Signal = std.os.darwin.SIG.ABRT } });
} else {
run.addCheck(.{ .expect_term = .{ .Signal = std.os.darwin.SIG.TRAP } });
}
test_step.dependOn(&run.step);
return test_step;