1240116Smarcel/* 2240116Smarcel * Automated Testing Framework (atf) 3240116Smarcel * 4240116Smarcel * Copyright (c) 2008 The NetBSD Foundation, Inc. 5240116Smarcel * All rights reserved. 6240116Smarcel * 7240116Smarcel * Redistribution and use in source and binary forms, with or without 8240116Smarcel * modification, are permitted provided that the following conditions 9240116Smarcel * are met: 10240116Smarcel * 1. Redistributions of source code must retain the above copyright 11240116Smarcel * notice, this list of conditions and the following disclaimer. 12240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright 13240116Smarcel * notice, this list of conditions and the following disclaimer in the 14240116Smarcel * documentation and/or other materials provided with the distribution. 15240116Smarcel * 16240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17240116Smarcel * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18240116Smarcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19240116Smarcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20240116Smarcel * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21240116Smarcel * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23240116Smarcel * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24240116Smarcel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25240116Smarcel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26240116Smarcel * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27240116Smarcel * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28240116Smarcel */ 29240116Smarcel 30240116Smarcel#if defined(TESTS_ATF_ATF_C_TEST_HELPERS_H) 31240116Smarcel# error "Cannot include test_helpers.h more than once." 32240116Smarcel#else 33240116Smarcel# define TESTS_ATF_ATF_C_TEST_HELPERS_H 34240116Smarcel#endif 35240116Smarcel 36240116Smarcel#include <stdbool.h> 37240116Smarcel 38240116Smarcel#include "atf-c/error_fwd.h" 39240116Smarcel 40240116Smarcelstruct atf_dynstr; 41240116Smarcelstruct atf_fs_path; 42240116Smarcel 43240116Smarcel#define CE(stm) ATF_CHECK(!atf_is_error(stm)) 44240116Smarcel#define RE(stm) ATF_REQUIRE(!atf_is_error(stm)) 45240116Smarcel 46240116Smarcel#define HEADER_TC(name, hdrname) \ 47240116Smarcel ATF_TC(name); \ 48240116Smarcel ATF_TC_HEAD(name, tc) \ 49240116Smarcel { \ 50240116Smarcel atf_tc_set_md_var(tc, "descr", "Tests that the " hdrname " file can " \ 51240116Smarcel "be included on its own, without any prerequisites"); \ 52240116Smarcel } \ 53240116Smarcel ATF_TC_BODY(name, tc) \ 54240116Smarcel { \ 55240116Smarcel header_check(hdrname); \ 56240116Smarcel } 57240116Smarcel 58240116Smarcel#define BUILD_TC(name, sfile, descr, failmsg) \ 59240116Smarcel ATF_TC(name); \ 60240116Smarcel ATF_TC_HEAD(name, tc) \ 61240116Smarcel { \ 62240116Smarcel atf_tc_set_md_var(tc, "descr", descr); \ 63240116Smarcel } \ 64240116Smarcel ATF_TC_BODY(name, tc) \ 65240116Smarcel { \ 66240116Smarcel build_check_c_o(tc, sfile, failmsg, true); \ 67240116Smarcel } 68240116Smarcel 69240116Smarcel#define BUILD_TC_FAIL(name, sfile, descr, failmsg) \ 70240116Smarcel ATF_TC(name); \ 71240116Smarcel ATF_TC_HEAD(name, tc) \ 72240116Smarcel { \ 73240116Smarcel atf_tc_set_md_var(tc, "descr", descr); \ 74240116Smarcel } \ 75240116Smarcel ATF_TC_BODY(name, tc) \ 76240116Smarcel { \ 77240116Smarcel build_check_c_o(tc, sfile, failmsg, false); \ 78240116Smarcel } 79240116Smarcel 80240116Smarcelvoid build_check_c_o(const atf_tc_t *, const char *, const char *, const bool); 81240116Smarcelvoid header_check(const char *); 82240116Smarcelvoid get_process_helpers_path(const atf_tc_t *, const bool, 83240116Smarcel struct atf_fs_path *); 84240116Smarcelbool grep_string(const struct atf_dynstr *, const char *); 85240116Smarcelbool grep_file(const char *, const char *, ...); 86240116Smarcelbool read_line(int, struct atf_dynstr *); 87240116Smarcelvoid run_h_tc(atf_tc_t *, const char *, const char *, const char *); 88