1 /* $NetBSD: test_helpers.h,v 1.3 2014/12/10 04:38:03 christos Exp $ */ 2 3 /* 4 * Automated Testing Framework (atf) 5 * 6 * Copyright (c) 2008 The NetBSD Foundation, Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #if defined(TESTS_ATF_ATF_C_TEST_HELPERS_H) 33 # error "Cannot include test_helpers.h more than once." 34 #else 35 # define TESTS_ATF_ATF_C_TEST_HELPERS_H 36 #endif 37 38 #include <stdbool.h> 39 40 #include "atf-c/error_fwd.h" 41 42 struct atf_dynstr; 43 struct atf_fs_path; 44 45 #define CE(stm) ATF_CHECK(!atf_is_error(stm)) 46 #define RE(stm) ATF_REQUIRE(!atf_is_error(stm)) 47 48 #define HEADER_TC(name, hdrname) \ 49 ATF_TC(name); \ 50 ATF_TC_HEAD(name, tc) \ 51 { \ 52 atf_tc_set_md_var(tc, "descr", "Tests that the " hdrname " file can " \ 53 "be included on its own, without any prerequisites"); \ 54 } \ 55 ATF_TC_BODY(name, tc) \ 56 { \ 57 header_check(hdrname); \ 58 } 59 60 #define BUILD_TC(name, sfile, descr, failmsg) \ 61 ATF_TC(name); \ 62 ATF_TC_HEAD(name, tc) \ 63 { \ 64 atf_tc_set_md_var(tc, "descr", descr); \ 65 } \ 66 ATF_TC_BODY(name, tc) \ 67 { \ 68 build_check_c_o(tc, sfile, failmsg, true); \ 69 } 70 71 #define BUILD_TC_FAIL(name, sfile, descr, failmsg) \ 72 ATF_TC(name); \ 73 ATF_TC_HEAD(name, tc) \ 74 { \ 75 atf_tc_set_md_var(tc, "descr", descr); \ 76 } \ 77 ATF_TC_BODY(name, tc) \ 78 { \ 79 build_check_c_o(tc, sfile, failmsg, false); \ 80 } 81 82 void build_check_c_o(const atf_tc_t *, const char *, const char *, const bool); 83 void header_check(const char *); 84 void get_process_helpers_path(const atf_tc_t *, const bool, 85 struct atf_fs_path *); 86 bool read_line(int, struct atf_dynstr *); 87 void run_h_tc(atf_tc_t *, const char *, const char *, const char *); 88