test/link/macho: upgrade entry and entry in archive tests
This commit is contained in:
@@ -107,14 +107,6 @@ pub const cases = [_]Case{
|
||||
.build_root = "test/link/macho/bugs/16628",
|
||||
.import = @import("link/macho/bugs/16628/build.zig"),
|
||||
},
|
||||
.{
|
||||
.build_root = "test/link/macho/entry",
|
||||
.import = @import("link/macho/entry/build.zig"),
|
||||
},
|
||||
.{
|
||||
.build_root = "test/link/macho/entry_in_archive",
|
||||
.import = @import("link/macho/entry_in_archive/build.zig"),
|
||||
},
|
||||
.{
|
||||
.build_root = "test/link/macho/linksection",
|
||||
.import = @import("link/macho/linksection/build.zig"),
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
|
||||
|
||||
macho_step.dependOn(testDeadStrip(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testEmptyObject(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testEntryPoint(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testHeaderWeakFlags(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testHelloC(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testHelloZig(b, .{ .target = default_target }));
|
||||
@@ -36,6 +36,8 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
|
||||
|
||||
// Tests requiring symlinks when tested on Windows
|
||||
if (build_opts.has_symlinks_windows) {
|
||||
macho_step.dependOn(testEntryPointArchive(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testEntryPointDylib(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testDylib(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target }));
|
||||
@@ -241,6 +243,64 @@ fn testEmptyObject(b: *Build, opts: Options) *Step {
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testEntryPoint(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "macho-entry-point", opts);
|
||||
|
||||
const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
|
||||
\\#include<stdio.h>
|
||||
\\int non_main() {
|
||||
\\ printf("%d", 42);
|
||||
\\ return 0;
|
||||
\\}
|
||||
});
|
||||
exe.entry = .{ .symbol_name = "_non_main" };
|
||||
|
||||
const run = addRunArtifact(exe);
|
||||
run.expectStdOutEqual("42");
|
||||
test_step.dependOn(&run.step);
|
||||
|
||||
const check = exe.checkObject();
|
||||
check.checkInHeaders();
|
||||
check.checkExact("segname __TEXT");
|
||||
check.checkExtract("vmaddr {vmaddr}");
|
||||
check.checkInHeaders();
|
||||
check.checkExact("cmd MAIN");
|
||||
check.checkExtract("entryoff {entryoff}");
|
||||
check.checkInSymtab();
|
||||
check.checkExtract("{n_value} (__TEXT,__text) external _non_main");
|
||||
check.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } });
|
||||
test_step.dependOn(&check.step);
|
||||
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testEntryPointArchive(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "macho-entry-point-archive", opts);
|
||||
|
||||
const lib = addStaticLibrary(b, opts, .{ .name = "main", .c_source_bytes = "int main() { return 0; }" });
|
||||
|
||||
{
|
||||
const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "" });
|
||||
exe.root_module.linkSystemLibrary("main", .{});
|
||||
exe.addLibraryPath(lib.getEmittedBinDirectory());
|
||||
|
||||
const run = addRunArtifact(exe);
|
||||
test_step.dependOn(&run.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = "" });
|
||||
exe.root_module.linkSystemLibrary("main", .{});
|
||||
exe.addLibraryPath(lib.getEmittedBinDirectory());
|
||||
exe.link_gc_sections = true;
|
||||
|
||||
const run = addRunArtifact(exe);
|
||||
test_step.dependOn(&run.step);
|
||||
}
|
||||
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testEntryPointDylib(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "macho-entry-point-dylib", opts);
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const requires_symlinks = true;
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const test_step = b.step("test", "Test it");
|
||||
b.default_step = test_step;
|
||||
|
||||
add(b, test_step, .Debug);
|
||||
add(b, test_step, .ReleaseFast);
|
||||
add(b, test_step, .ReleaseSmall);
|
||||
add(b, test_step, .ReleaseSafe);
|
||||
}
|
||||
|
||||
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "main",
|
||||
.optimize = optimize,
|
||||
.target = b.resolveTargetQuery(.{ .os_tag = .macos }),
|
||||
});
|
||||
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
|
||||
exe.linkLibC();
|
||||
exe.entry = .{ .symbol_name = "_non_main" };
|
||||
|
||||
const check_exe = exe.checkObject();
|
||||
|
||||
check_exe.checkInHeaders();
|
||||
check_exe.checkExact("segname __TEXT");
|
||||
check_exe.checkExtract("vmaddr {vmaddr}");
|
||||
|
||||
check_exe.checkInHeaders();
|
||||
check_exe.checkExact("cmd MAIN");
|
||||
check_exe.checkExtract("entryoff {entryoff}");
|
||||
|
||||
check_exe.checkInSymtab();
|
||||
check_exe.checkExtract("{n_value} (__TEXT,__text) external _non_main");
|
||||
|
||||
check_exe.checkComputeCompare("vmaddr entryoff +", .{ .op = .eq, .value = .{ .variable = "n_value" } });
|
||||
test_step.dependOn(&check_exe.step);
|
||||
|
||||
const run = b.addRunArtifact(exe);
|
||||
run.skip_foreign_checks = true;
|
||||
run.expectStdOutEqual("42");
|
||||
test_step.dependOn(&run.step);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int non_main() {
|
||||
printf("%d", 42);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const requires_symlinks = true;
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const test_step = b.step("test", "Test it");
|
||||
b.default_step = test_step;
|
||||
|
||||
add(b, test_step, .Debug);
|
||||
add(b, test_step, .ReleaseFast);
|
||||
add(b, test_step, .ReleaseSmall);
|
||||
add(b, test_step, .ReleaseSafe);
|
||||
}
|
||||
|
||||
fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "main",
|
||||
.optimize = optimize,
|
||||
.target = b.resolveTargetQuery(.{ .os_tag = .macos }),
|
||||
});
|
||||
lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
|
||||
lib.linkLibC();
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "main",
|
||||
.optimize = optimize,
|
||||
.target = b.resolveTargetQuery(.{ .os_tag = .macos }),
|
||||
});
|
||||
exe.linkLibrary(lib);
|
||||
exe.linkLibC();
|
||||
|
||||
const run = b.addRunArtifact(exe);
|
||||
run.skip_foreign_checks = true;
|
||||
run.expectExitCode(0);
|
||||
test_step.dependOn(&run.step);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user