test_helpers.h revision 260029
1178825Sdfr/* 2233294Sstas * Automated Testing Framework (atf) 3233294Sstas * 4233294Sstas * Copyright (c) 2008 The NetBSD Foundation, Inc. 5178825Sdfr * All rights reserved. 6233294Sstas * 7233294Sstas * Redistribution and use in source and binary forms, with or without 8233294Sstas * modification, are permitted provided that the following conditions 9178825Sdfr * are met: 10233294Sstas * 1. Redistributions of source code must retain the above copyright 11233294Sstas * notice, this list of conditions and the following disclaimer. 12178825Sdfr * 2. Redistributions in binary form must reproduce the above copyright 13233294Sstas * notice, this list of conditions and the following disclaimer in the 14233294Sstas * documentation and/or other materials provided with the distribution. 15233294Sstas * 16178825Sdfr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17233294Sstas * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18233294Sstas * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19233294Sstas * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20178825Sdfr * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21233294Sstas * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23233294Sstas * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24233294Sstas * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25233294Sstas * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26233294Sstas * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27233294Sstas * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28233294Sstas */ 29233294Sstas 30233294Sstas#if defined(TESTS_ATF_ATF_C_TEST_HELPERS_H) 31233294Sstas# error "Cannot include test_helpers.h more than once." 32178825Sdfr#else 33178825Sdfr# define TESTS_ATF_ATF_C_TEST_HELPERS_H 34233294Sstas#endif 35178825Sdfr 36178825Sdfr#include <stdbool.h> 37178825Sdfr 38178825Sdfr#include "atf-c/error_fwd.h" 39178825Sdfr 40178825Sdfrstruct atf_dynstr; 41178825Sdfrstruct atf_fs_path; 42178825Sdfr 43178825Sdfr#define CE(stm) ATF_CHECK(!atf_is_error(stm)) 44178825Sdfr#define RE(stm) ATF_REQUIRE(!atf_is_error(stm)) 45178825Sdfr 46178825Sdfr#define HEADER_TC(name, hdrname) \ 47178825Sdfr ATF_TC(name); \ 48178825Sdfr ATF_TC_HEAD(name, tc) \ 49178825Sdfr { \ 50178825Sdfr atf_tc_set_md_var(tc, "descr", "Tests that the " hdrname " file can " \ 51178825Sdfr "be included on its own, without any prerequisites"); \ 52178825Sdfr } \ 53178825Sdfr ATF_TC_BODY(name, tc) \ 54178825Sdfr { \ 55178825Sdfr header_check(hdrname); \ 56178825Sdfr } 57178825Sdfr 58178825Sdfr#define BUILD_TC(name, sfile, descr, failmsg) \ 59178825Sdfr ATF_TC(name); \ 60178825Sdfr ATF_TC_HEAD(name, tc) \ 61178825Sdfr { \ 62178825Sdfr atf_tc_set_md_var(tc, "descr", descr); \ 63178825Sdfr } \ 64178825Sdfr ATF_TC_BODY(name, tc) \ 65178825Sdfr { \ 66178825Sdfr build_check_c_o(tc, sfile, failmsg, true); \ 67178825Sdfr } 68178825Sdfr 69178825Sdfr#define BUILD_TC_FAIL(name, sfile, descr, failmsg) \ 70178825Sdfr ATF_TC(name); \ 71178825Sdfr ATF_TC_HEAD(name, tc) \ 72178825Sdfr { \ 73178825Sdfr atf_tc_set_md_var(tc, "descr", descr); \ 74178825Sdfr } \ 75178825Sdfr ATF_TC_BODY(name, tc) \ 76178825Sdfr { \ 77233294Sstas build_check_c_o(tc, sfile, failmsg, false); \ 78178825Sdfr } 79233294Sstas 80233294Sstasvoid build_check_c_o(const atf_tc_t *, const char *, const char *, const bool); 81233294Sstasvoid header_check(const char *); 82178825Sdfrvoid get_process_helpers_path(const atf_tc_t *, const bool, 83233294Sstas struct atf_fs_path *); 84178825Sdfrbool read_line(int, struct atf_dynstr *); 85233294Sstasvoid run_h_tc(atf_tc_t *, const char *, const char *, const char *); 86178825Sdfr