authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-03 17:57:35+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-03 17:57:35+01:00
log4ebd0036fd6d1d51e8cd6693abe77c2eb2f5e743
tree2eb0cb0c687f2950dc70a75267deb068e3d42423
parent7641561f2d538cdccf452bc801a1bea88b91fed7

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


2 files changed, 24 insertions(+), 4 deletions(-)

test/link/link.zig+12-3
......@@ -27,14 +27,23 @@ pub const Options = struct {
2727 optimize: std.builtin.OptimizeMode = .Debug,
2828 use_llvm: bool = true,
2929 use_lld: bool = false,
30 strip: ?bool = null,
3031};
3132
3233pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step {
3334 const target = opts.target.result.zigTriple(b.allocator) catch @panic("OOM");
3435 const optimize = @tagName(opts.optimize);
3536 const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm";
36 const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}", .{
37 prefix, target, optimize, use_llvm,
37 const use_lld = if (opts.use_lld) "lld" else "no-lld";
38 if (opts.strip) |strip| {
39 const s = if (strip) "strip" else "no-strip";
40 const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}-{s}-{s}", .{
41 prefix, target, optimize, use_llvm, use_lld, s,
42 }) catch @panic("OOM");
43 return b.step(name, "");
44 }
45 const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}-{s}", .{
46 prefix, target, optimize, use_llvm, use_lld,
3847 }) catch @panic("OOM");
3948 return b.step(name, "");
4049}
......@@ -87,7 +96,7 @@ fn addCompileStep(
8796 break :rsf b.addWriteFiles().add("a.zig", bytes);
8897 },
8998 .pic = overlay.pic,
90 .strip = overlay.strip,
99 .strip = if (base.strip) |s| s else overlay.strip,
91100 },
92101 .use_llvm = base.use_llvm,
93102 .use_lld = base.use_lld,
test/link/macho.zig+12-1
......@@ -15,6 +15,11 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
1515 .os_tag = .macos,
1616 });
1717
18 // Exercise linker with self-hosted backend (no LLVM)
19 macho_step.dependOn(testHelloZig(b, .{ .use_llvm = false, .target = x86_64_target }));
20 macho_step.dependOn(testRelocatableZig(b, .{ .use_llvm = false, .strip = true, .target = x86_64_target }));
21
22 // Exercise linker with LLVM backend
1823 macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
1924 macho_step.dependOn(testEmptyObject(b, .{ .target = default_target }));
2025 macho_step.dependOn(testEmptyZig(b, .{ .target = default_target }));
......@@ -1234,7 +1239,13 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step {
12341239 const run = addRunArtifact(exe);
12351240 run.addCheck(.{ .expect_stderr_match = b.dupe("incrFoo=1") });
12361241 run.addCheck(.{ .expect_stderr_match = b.dupe("decrFoo=0") });
1237 run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
1242 if (opts.use_llvm) {
1243 // TODO: enable this once self-hosted can print panics and stack traces
1244 run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
1245 run.addCheck(.{ .expect_term = .{ .Signal = std.os.darwin.SIG.ABRT } });
1246 } else {
1247 run.addCheck(.{ .expect_term = .{ .Signal = std.os.darwin.SIG.TRAP } });
1248 }
12381249 test_step.dependOn(&run.step);
12391250
12401251 return test_step;