test/link/macho: upgrade tls test
This commit is contained in:
@@ -163,10 +163,6 @@ pub const cases = [_]Case{
|
||||
.build_root = "test/link/macho/tbdv3",
|
||||
.import = @import("link/macho/tbdv3/build.zig"),
|
||||
},
|
||||
.{
|
||||
.build_root = "test/link/macho/tls",
|
||||
.import = @import("link/macho/tls/build.zig"),
|
||||
},
|
||||
.{
|
||||
.build_root = "test/link/macho/unwind_info",
|
||||
.import = @import("link/macho/unwind_info/build.zig"),
|
||||
|
||||
@@ -34,6 +34,7 @@ pub fn testAll(b: *Build, build_opts: BuildOptions) *Step {
|
||||
if (build_opts.has_symlinks_windows) {
|
||||
macho_step.dependOn(testNeededLibrary(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testWeakLibrary(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testTls(b, .{ .target = default_target }));
|
||||
macho_step.dependOn(testTwoLevelNamespace(b, .{ .target = default_target }));
|
||||
|
||||
// Tests requiring presence of macOS SDK in system path
|
||||
@@ -673,6 +674,40 @@ fn testThunks(b: *Build, opts: Options) *Step {
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testTls(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "macho-tls", opts);
|
||||
|
||||
const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes =
|
||||
\\_Thread_local int a;
|
||||
\\int getA() {
|
||||
\\ return a;
|
||||
\\}
|
||||
});
|
||||
|
||||
const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
|
||||
\\#include<stdio.h>
|
||||
\\extern _Thread_local int a;
|
||||
\\extern int getA();
|
||||
\\int getA2() {
|
||||
\\ return a;
|
||||
\\}
|
||||
\\int main() {
|
||||
\\ a = 2;
|
||||
\\ printf("%d %d %d", a, getA(), getA2());
|
||||
\\ return 0;
|
||||
\\}
|
||||
});
|
||||
exe.root_module.linkSystemLibrary("a", .{});
|
||||
exe.addLibraryPath(dylib.getEmittedBinDirectory());
|
||||
exe.addRPath(dylib.getEmittedBinDirectory());
|
||||
|
||||
const run = addRunArtifact(exe);
|
||||
run.expectStdOutEqual("2 2 2");
|
||||
test_step.dependOn(&run.step);
|
||||
|
||||
return test_step;
|
||||
}
|
||||
|
||||
fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
|
||||
const test_step = addTestStep(b, "macho-tls-large-tbss", opts);
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
_Thread_local int a;
|
||||
|
||||
int getA() {
|
||||
return a;
|
||||
}
|
||||
@@ -1,39 +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 target = b.resolveTargetQuery(.{ .os_tag = .macos });
|
||||
|
||||
const lib = b.addSharedLibrary(.{
|
||||
.name = "a",
|
||||
.version = .{ .major = 1, .minor = 0, .patch = 0 },
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
|
||||
lib.linkLibC();
|
||||
|
||||
const test_exe = b.addTest(.{
|
||||
.root_source_file = .{ .path = "main.zig" },
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
});
|
||||
test_exe.linkLibrary(lib);
|
||||
test_exe.linkLibC();
|
||||
|
||||
const run = b.addRunArtifact(test_exe);
|
||||
run.skip_foreign_checks = true;
|
||||
|
||||
test_step.dependOn(&run.step);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
extern threadlocal var a: i32;
|
||||
extern fn getA() i32;
|
||||
|
||||
fn getA2() i32 {
|
||||
return a;
|
||||
}
|
||||
|
||||
test {
|
||||
a = 2;
|
||||
try std.testing.expect(getA() == 2);
|
||||
try std.testing.expect(2 == getA2());
|
||||
try std.testing.expect(getA() == getA2());
|
||||
}
|
||||
Reference in New Issue
Block a user