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/check.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
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
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/fs.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/map.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/process.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/test_helpers.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Auxiliary functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntdo_exec(const atf_tc_t *tc, const char *helper_name, atf_check_result_t *r)
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, false, &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 RE(atf_check_exec_array(argv, r));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntdo_exec_with_arg(const atf_tc_t *tc, const char *helper_name, const char *arg,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t *r)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t process_helpers;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *argv[4];
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt get_process_helpers_path(tc, false, &process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[0] = atf_fs_path_cstring(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[1] = helper_name;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[2] = arg;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[3] = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt printf("Executing %s %s %s\n", argv[0], argv[1], argv[2]);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_exec_array(argv, r));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
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 Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Helper test cases for the free functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(h_build_c_o_ok);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(h_build_c_o_ok, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Helper test case for build_c_o");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(h_build_c_o_ok, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt FILE *sfile;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool success;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE((sfile = fopen("test.c", "w")) != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "#include <stdio.h>\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fclose(sfile);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_build_c_o("test.c", "test.o", NULL, &success));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(h_build_c_o_fail);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(h_build_c_o_fail, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Helper test case for build_c_o");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(h_build_c_o_fail, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt FILE *sfile;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool success;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE((sfile = fopen("test.c", "w")) != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "void foo(void) { int a = UNDEFINED_SYMBOL; }\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fclose(sfile);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_build_c_o("test.c", "test.o", NULL, &success));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(!success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(h_build_cpp_ok);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(h_build_cpp_ok, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Helper test case for build_cpp");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(h_build_cpp_ok, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt FILE *sfile;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool success;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t test_p;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&test_p, "test.p"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE((sfile = fopen("test.c", "w")) != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "#define A foo\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "#define B bar\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "A B\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fclose(sfile);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_build_cpp("test.c", atf_fs_path_cstring(&test_p), NULL,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &success));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&test_p);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(h_build_cpp_fail);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(h_build_cpp_fail, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Helper test case for build_cpp");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(h_build_cpp_fail, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt FILE *sfile;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool success;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE((sfile = fopen("test.c", "w")) != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "#include \"./non-existent.h\"\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fclose(sfile);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_build_cpp("test.c", "test.p", NULL, &success));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(!success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(h_build_cxx_o_ok);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(h_build_cxx_o_ok, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Helper test case for build_cxx_o");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(h_build_cxx_o_ok, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt FILE *sfile;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool success;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE((sfile = fopen("test.cpp", "w")) != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "#include <iostream>\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fclose(sfile);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_build_cxx_o("test.cpp", "test.o", NULL, &success));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(h_build_cxx_o_fail);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(h_build_cxx_o_fail, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Helper test case for build_cxx_o");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(h_build_cxx_o_fail, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt FILE *sfile;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool success;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE((sfile = fopen("test.cpp", "w")) != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fprintf(sfile, "void foo(void) { int a = UNDEFINED_SYMBOL; }\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt fclose(sfile);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_build_cxx_o("test.cpp", "test.o", NULL, &success));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_REQUIRE(!success);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Test cases for the free functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntinit_and_run_h_tc(atf_tc_t *tc, const atf_tc_pack_t *tcpack,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *outname, const char *errname)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *const config[] = { NULL };
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_tc_init_pack(tc, tcpack, config));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt run_h_tc(tc, outname, errname, "result");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_fini(tc);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(build_c_o);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(build_c_o, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks the atf_check_build_c_o "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(build_c_o, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt init_and_run_h_tc(&ATF_TC_NAME(h_build_c_o_ok),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &ATF_TC_PACK_NAME(h_build_c_o_ok), "stdout", "stderr");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-c test.c", "stdout"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt init_and_run_h_tc(&ATF_TC_NAME(h_build_c_o_fail),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &ATF_TC_PACK_NAME(h_build_c_o_fail), "stdout", "stderr");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-c test.c", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("test.c", "stderr"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("UNDEFINED_SYMBOL", "stderr"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(build_cpp);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(build_cpp, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks the atf_check_build_cpp "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(build_cpp, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt init_and_run_h_tc(&ATF_TC_NAME(h_build_cpp_ok),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &ATF_TC_PACK_NAME(h_build_cpp_ok), "stdout", "stderr");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-o.*test.p", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("test.c", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("foo bar", "test.p"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt init_and_run_h_tc(&ATF_TC_NAME(h_build_cpp_fail),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &ATF_TC_PACK_NAME(h_build_cpp_fail), "stdout", "stderr");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-o test.p", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("test.c", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("test.c", "stderr"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("non-existent.h", "stderr"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(build_cxx_o);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(build_cxx_o, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks the atf_check_build_cxx_o "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "function");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(build_cxx_o, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt init_and_run_h_tc(&ATF_TC_NAME(h_build_cxx_o_ok),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &ATF_TC_PACK_NAME(h_build_cxx_o_ok), "stdout", "stderr");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-c test.cpp", "stdout"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt init_and_run_h_tc(&ATF_TC_NAME(h_build_cxx_o_fail),
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt &ATF_TC_PACK_NAME(h_build_cxx_o_fail), "stdout", "stderr");
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-o test.o", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("-c test.cpp", "stdout"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("test.cpp", "stderr"));
a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt ATF_CHECK(atf_utils_grep_file("UNDEFINED_SYMBOL", "stderr"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_array);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_array, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "works properly");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_array, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t process_helpers;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt get_process_helpers_path(tc, false, &process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *argv[4];
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[0] = atf_fs_path_cstring(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[1] = "echo";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[2] = "test-message";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[3] = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_exec_array(argv, &result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exited(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *path = atf_check_result_stdout(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int fd = open(path, 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_check_result_fini(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_cleanup);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_cleanup, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "properly cleans up the temporary files it creates");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_cleanup, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t out, err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt bool exists;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_exec(tc, "exit-success", &result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&out, "%s", atf_check_result_stdout(&result)));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_path_init_fmt(&err, "%s", atf_check_result_stderr(&result)));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_exists(&out, &exists)); ATF_CHECK(exists);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_exists(&err, &exists)); ATF_CHECK(exists);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_exists(&out, &exists)); ATF_CHECK(!exists);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_fs_exists(&err, &exists)); ATF_CHECK(!exists);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&out);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_exitstatus);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_exitstatus, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "properly captures the exit status of the executed "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "command");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_exitstatus, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_exec(tc, "exit-success", &result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exited(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_check_result_signaled(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_exec(tc, "exit-failure", &result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exited(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_check_result_signaled(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_FAILURE);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_exec(tc, "exit-signal", &result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(!atf_check_result_exited(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_signaled(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_termsig(&result) == SIGKILL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_stdout_stderr);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_stdout_stderr, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "properly captures the stdout and stderr streams "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "of the child process");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_stdout_stderr, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result1, result2;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *out1, *out2;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *err1, *err2;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_exec_with_arg(tc, "stdout-stderr", "result1", &result1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exited(&result1));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exitcode(&result1) == EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do_exec_with_arg(tc, "stdout-stderr", "result2", &result2);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exited(&result2));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exitcode(&result2) == EXIT_SUCCESS);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt out1 = atf_check_result_stdout(&result1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt out2 = atf_check_result_stdout(&result2);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err1 = atf_check_result_stderr(&result1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err2 = atf_check_result_stderr(&result2);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(out1, "check.XXXXXX") == NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(out2, "check.XXXXXX") == NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(err1, "check.XXXXXX") == NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(err2, "check.XXXXXX") == NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(out1, "/check") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(out2, "/check") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(err1, "/check") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(err2, "/check") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(out1, "/stdout") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(out2, "/stdout") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(err1, "/stderr") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strstr(err2, "/stderr") != NULL);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strcmp(out1, out2) != 0);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(strcmp(err1, err2) != 0);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define CHECK_LINES(path, outname, resname) \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt do { \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt int fd = open(path, O_RDONLY); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(fd != -1); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_line(fd, "Line 1 to " outname " for " resname); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_line(fd, "Line 2 to " outname " for " resname); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt close(fd); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt } while (false)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK_LINES(out1, "stdout", "result1");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK_LINES(out2, "stdout", "result2");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK_LINES(err1, "stderr", "result1");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK_LINES(err2, "stderr", "result2");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#undef CHECK_LINES
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result2);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result1);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_umask);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_umask, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "correctly reports an error if the umask is too "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "restrictive to create temporary files");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_umask, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_t process_helpers;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *argv[3];
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt get_process_helpers_path(tc, false, &process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[0] = atf_fs_path_cstring(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[1] = "exit-success";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[2] = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt umask(0222);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err = atf_check_exec_array(argv, &result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_is_error(err));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_error_is(err, "invalid_umask"));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_free(err);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_fs_path_fini(&process_helpers);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC(exec_unknown);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_HEAD(exec_unknown, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_tc_set_md_var(tc, "descr", "Checks that running a non-existing "
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "binary is handled correctly");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TC_BODY(exec_unknown, tc)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *argv[2];
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews argv[0] = "/foo/bar/non-existent";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt argv[1] = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_t result;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RE(atf_check_exec_array(argv, &result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exited(&result));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_CHECK(atf_check_result_exitcode(&result) == 127);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_check_result_fini(&result);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Main.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TP_ADD_TCS(tp)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt /* Add the test cases for the free functions. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, build_c_o);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, build_cpp);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, build_cxx_o);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_array);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_cleanup);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_exitstatus);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_stdout_stderr);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_umask);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_TP_ADD_TC(tp, exec_unknown);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return atf_no_error();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}