Skip to content

Commit 41304c9

Browse files
Run tls dlopen tests
1 parent b860e07 commit 41304c9

File tree

1 file changed

+104
-8
lines changed

1 file changed

+104
-8
lines changed

build.zig

Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,20 @@ pub fn build(b: *std.Build) !void {
924924
.wasi = .unsupported,
925925
}, false);
926926
installTlsAlignStaticTestCase(&libc_test, .passes, false);
927+
installTlsDlopenTestCase(&libc_test, "functional/tls_align_dlopen.c", "functional/tls_align_dso.c", .{
928+
.darwin = .passes,
929+
.gnu = .passes,
930+
.musl = .unstable,
931+
.mingw = .unsupported,
932+
.wasi = .unsupported,
933+
}, false);
934+
installTlsDlopenTestCase(&libc_test, "functional/tls_init_dlopen.c", "functional/tls_init_dso.c", .{
935+
.darwin = .passes,
936+
.gnu = .passes,
937+
.musl = .unstable,
938+
.mingw = .unsupported,
939+
.wasi = .unsupported,
940+
}, false);
927941
installSimpleTestCase(&libc_test, "functional/tls_init.c", .{
928942
.darwin = .passes,
929943
.gnu = .passes,
@@ -2409,6 +2423,13 @@ pub fn build(b: *std.Build) !void {
24092423
.mingw = .unsupported,
24102424
.wasi = .unsupported,
24112425
}, false);
2426+
installTlsGetNewDtvTestCase(&libc_test, .{
2427+
.darwin = .unsupported,
2428+
.gnu = .passes,
2429+
.musl = .unstable,
2430+
.mingw = .unsupported,
2431+
.wasi = .unsupported,
2432+
}, false);
24122433
installSimpleTestCase(&libc_test, "regression/uselocale-0.c", .{
24132434
.darwin = .passes,
24142435
.gnu = .passes,
@@ -2418,14 +2439,6 @@ pub fn build(b: *std.Build) !void {
24182439
}, false);
24192440
installSimpleTestCase(&libc_test, "regression/wcsncpy-read-overflow.c", .passes, false);
24202441
installSimpleTestCase(&libc_test, "regression/wcsstr-false-negative.c", .passes, false);
2421-
2422-
// TODO
2423-
// "functional/tls_align_dlopen.c"
2424-
// "functional/tls_align_dso.c"
2425-
// "functional/tls_init_dlopen.c"
2426-
// "functional/tls_init_dso.c"
2427-
// "regression/tls_get_new-dtv.c"
2428-
// "regression/tls_get_new-dtv_dso.c"
24292442
}
24302443

24312444
/// Generate options.h based on libc-test/src/common/options.h.in
@@ -2610,10 +2623,90 @@ fn installTlsAlignStaticTestCase(libc_test: *const LibCTest, support: LibCImpl.S
26102623
installTestCase(libc_test, exe, .{});
26112624
}
26122625

2626+
fn installTlsDlopenTestCase(
2627+
libc_test: *const LibCTest,
2628+
case: []const u8,
2629+
library: []const u8,
2630+
support: LibCImpl.Support,
2631+
debug_only: bool,
2632+
) void {
2633+
if (support.shouldSkip(libc_test)) return;
2634+
if (debug_only and libc_test.optimize != .Debug) return;
2635+
2636+
const b = libc_test.b;
2637+
2638+
const test_mod = b.createModule(.{
2639+
.target = libc_test.target,
2640+
.optimize = libc_test.optimize,
2641+
.link_libc = true,
2642+
});
2643+
2644+
test_mod.addIncludePath(libc_test.src.path(b, "common"));
2645+
2646+
test_mod.addCSourceFile(.{
2647+
.file = libc_test.src.path(b, case),
2648+
});
2649+
2650+
test_mod.linkLibrary(libc_test.libtest);
2651+
2652+
const exe = b.addExecutable(.{
2653+
.name = std.fs.path.stem(case),
2654+
.root_module = test_mod,
2655+
});
2656+
2657+
// Copy 'tls_align_dso.so' to '<cache directory>/src/functional'
2658+
const lib = installTestLibrary(libc_test, library);
2659+
const copy_dso = b.addRunArtifact(libc_test.copy_file);
2660+
copy_dso.addFileArg(lib.getEmittedBin());
2661+
const dso = copy_dso.addOutputFileArg(b.fmt("src/functional/{s}.so", .{std.fs.path.stem(library)}));
2662+
2663+
// Use <cache directory> as the working directory for 'tls_align_dlopen'
2664+
const cwd = dso.dirname().dirname().dirname();
2665+
2666+
installTestCase(libc_test, exe, .{ .cwd = cwd });
2667+
}
2668+
2669+
fn installTlsGetNewDtvTestCase(libc_test: *const LibCTest, support: LibCImpl.Support, debug_only: bool) void {
2670+
if (support.shouldSkip(libc_test)) return;
2671+
if (debug_only and libc_test.optimize != .Debug) return;
2672+
2673+
const b = libc_test.b;
2674+
2675+
const test_mod = b.createModule(.{
2676+
.target = libc_test.target,
2677+
.optimize = libc_test.optimize,
2678+
.link_libc = true,
2679+
});
2680+
2681+
test_mod.addIncludePath(libc_test.src.path(b, "common"));
2682+
2683+
test_mod.addCSourceFile(.{
2684+
.file = libc_test.src.path(b, "regression/tls_get_new-dtv.c"),
2685+
});
2686+
2687+
test_mod.addRPathSpecial("$ORIGIN");
2688+
2689+
test_mod.linkLibrary(libc_test.libtest);
2690+
2691+
const exe = b.addExecutable(.{
2692+
.name = "tls_get_new-dtv",
2693+
.root_module = test_mod,
2694+
});
2695+
2696+
// Copy 'tls_get_new-dtv_dso.so' to same directory as 'tls_get_new-dtv' executable
2697+
const lib = installTestLibrary(libc_test, "regression/tls_get_new-dtv_dso.c");
2698+
const copy_dso = b.addRunArtifact(libc_test.copy_file);
2699+
copy_dso.addFileArg(lib.getEmittedBin());
2700+
copy_dso.addFileArg(exe.getEmittedBin().dirname().path(b, "tls_get_new-dtv_dso.so"));
2701+
2702+
installTestCase(libc_test, exe, .{ .run_dep = &copy_dso.step });
2703+
}
2704+
26132705
fn installTestCase(
26142706
libc_test: *const LibCTest,
26152707
exe: *std.Build.Step.Compile,
26162708
options: struct {
2709+
cwd: ?std.Build.LazyPath = null,
26172710
run_dep: ?*std.Build.Step = null,
26182711
},
26192712
) void {
@@ -2622,6 +2715,9 @@ fn installTestCase(
26222715

26232716
const test_run = b.addRunArtifact(exe);
26242717

2718+
if (options.cwd) |cwd|
2719+
test_run.setCwd(cwd);
2720+
26252721
if (options.run_dep) |dep|
26262722
test_run.step.dependOn(dep);
26272723

0 commit comments

Comments
 (0)