2022-07-02 17:36:39 +01:00
|
|
|
const std = @import("std");
|
2024-03-19 06:59:35 +00:00
|
|
|
const posix = std.posix;
|
2022-07-02 17:36:39 +01:00
|
|
|
|
|
|
|
pub fn build(b: *std.build.Builder) !void {
|
2023-03-08 07:16:16 +00:00
|
|
|
const test_step = b.step("test", "Test it");
|
|
|
|
b.default_step = test_step;
|
|
|
|
|
|
|
|
// TODO signal handling code has no business being in a build script.
|
|
|
|
// this logic needs to move to a file called parent.zig which is
|
|
|
|
// added as an executable.
|
|
|
|
|
|
|
|
//if (!std.os.have_sigpipe_support) {
|
|
|
|
// return;
|
|
|
|
//}
|
2022-07-02 17:36:39 +01:00
|
|
|
|
|
|
|
// This test runs "breakpipe" as a child process and that process
|
|
|
|
// depends on inheriting a SIGPIPE disposition of "default".
|
|
|
|
{
|
2024-03-19 06:59:35 +00:00
|
|
|
const act = posix.Sigaction{
|
|
|
|
.handler = .{ .handler = posix.SIG.DFL },
|
|
|
|
.mask = posix.empty_sigset,
|
2022-07-02 17:36:39 +01:00
|
|
|
.flags = 0,
|
|
|
|
};
|
2024-03-19 06:59:35 +00:00
|
|
|
try posix.sigaction(posix.SIG.PIPE, &act, null);
|
2022-07-02 17:36:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for ([_]bool{ false, true }) |keep_sigpipe| {
|
|
|
|
const options = b.addOptions();
|
|
|
|
options.addOption(bool, "keep_sigpipe", keep_sigpipe);
|
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = "breakpipe",
|
2024-05-04 19:29:17 +01:00
|
|
|
.root_source_file = b.path("breakpipe.zig"),
|
2022-07-02 17:36:39 +01:00
|
|
|
});
|
|
|
|
exe.addOptions("build_options", options);
|
2023-03-03 22:35:07 +00:00
|
|
|
const run = b.addRunArtifact(exe);
|
2022-07-02 17:36:39 +01:00
|
|
|
if (keep_sigpipe) {
|
2024-03-19 06:59:35 +00:00
|
|
|
run.addCheck(.{ .expect_term = .{ .Signal = std.posix.SIG.PIPE } });
|
2022-07-02 17:36:39 +01:00
|
|
|
} else {
|
2023-03-03 22:35:07 +00:00
|
|
|
run.addCheck(.{ .expect_stdout_exact = "BrokenPipe\n" });
|
|
|
|
run.addCheck(.{ .expect_term = .{ .Exited = 123 } });
|
2022-07-02 17:36:39 +01:00
|
|
|
}
|
|
|
|
test_step.dependOn(&run.step);
|
|
|
|
}
|
|
|
|
}
|