authorgravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-08-06 21:50:56-07:00
committergravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2025-09-09 22:07:44-07:00
logc614d8d0081782116e94f3c8bfbf4ea515e7a3f3
treed905648f52ac6156931db09df426477bf6b7a3f6
parente46ddeeb296aeb259d1bb9f96cb977f4868309e7

standalone posix tests: add skeleton

Add build.zig, README and empty test files.

7 files changed, 87 insertions(+), 0 deletions(-)

test/standalone/build.zig.zon+3
...@@ -211,6 +211,9 @@...@@ -211,6 +211,9 @@
211 .tsan = .{211 .tsan = .{
212 .path = "tsan",212 .path = "tsan",
213 },213 },
214 .posix = .{
215 .path = "posix",
216 },
214 },217 },
215 .paths = .{218 .paths = .{
216 "build.zig",219 "build.zig",
test/standalone/posix/README.md created+8
...@@ -0,0 +1,8 @@
1## Zig standalone POSIX tests
2
3This directory is just for std.posix-related test cases that depend on
4process-wide state like the current-working directory, signal handlers,
5fork, the main thread, environment variables, etc. Most tests (e.g,
6around file descriptors, etc) are with the unit tests in
7`lib/std/posix/test.zig`. New tests should be with the unit tests, unless
8there is a specific reason they cannot.
test/standalone/posix/build.zig created+72
...@@ -0,0 +1,72 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4const Case = struct {
5 src_path: []const u8,
6};
7
8const cases = [_]Case{
9 .{
10 .src_path = "cwd.zig",
11 },
12 .{
13 .src_path = "getenv.zig",
14 },
15 .{
16 .src_path = "sigaction.zig",
17 },
18 .{
19 .src_path = "relpaths.zig",
20 },
21};
22
23pub fn build(b: *std.Build) void {
24 const test_step = b.step("test", "Run POSIX standalone test cases");
25 b.default_step = test_step;
26
27 const optimize = b.standardOptimizeOption(.{});
28
29 const default_target = b.resolveTargetQuery(.{});
30
31 // Run each test case built against libc-less, glibc, and musl.
32 for (cases) |case| {
33 const run_def = run_exe(b, optimize, &case, default_target, false);
34 test_step.dependOn(&run_def.step);
35
36 if (default_target.result.os.tag == .linux) {
37 const gnu_target = b.resolveTargetQuery(.{ .abi = .gnu });
38 const musl_target = b.resolveTargetQuery(.{ .abi = .musl });
39
40 const run_gnu = run_exe(b, optimize, &case, gnu_target, true);
41 const run_musl = run_exe(b, optimize, &case, musl_target, true);
42
43 test_step.dependOn(&run_gnu.step);
44 test_step.dependOn(&run_musl.step);
45 } else {
46 const run_libc = run_exe(b, optimize, &case, default_target, true);
47 test_step.dependOn(&run_libc.step);
48 }
49 }
50}
51
52fn run_exe(b: *std.Build, optimize: std.builtin.OptimizeMode, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run {
53 const exe_name = b.fmt("test-posix-{s}{s}{s}", .{
54 std.fs.path.stem(case.src_path),
55 if (link_libc) "-libc" else "",
56 if (link_libc and target.result.isGnuLibC()) "-gnu" else if (link_libc and target.result.isMuslLibC()) "-musl" else "",
57 });
58
59 const exe = b.addExecutable(.{
60 .name = exe_name,
61 .root_module = b.createModule(.{
62 .root_source_file = b.path(case.src_path),
63 .link_libc = link_libc,
64 .optimize = optimize,
65 .target = target,
66 }),
67 });
68
69 const run_cmd = b.addRunArtifact(exe);
70
71 return run_cmd;
72}
test/standalone/posix/cwd.zig created+1
...@@ -0,0 +1 @@
1pub fn main() !void {}
test/standalone/posix/getenv.zig created+1
...@@ -0,0 +1 @@
1pub fn main() !void {}
test/standalone/posix/relpaths.zig created+1
...@@ -0,0 +1 @@
1pub fn main() !void {}
test/standalone/posix/sigaction.zig created+1
...@@ -0,0 +1 @@
1pub fn main() !void {}