test_helpers.h revision 4a53e3c2b83c476a93148eaee0272649beb221ca
664e667e221a15fa5f456e73948c67710f43f1b4minfrin/* Copyright (c) 2008 The NetBSD Foundation, Inc.
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * All rights reserved.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd *
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Redistribution and use in source and binary forms, with or without
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * modification, are permitted provided that the following conditions
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * are met:
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * 1. Redistributions of source code must retain the above copyright
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * notice, this list of conditions and the following disclaimer.
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * 2. Redistributions in binary form must reproduce the above copyright
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * notice, this list of conditions and the following disclaimer in the
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * documentation and/or other materials provided with the distribution.
664e667e221a15fa5f456e73948c67710f43f1b4minfrin *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
2e545ce2450a9953665f701bb05350f0d3f26275nd * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
664e667e221a15fa5f456e73948c67710f43f1b4minfrin * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
664e667e221a15fa5f456e73948c67710f43f1b4minfrin
664e667e221a15fa5f456e73948c67710f43f1b4minfrin#if defined(ATF_C_DETAIL_TEST_HELPERS_H)
664e667e221a15fa5f456e73948c67710f43f1b4minfrin# error "Cannot include test_helpers.h more than once."
664e667e221a15fa5f456e73948c67710f43f1b4minfrin#else
664e667e221a15fa5f456e73948c67710f43f1b4minfrin# define ATF_C_DETAIL_TEST_HELPERS_H
403c4b12252c59673100b19905e3c1fcb53ac773minfrin#endif
403c4b12252c59673100b19905e3c1fcb53ac773minfrin
403c4b12252c59673100b19905e3c1fcb53ac773minfrin#include <stdbool.h>
403c4b12252c59673100b19905e3c1fcb53ac773minfrin
403c4b12252c59673100b19905e3c1fcb53ac773minfrin#include <atf-c.h>
403c4b12252c59673100b19905e3c1fcb53ac773minfrin
403c4b12252c59673100b19905e3c1fcb53ac773minfrin#include <atf-c/error_fwd.h>
c4d3a12e7bb879798ec5f795c9cd30427089ddffminfrin#include <atf-c/tc.h>
403c4b12252c59673100b19905e3c1fcb53ac773minfrin
664e667e221a15fa5f456e73948c67710f43f1b4minfrinstruct atf_dynstr;
403c4b12252c59673100b19905e3c1fcb53ac773minfrinstruct atf_fs_path;
664e667e221a15fa5f456e73948c67710f43f1b4minfrin
664e667e221a15fa5f456e73948c67710f43f1b4minfrin#define CE(stm) ATF_CHECK(!atf_is_error(stm))
664e667e221a15fa5f456e73948c67710f43f1b4minfrin#define RE(stm) ATF_REQUIRE(!atf_is_error(stm))
664e667e221a15fa5f456e73948c67710f43f1b4minfrin
664e667e221a15fa5f456e73948c67710f43f1b4minfrin#define HEADER_TC(name, hdrname) \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin ATF_TC(name); \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin ATF_TC_HEAD(name, tc) \
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh { \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin atf_tc_set_md_var(tc, "descr", "Tests that the " hdrname " file can " \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin "be included on its own, without any prerequisites"); \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin } \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin ATF_TC_BODY(name, tc) \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin { \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin header_check(hdrname); \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin }
664e667e221a15fa5f456e73948c67710f43f1b4minfrin
664e667e221a15fa5f456e73948c67710f43f1b4minfrin#define BUILD_TC(name, sfile, descr, failmsg) \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin ATF_TC(name); \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin ATF_TC_HEAD(name, tc) \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin { \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin atf_tc_set_md_var(tc, "descr", descr); \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin } \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin ATF_TC_BODY(name, tc) \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin { \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin if (!build_check_c_o_srcdir(tc, sfile)) \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin atf_tc_fail("%s", failmsg); \
664e667e221a15fa5f456e73948c67710f43f1b4minfrin }
664e667e221a15fa5f456e73948c67710f43f1b4minfrin
664e667e221a15fa5f456e73948c67710f43f1b4minfrinbool build_check_c_o(const char *);
664e667e221a15fa5f456e73948c67710f43f1b4minfrinbool build_check_c_o_srcdir(const atf_tc_t *, const char *);
664e667e221a15fa5f456e73948c67710f43f1b4minfrinvoid header_check(const char *);
664e667e221a15fa5f456e73948c67710f43f1b4minfrinvoid get_process_helpers_path(const atf_tc_t *, const bool,
403c4b12252c59673100b19905e3c1fcb53ac773minfrin struct atf_fs_path *);
403c4b12252c59673100b19905e3c1fcb53ac773minfrinbool read_line(int, struct atf_dynstr *);
403c4b12252c59673100b19905e3c1fcb53ac773minfrinvoid run_h_tc(atf_tc_t *, const char *, const char *, const char *);
403c4b12252c59673100b19905e3c1fcb53ac773minfrin