mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
standalone posix tests: add skeleton
Add build.zig, README and empty test files.
This commit is contained in:
parent
e46ddeeb29
commit
c614d8d008
7 changed files with 87 additions and 0 deletions
|
|
@ -211,6 +211,9 @@
|
||||||
.tsan = .{
|
.tsan = .{
|
||||||
.path = "tsan",
|
.path = "tsan",
|
||||||
},
|
},
|
||||||
|
.posix = .{
|
||||||
|
.path = "posix",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
|
|
||||||
8
test/standalone/posix/README.md
Normal file
8
test/standalone/posix/README.md
Normal file
|
|
@ -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.
|
||||||
72
test/standalone/posix/build.zig
Normal file
72
test/standalone/posix/build.zig
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
1
test/standalone/posix/cwd.zig
Normal file
1
test/standalone/posix/cwd.zig
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub fn main() !void {}
|
||||||
1
test/standalone/posix/getenv.zig
Normal file
1
test/standalone/posix/getenv.zig
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub fn main() !void {}
|
||||||
1
test/standalone/posix/relpaths.zig
Normal file
1
test/standalone/posix/relpaths.zig
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub fn main() !void {}
|
||||||
1
test/standalone/posix/sigaction.zig
Normal file
1
test/standalone/posix/sigaction.zig
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
pub fn main() !void {}
|
||||||
Loading…
Add table
Reference in a new issue