4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews/* Copyright (c) 2008 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * are met:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/process.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sys/types.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sys/time.h>
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt#include <sys/resource.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sys/wait.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <errno.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <fcntl.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <signal.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <stdio.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <stdlib.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <string.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <unistd.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <atf-c.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include "atf-c/defs.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/sanity.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/test_helpers.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t atf_process_status_init(atf_process_status_t *, int);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Auxiliary functions for testing of 'atf_process_fork'.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/*
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Testing of atf_process_fork is quite messy. We want to be able to test
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * all the possible combinations of stdout and stderr behavior to ensure
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * that the streams are manipulated correctly.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * To do this, the do_fork function is a wrapper for atf_process_fork that
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * issues stream-specific hooks before fork, while the child is running and
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * after the child terminates. We then provide test cases that just call
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * do_fork with different hooks.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * The hooks are described by base_stream, and we then have one *_stream
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * type for ever possible stream behavior.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntenum out_type { stdout_type, stderr_type };
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct base_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt void (*init)(void *);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt void (*process)(void *, atf_process_child_t *);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt void (*fini)(void *);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* m_sb is initialized by subclasses that need it, but all consumers
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * must use m_sb_ptr, which may or may not point to m_sb. This allows
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * us to test the interface with a NULL value, which triggers a
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * default behavior. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t *m_sb_ptr;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt enum out_type m_type;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define BASE_STREAM(ihook, phook, fhook, type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .init = ihook, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt .process = phook, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt .fini = fhook, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt .m_type = type }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcheck_file(const enum out_type type)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("stdout: msg", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(!atf_utils_grep_file("stderr: msg", "stdout"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("stderr: msg", "stderr"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(!atf_utils_grep_file("stdout: msg", "stderr"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct capture_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct base_stream m_base;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt char *m_msg;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define CAPTURE_STREAM(type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .m_base = BASE_STREAM(capture_stream_init, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt capture_stream_process, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt capture_stream_fini, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt type) }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcapture_stream_init(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct capture_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_base.m_sb_ptr = &s->m_base.m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_capture(&s->m_base.m_sb));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt s->m_msg = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcapture_stream_process(void *v, atf_process_child_t *c)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct capture_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (s->m_base.m_type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt s->m_msg = atf_utils_readline(atf_process_child_stdout(c));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt s->m_msg = atf_utils_readline(atf_process_child_stderr(c));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcapture_stream_fini(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct capture_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (s->m_base.m_type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_string("stdout: msg", s->m_msg));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(!atf_utils_grep_string("stderr: msg", s->m_msg));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(!atf_utils_grep_string("stdout: msg", s->m_msg));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_string("stderr: msg", s->m_msg));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt free(s->m_msg);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&s->m_base.m_sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct connect_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct base_stream m_base;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int m_fd;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define CONNECT_STREAM(type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .m_base = BASE_STREAM(connect_stream_init, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt NULL, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt connect_stream_fini, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt type) }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntconnect_stream_init(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct connect_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int src_fd;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (s->m_base.m_type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt src_fd = STDOUT_FILENO;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd = open("stdout", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt src_fd = STDERR_FILENO;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd = open("stderr", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt src_fd = -1;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(s->m_fd != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_base.m_sb_ptr = &s->m_base.m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_connect(&s->m_base.m_sb, src_fd, s->m_fd));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntconnect_stream_fini(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct connect_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(close(s->m_fd) != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&s->m_base.m_sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_file(s->m_base.m_type);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct inherit_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct base_stream m_base;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int m_fd;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int m_old_fd;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define INHERIT_STREAM(type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .m_base = BASE_STREAM(inherit_stream_init, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt NULL, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt inherit_stream_fini, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt type) }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntinherit_stream_init(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct inherit_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *name;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_base.m_sb_ptr = &s->m_base.m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_inherit(&s->m_base.m_sb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (s->m_base.m_type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd = STDOUT_FILENO;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt name = "stdout";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd = STDERR_FILENO;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt name = "stderr";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt name = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_old_fd = dup(s->m_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(s->m_old_fd != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(close(s->m_fd) != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE_EQ(open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntinherit_stream_fini(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct inherit_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(dup2(s->m_old_fd, s->m_fd) != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(close(s->m_old_fd) != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&s->m_base.m_sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_file(s->m_base.m_type);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define default_stream inherit_stream
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define DEFAULT_STREAM(type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .m_base = BASE_STREAM(default_stream_init, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt NULL, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default_stream_fini, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt type) }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntdefault_stream_init(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct inherit_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt inherit_stream_init(v);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_base.m_sb_ptr = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntdefault_stream_fini(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt inherit_stream_fini(v);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct redirect_fd_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct base_stream m_base;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int m_fd;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define REDIRECT_FD_STREAM(type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .m_base = BASE_STREAM(redirect_fd_stream_init, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt NULL, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt redirect_fd_stream_fini, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt type) }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntredirect_fd_stream_init(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct redirect_fd_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (s->m_base.m_type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd = open("stdout", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_fd = open("stderr", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(s->m_fd != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_base.m_sb_ptr = &s->m_base.m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_redirect_fd(&s->m_base.m_sb, s->m_fd));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntredirect_fd_stream_fini(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct redirect_fd_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(close(s->m_fd) != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&s->m_base.m_sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_file(s->m_base.m_type);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct redirect_path_stream {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct base_stream m_base;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t m_path;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define REDIRECT_PATH_STREAM(type) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { .m_base = BASE_STREAM(redirect_path_stream_init, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt NULL, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt redirect_path_stream_fini, \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt type) }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntredirect_path_stream_init(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct redirect_path_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt switch (s->m_base.m_type) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stdout_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&s->m_path, "stdout"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt case stderr_type:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&s->m_path, "stderr"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt break;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt default:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt s->m_base.m_sb_ptr = &s->m_base.m_sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_redirect_path(&s->m_base.m_sb, &s->m_path));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntredirect_path_stream_fini(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct redirect_path_stream *s = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&s->m_base.m_sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&s->m_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_file(s->m_base.m_type);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_print(void *) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstruct child_print_data {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *m_msg;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt};
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_print(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct child_print_data *cpd = v;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stdout, "stdout: %s\n", cpd->m_msg);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "stderr: %s\n", cpd->m_msg);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntdo_fork(const struct base_stream *outfs, void *out,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const struct base_stream *errfs, void *err)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct child_print_data cpd = { "msg" };
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt outfs->init(out);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt errfs->init(err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_fork(&child, child_print, outfs->m_sb_ptr,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt errfs->m_sb_ptr, &cpd));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (outfs->process != NULL)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt outfs->process(out, &child);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (errfs->process != NULL)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt errfs->process(err, &child);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_child_wait(&child, &status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt outfs->fini(out);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt errfs->fini(err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Test cases for the "stream" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(stream_init_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(stream_init_capture, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "atf_process_stream_init_capture function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(stream_init_capture, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_capture(&sb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_stream_type(&sb),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_type_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(stream_init_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(stream_init_connect, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "atf_process_stream_init_connect function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(stream_init_connect, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_connect(&sb, 1, 2));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_stream_type(&sb),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_type_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(stream_init_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(stream_init_inherit, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "atf_process_stream_init_inherit function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(stream_init_inherit, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_inherit(&sb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_stream_type(&sb),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_type_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(stream_init_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(stream_init_redirect_fd, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "atf_process_stream_init_redirect_fd function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(stream_init_redirect_fd, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_redirect_fd(&sb, 1));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_stream_type(&sb),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_type_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(stream_init_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(stream_init_redirect_path, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "atf_process_stream_init_redirect_path function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(stream_init_redirect_path, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t sb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t path;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&path, "foo"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_redirect_path(&sb, &path));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_stream_type(&sb),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_type_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&sb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Test cases for the "status" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_exit_success(void) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_exit_failure(void) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_sigkill(void) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_sigquit(void) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_sigterm(void) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_exit_success(void)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_exit_failure(void)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(EXIT_FAILURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_sigkill(void)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt kill(getpid(), SIGKILL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_sigquit(void)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt kill(getpid(), SIGQUIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_sigterm(void)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt kill(getpid(), SIGTERM);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntint
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntfork_and_wait_child(void (*child_func)(void))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pid_t pid;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pid = fork();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(pid != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (pid == 0) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt status = 0; /* Silence compiler warnings */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt child_func();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } else {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(waitpid(pid, &status, 0) != 0);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(status_exited);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(status_exited, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the status type for processes "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "that exit cleanly");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(status_exited, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const int rawstatus = fork_and_wait_child(child_exit_success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t s;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_status_init(&s, rawstatus));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&s), EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_signaled(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&s);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const int rawstatus = fork_and_wait_child(child_exit_failure);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t s;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_status_init(&s, rawstatus));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&s), EXIT_FAILURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_signaled(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&s);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(status_signaled);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(status_signaled, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the status type for processes "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "that end due to a signal");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(status_signaled, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const int rawstatus = fork_and_wait_child(child_sigkill);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t s;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_status_init(&s, rawstatus));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_exited(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_signaled(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_termsig(&s), SIGKILL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_coredump(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&s);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const int rawstatus = fork_and_wait_child(child_sigterm);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t s;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_status_init(&s, rawstatus));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_exited(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_signaled(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_termsig(&s), SIGTERM);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_coredump(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&s);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(status_coredump);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(status_coredump, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the status type for processes "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "that crash");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(status_coredump, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct rlimit rl;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt rl.rlim_cur = RLIM_INFINITY;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt rl.rlim_max = RLIM_INFINITY;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (setrlimit(RLIMIT_CORE, &rl) == -1)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_skip("Cannot unlimit the core file size; check limits "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "manually");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const int rawstatus = fork_and_wait_child(child_sigquit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t s;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_status_init(&s, rawstatus));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_process_status_exited(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_signaled(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_termsig(&s), SIGQUIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_coredump(&s));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&s);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Test cases for the "child" type.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic void child_report_pid(void *) ATF_DEFS_ATTRIBUTE_NORETURN;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntchild_report_pid(void *v ATF_DEFS_ATTRIBUTE_UNUSED)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const pid_t pid = getpid();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (write(STDOUT_FILENO, &pid, sizeof(pid)) != sizeof(pid))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "Reporting %d to parent\n", (int)getpid());
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(child_pid);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(child_pid, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the correctness of the pid "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "stored in the child type");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(child_pid, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t outsb, errsb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt pid_t pid;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_capture(&outsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_inherit(&errsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_fork(&child, child_report_pid, &outsb, &errsb, NULL));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(read(atf_process_child_stdout(&child), &pid, sizeof(pid)),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sizeof(pid));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Expected PID: %d\n", (int)atf_process_child_pid(&child));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Actual PID: %d\n", (int)pid);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_child_pid(&child), pid);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_child_wait(&child, &status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&outsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&errsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntchild_loop(void *v ATF_DEFS_ATTRIBUTE_UNUSED)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for (;;)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sleep(1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntnop_signal(int sig ATF_DEFS_ATTRIBUTE_UNUSED)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntchild_spawn_loop_and_wait_eintr(void *v ATF_DEFS_ATTRIBUTE_UNUSED)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct sigaction sighup, old_sighup;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define RE_ABORT(expr) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do { \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t _aux_err = expr; \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(_aux_err)) { \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_free(_aux_err); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort(); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } while (0)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t outsb, errsb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE_ABORT(atf_process_stream_init_capture(&outsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE_ABORT(atf_process_stream_init_inherit(&errsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE_ABORT(atf_process_fork(&child, child_loop, &outsb, &errsb, NULL));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&outsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&errsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sighup.sa_handler = nop_signal;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sigemptyset(&sighup.sa_mask);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sighup.sa_flags = 0;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (sigaction(SIGHUP, &sighup, &old_sighup) == -1)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("waiting\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fflush(stdout);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "Child entering wait(2)\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err = atf_process_child_wait(&child, &status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "Child's wait(2) terminated\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (!atf_is_error(err)) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "wait completed successfully (not interrupted)\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (!atf_error_is(err, "libc")) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "wait did not raise libc_error\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_libc_error_code(err) != EINTR) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "libc_error is not EINTR\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt abort();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_free(err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sigaction(SIGHUP, &old_sighup, NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(stderr, "Child is killing subchild\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt kill(atf_process_child_pid(&child), SIGTERM);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE_ABORT(atf_process_child_wait(&child, &status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#undef RE_ABORT
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(child_wait_eintr);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(child_wait_eintr, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests the interruption of the wait "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "method by an external signal, and the return of "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "an EINTR error");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "timeout", "30");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(child_wait_eintr, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t outsb, errsb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_capture(&outsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_inherit(&errsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_fork(&child, child_spawn_loop_and_wait_eintr,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &outsb, &errsb, NULL));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&outsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&errsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* Wait until the child process performs the wait call. This is
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * racy, because the message we get from it is sent *before*
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * doing the real system call... but I can't figure any other way
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * to do this. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt char buf[16];
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Waiting for child to issue wait(2)\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(read(atf_process_child_stdout(&child), buf,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sizeof(buf)) > 0);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt sleep(1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Interrupting child's wait(2) call\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt kill(atf_process_child_pid(&child), SIGHUP);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Waiting for child's completion\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_child_wait(&child, &status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(atf_process_status_exited(&status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE_EQ(atf_process_status_exitstatus(&status), EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Tests cases for the free functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntdo_exec(const atf_tc_t *tc, const char *helper_name, atf_process_status_t *s,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt void (*prehook)(void))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t process_helpers;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *argv[3];
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt get_process_helpers_path(tc, true, &process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[0] = atf_fs_path_cstring(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[1] = helper_name;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[2] = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Executing %s %s\n", argv[0], argv[1]);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt RE(atf_process_exec_array(s, &process_helpers, argv, NULL, NULL, prehook));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcheck_line(int fd, const char *exp)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt char *line = atf_utils_readline(fd);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(line != NULL);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK_STREQ_MSG(exp, line, "read: '%s', expected: '%s'", line, exp);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt free(line);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_failure);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_failure, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests execing a command");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_failure, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt do_exec(tc, "exit-failure", &status, NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&status), EXIT_FAILURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_list, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests execing a command");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_list, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t process_helpers;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_t argv;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_list_init(&argv));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt get_process_helpers_path(tc, true, &process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_append(&argv, strdup(atf_fs_path_cstring(&process_helpers)), true);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_append(&argv, strdup("echo"), true);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_append(&argv, strdup("test-message"), true);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t outpath;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t outsb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&outpath, "stdout"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_redirect_path(&outsb, &outpath));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_exec_list(&status, &process_helpers, &argv, &outsb,
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt NULL, NULL));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&outsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&outpath);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_fini(&argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&status), EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int fd = open("stdout", O_RDONLY);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(fd != -1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_line(fd, "test-message");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt close(fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntstatic void
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Huntexit_early(void)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt exit(80);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt}
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan HuntATF_TC(exec_prehook);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan HuntATF_TC_HEAD(exec_prehook, tc)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_tc_set_md_var(tc, "descr", "Tests execing a command with a prehook");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt}
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan HuntATF_TC_BODY(exec_prehook, tc)
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt{
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_process_status_t status;
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt do_exec(tc, "exit-success", &status, exit_early);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_process_status_exited(&status));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&status), 80);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt atf_process_status_fini(&status);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt}
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_success, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests execing a command");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_success, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt do_exec(tc, "exit-success", &status, NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&status), EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic const int exit_v_null = 1;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic const int exit_v_notnull = 2;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntchild_cookie(void *v)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (v == NULL)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(exit_v_null);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt exit(exit_v_notnull);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt UNREACHABLE;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(fork_cookie);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(fork_cookie, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests forking a child, with "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "a null and non-null data cookie");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(fork_cookie, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_t outsb, errsb;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_inherit(&outsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_stream_init_inherit(&errsb));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_fork(&child, child_cookie, &outsb, &errsb, NULL));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_child_wait(&child, &status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&status), exit_v_null);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_child_t child;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_t status;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int dummy_int;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_fork(&child, child_cookie, &outsb, &errsb, &dummy_int));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_process_child_wait(&child, &status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_process_status_exited(&status));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK_EQ(atf_process_status_exitstatus(&status), exit_v_notnull);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_status_fini(&status);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&errsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_process_stream_fini(&outsb);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define TC_FORK_STREAMS(outlc, outuc, errlc, erruc) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TC(fork_out_ ## outlc ## _err_ ## errlc); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TC_HEAD(fork_out_ ## outlc ## _err_ ## errlc, tc) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Tests forking a child, with " \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "stdout " #outlc " and stderr " #errlc); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TC_BODY(fork_out_ ## outlc ## _err_ ## errlc, tc) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt { \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct outlc ## _stream out = outuc ## _STREAM(stdout_type); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt struct errlc ## _stream err = erruc ## _STREAM(stderr_type); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_fork(&out.m_base, &out, &err.m_base, &err); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(capture, CAPTURE, capture, CAPTURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(capture, CAPTURE, connect, CONNECT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(capture, CAPTURE, default, DEFAULT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(capture, CAPTURE, inherit, INHERIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(capture, CAPTURE, redirect_fd, REDIRECT_FD);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(capture, CAPTURE, redirect_path, REDIRECT_PATH);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(connect, CONNECT, capture, CAPTURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(connect, CONNECT, connect, CONNECT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(connect, CONNECT, default, DEFAULT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(connect, CONNECT, inherit, INHERIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(connect, CONNECT, redirect_fd, REDIRECT_FD);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(connect, CONNECT, redirect_path, REDIRECT_PATH);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(default, DEFAULT, capture, CAPTURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(default, DEFAULT, connect, CONNECT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(default, DEFAULT, default, DEFAULT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(default, DEFAULT, inherit, INHERIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(default, DEFAULT, redirect_fd, REDIRECT_FD);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(default, DEFAULT, redirect_path, REDIRECT_PATH);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(inherit, INHERIT, capture, CAPTURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(inherit, INHERIT, connect, CONNECT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(inherit, INHERIT, default, DEFAULT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(inherit, INHERIT, inherit, INHERIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(inherit, INHERIT, redirect_fd, REDIRECT_FD);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(inherit, INHERIT, redirect_path, REDIRECT_PATH);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_fd, REDIRECT_FD, capture, CAPTURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_fd, REDIRECT_FD, connect, CONNECT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_fd, REDIRECT_FD, default, DEFAULT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_fd, REDIRECT_FD, inherit, INHERIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_fd, REDIRECT_FD, redirect_fd, REDIRECT_FD);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_fd, REDIRECT_FD, redirect_path, REDIRECT_PATH);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_path, REDIRECT_PATH, capture, CAPTURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_path, REDIRECT_PATH, connect, CONNECT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_path, REDIRECT_PATH, default, DEFAULT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_path, REDIRECT_PATH, inherit, INHERIT);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_path, REDIRECT_PATH, redirect_fd, REDIRECT_FD);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntTC_FORK_STREAMS(redirect_path, REDIRECT_PATH, redirect_path, REDIRECT_PATH);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#undef TC_FORK_STREAMS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Main.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TP_ADD_TCS(tp)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* Add the tests for the "stream" type. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, stream_init_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, stream_init_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, stream_init_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, stream_init_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, stream_init_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* Add the tests for the "status" type. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, status_exited);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, status_signaled);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, status_coredump);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* Add the tests for the "child" type. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, child_pid);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, child_wait_eintr);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* Add the tests for the free functions. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_failure);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_list);
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_TP_ADD_TC(tp, exec_prehook);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_cookie);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_capture_err_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_capture_err_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_capture_err_default);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_capture_err_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_capture_err_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_capture_err_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_connect_err_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_connect_err_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_connect_err_default);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_connect_err_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_connect_err_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_connect_err_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_default_err_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_default_err_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_default_err_default);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_default_err_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_default_err_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_default_err_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_inherit_err_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_inherit_err_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_inherit_err_default);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_inherit_err_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_inherit_err_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_inherit_err_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_fd_err_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_fd_err_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_fd_err_default);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_fd_err_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_fd_err_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_fd_err_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_path_err_capture);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_path_err_connect);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_path_err_default);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_path_err_inherit);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_path_err_redirect_fd);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, fork_out_redirect_path_err_redirect_path);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return atf_no_error();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}