authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-08 23:51:01+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-08 23:51:30+01:00
log738853459062ccfa9fdea7434b7746e6fe172e3a
tree8373bc0332daa9638db22fe27aa77f244b65c182
parent3bfda3d791c5315712f4c4c2fd0e83c8518d089a

test/link/macho: more self-hosted tests


1 files changed, 43 insertions(+), 8 deletions(-)

test/link/macho.zig+43-8
......@@ -16,7 +16,10 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
1616 });
1717
1818 // Exercise linker with self-hosted backend (no LLVM)
19 macho_step.dependOn(testEmptyZig(b, .{ .use_llvm = false, .target = x86_64_target }));
1920 macho_step.dependOn(testHelloZig(b, .{ .use_llvm = false, .target = x86_64_target }));
21 macho_step.dependOn(testLinkingStaticLib(b, .{ .use_llvm = false, .target = x86_64_target }));
22 macho_step.dependOn(testReexportsZig(b, .{ .use_llvm = false, .target = x86_64_target }));
2023 macho_step.dependOn(testRelocatableZig(b, .{ .use_llvm = false, .target = x86_64_target }));
2124
2225 // Exercise linker with LLVM backend
......@@ -29,6 +32,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
2932 macho_step.dependOn(testHelloZig(b, .{ .target = default_target }));
3033 macho_step.dependOn(testLargeBss(b, .{ .target = default_target }));
3134 macho_step.dependOn(testLayout(b, .{ .target = default_target }));
35 macho_step.dependOn(testLinkingStaticLib(b, .{ .target = default_target }));
3236 macho_step.dependOn(testLinksection(b, .{ .target = default_target }));
3337 macho_step.dependOn(testMhExecuteHeader(b, .{ .target = default_target }));
3438 macho_step.dependOn(testNoDeadStrip(b, .{ .target = default_target }));
......@@ -839,6 +843,44 @@ fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {
839843 return test_step;
840844}
841845
846fn testLinkingStaticLib(b: *Build, opts: Options) *Step {
847 const test_step = addTestStep(b, "linking-static-lib", opts);
848
849 const obj = addObject(b, opts, .{
850 .name = "bobj",
851 .zig_source_bytes = "export var bar: i32 = -42;",
852 });
853
854 const lib = addStaticLibrary(b, opts, .{
855 .name = "alib",
856 .zig_source_bytes =
857 \\export fn foo() i32 {
858 \\ return 42;
859 \\}
860 ,
861 });
862 lib.addObject(obj);
863
864 const exe = addExecutable(b, opts, .{
865 .name = "testlib",
866 .zig_source_bytes =
867 \\const std = @import("std");
868 \\extern fn foo() i32;
869 \\extern var bar: i32;
870 \\pub fn main() void {
871 \\ std.debug.print("{d}\n", .{foo() + bar});
872 \\}
873 ,
874 });
875 exe.linkLibrary(lib);
876
877 const run = addRunArtifact(exe);
878 run.expectStdErrEqual("0\n");
879 test_step.dependOn(&run.step);
880
881 return test_step;
882}
883
842884fn testLinksection(b: *Build, opts: Options) *Step {
843885 const test_step = addTestStep(b, "macho-linksection", opts);
844886
......@@ -1239,14 +1281,7 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step {
12391281 const run = addRunArtifact(exe);
12401282 run.addCheck(.{ .expect_stderr_match = b.dupe("incrFoo=1") });
12411283 run.addCheck(.{ .expect_stderr_match = b.dupe("decrFoo=0") });
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 }
1246 if (builtin.os.tag == .macos) {
1247 const signal: u32 = if (opts.use_llvm) std.os.darwin.SIG.ABRT else std.os.darwin.SIG.TRAP;
1248 run.addCheck(.{ .expect_term = .{ .Signal = signal } });
1249 }
1284 run.addCheck(.{ .expect_stderr_match = b.dupe("panic: Oh no!") });
12501285 test_step.dependOn(&run.step);
12511286
12521287 return test_step;