From c614d8d0081782116e94f3c8bfbf4ea515e7a3f3 Mon Sep 17 00:00:00 2001 From: Pat Tullmann Date: Wed, 6 Aug 2025 21:50:56 -0700 Subject: [PATCH] standalone posix tests: add skeleton Add build.zig, README and empty test files. --- test/standalone/build.zig.zon | 3 ++ test/standalone/posix/README.md | 8 ++++ test/standalone/posix/build.zig | 72 +++++++++++++++++++++++++++++ test/standalone/posix/cwd.zig | 1 + test/standalone/posix/getenv.zig | 1 + test/standalone/posix/relpaths.zig | 1 + test/standalone/posix/sigaction.zig | 1 + 7 files changed, 87 insertions(+) create mode 100644 test/standalone/posix/README.md create mode 100644 test/standalone/posix/build.zig create mode 100644 test/standalone/posix/cwd.zig create mode 100644 test/standalone/posix/getenv.zig create mode 100644 test/standalone/posix/relpaths.zig create mode 100644 test/standalone/posix/sigaction.zig diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index c57837c8e6..8aaf2054b0 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -211,6 +211,9 @@ .tsan = .{ .path = "tsan", }, + .posix = .{ + .path = "posix", + }, }, .paths = .{ "build.zig", diff --git a/test/standalone/posix/README.md b/test/standalone/posix/README.md new file mode 100644 index 0000000000..488c9c0205 --- /dev/null +++ b/test/standalone/posix/README.md @@ -0,0 +1,8 @@ +## Zig standalone POSIX tests + +This directory is just for std.posix-related test cases that depend on +process-wide state like the current-working directory, signal handlers, +fork, the main thread, environment variables, etc. Most tests (e.g, +around file descriptors, etc) are with the unit tests in +`lib/std/posix/test.zig`. New tests should be with the unit tests, unless +there is a specific reason they cannot. diff --git a/test/standalone/posix/build.zig b/test/standalone/posix/build.zig new file mode 100644 index 0000000000..71446256ac --- /dev/null +++ b/test/standalone/posix/build.zig @@ -0,0 +1,72 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +const Case = struct { + src_path: []const u8, +}; + +const cases = [_]Case{ + .{ + .src_path = "cwd.zig", + }, + .{ + .src_path = "getenv.zig", + }, + .{ + .src_path = "sigaction.zig", + }, + .{ + .src_path = "relpaths.zig", + }, +}; + +pub fn build(b: *std.Build) void { + const test_step = b.step("test", "Run POSIX standalone test cases"); + b.default_step = test_step; + + const optimize = b.standardOptimizeOption(.{}); + + const default_target = b.resolveTargetQuery(.{}); + + // Run each test case built against libc-less, glibc, and musl. + for (cases) |case| { + const run_def = run_exe(b, optimize, &case, default_target, false); + test_step.dependOn(&run_def.step); + + if (default_target.result.os.tag == .linux) { + const gnu_target = b.resolveTargetQuery(.{ .abi = .gnu }); + const musl_target = b.resolveTargetQuery(.{ .abi = .musl }); + + const run_gnu = run_exe(b, optimize, &case, gnu_target, true); + const run_musl = run_exe(b, optimize, &case, musl_target, true); + + test_step.dependOn(&run_gnu.step); + test_step.dependOn(&run_musl.step); + } else { + const run_libc = run_exe(b, optimize, &case, default_target, true); + test_step.dependOn(&run_libc.step); + } + } +} + +fn run_exe(b: *std.Build, optimize: std.builtin.OptimizeMode, case: *const Case, target: std.Build.ResolvedTarget, link_libc: bool) *std.Build.Step.Run { + const exe_name = b.fmt("test-posix-{s}{s}{s}", .{ + std.fs.path.stem(case.src_path), + if (link_libc) "-libc" else "", + if (link_libc and target.result.isGnuLibC()) "-gnu" else if (link_libc and target.result.isMuslLibC()) "-musl" else "", + }); + + const exe = b.addExecutable(.{ + .name = exe_name, + .root_module = b.createModule(.{ + .root_source_file = b.path(case.src_path), + .link_libc = link_libc, + .optimize = optimize, + .target = target, + }), + }); + + const run_cmd = b.addRunArtifact(exe); + + return run_cmd; +} diff --git a/test/standalone/posix/cwd.zig b/test/standalone/posix/cwd.zig new file mode 100644 index 0000000000..bbb7b6ed70 --- /dev/null +++ b/test/standalone/posix/cwd.zig @@ -0,0 +1 @@ +pub fn main() !void {} diff --git a/test/standalone/posix/getenv.zig b/test/standalone/posix/getenv.zig new file mode 100644 index 0000000000..bbb7b6ed70 --- /dev/null +++ b/test/standalone/posix/getenv.zig @@ -0,0 +1 @@ +pub fn main() !void {} diff --git a/test/standalone/posix/relpaths.zig b/test/standalone/posix/relpaths.zig new file mode 100644 index 0000000000..bbb7b6ed70 --- /dev/null +++ b/test/standalone/posix/relpaths.zig @@ -0,0 +1 @@ +pub fn main() !void {} diff --git a/test/standalone/posix/sigaction.zig b/test/standalone/posix/sigaction.zig new file mode 100644 index 0000000000..bbb7b6ed70 --- /dev/null +++ b/test/standalone/posix/sigaction.zig @@ -0,0 +1 @@ +pub fn main() !void {}