1*0677dfd1SJulio Merino /* Copyright (c) 2008 The NetBSD Foundation, Inc. 2c243e490SMarcel Moolenaar * All rights reserved. 3c243e490SMarcel Moolenaar * 4c243e490SMarcel Moolenaar * Redistribution and use in source and binary forms, with or without 5c243e490SMarcel Moolenaar * modification, are permitted provided that the following conditions 6c243e490SMarcel Moolenaar * are met: 7c243e490SMarcel Moolenaar * 1. Redistributions of source code must retain the above copyright 8c243e490SMarcel Moolenaar * notice, this list of conditions and the following disclaimer. 9c243e490SMarcel Moolenaar * 2. Redistributions in binary form must reproduce the above copyright 10c243e490SMarcel Moolenaar * notice, this list of conditions and the following disclaimer in the 11c243e490SMarcel Moolenaar * documentation and/or other materials provided with the distribution. 12c243e490SMarcel Moolenaar * 13c243e490SMarcel Moolenaar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 14c243e490SMarcel Moolenaar * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 15c243e490SMarcel Moolenaar * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16c243e490SMarcel Moolenaar * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17c243e490SMarcel Moolenaar * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 18c243e490SMarcel Moolenaar * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19c243e490SMarcel Moolenaar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 20c243e490SMarcel Moolenaar * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21c243e490SMarcel Moolenaar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 22c243e490SMarcel Moolenaar * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23c243e490SMarcel Moolenaar * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 24*0677dfd1SJulio Merino * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 25c243e490SMarcel Moolenaar 26c243e490SMarcel Moolenaar #if !defined(ATF_C_TC_H) 27c243e490SMarcel Moolenaar #define ATF_C_TC_H 28c243e490SMarcel Moolenaar 29c243e490SMarcel Moolenaar #include <stdbool.h> 30c243e490SMarcel Moolenaar #include <stddef.h> 31c243e490SMarcel Moolenaar 32c243e490SMarcel Moolenaar #include <atf-c/defs.h> 33c243e490SMarcel Moolenaar #include <atf-c/error_fwd.h> 34c243e490SMarcel Moolenaar 35c243e490SMarcel Moolenaar struct atf_tc; 36c243e490SMarcel Moolenaar 37c243e490SMarcel Moolenaar typedef void (*atf_tc_head_t)(struct atf_tc *); 38c243e490SMarcel Moolenaar typedef void (*atf_tc_body_t)(const struct atf_tc *); 39c243e490SMarcel Moolenaar typedef void (*atf_tc_cleanup_t)(const struct atf_tc *); 40c243e490SMarcel Moolenaar 41c243e490SMarcel Moolenaar /* --------------------------------------------------------------------- 42c243e490SMarcel Moolenaar * The "atf_tc_pack" type. 43c243e490SMarcel Moolenaar * --------------------------------------------------------------------- */ 44c243e490SMarcel Moolenaar 45c243e490SMarcel Moolenaar /* For static initialization only. */ 46c243e490SMarcel Moolenaar struct atf_tc_pack { 47c243e490SMarcel Moolenaar const char *m_ident; 48c243e490SMarcel Moolenaar 49c243e490SMarcel Moolenaar const char *const *m_config; 50c243e490SMarcel Moolenaar 51c243e490SMarcel Moolenaar atf_tc_head_t m_head; 52c243e490SMarcel Moolenaar atf_tc_body_t m_body; 53c243e490SMarcel Moolenaar atf_tc_cleanup_t m_cleanup; 54c243e490SMarcel Moolenaar }; 55c243e490SMarcel Moolenaar typedef const struct atf_tc_pack atf_tc_pack_t; 56c243e490SMarcel Moolenaar 57c243e490SMarcel Moolenaar /* --------------------------------------------------------------------- 58c243e490SMarcel Moolenaar * The "atf_tc" type. 59c243e490SMarcel Moolenaar * --------------------------------------------------------------------- */ 60c243e490SMarcel Moolenaar 61c243e490SMarcel Moolenaar struct atf_tc_impl; 62c243e490SMarcel Moolenaar struct atf_tc { 63c243e490SMarcel Moolenaar struct atf_tc_impl *pimpl; 64c243e490SMarcel Moolenaar }; 65c243e490SMarcel Moolenaar typedef struct atf_tc atf_tc_t; 66c243e490SMarcel Moolenaar 67c243e490SMarcel Moolenaar /* Constructors/destructors. */ 68c243e490SMarcel Moolenaar atf_error_t atf_tc_init(atf_tc_t *, const char *, atf_tc_head_t, 69c243e490SMarcel Moolenaar atf_tc_body_t, atf_tc_cleanup_t, 70c243e490SMarcel Moolenaar const char *const *); 71c243e490SMarcel Moolenaar atf_error_t atf_tc_init_pack(atf_tc_t *, atf_tc_pack_t *, 72c243e490SMarcel Moolenaar const char *const *); 73c243e490SMarcel Moolenaar void atf_tc_fini(atf_tc_t *); 74c243e490SMarcel Moolenaar 75c243e490SMarcel Moolenaar /* Getters. */ 76c243e490SMarcel Moolenaar const char *atf_tc_get_ident(const atf_tc_t *); 77c243e490SMarcel Moolenaar const char *atf_tc_get_config_var(const atf_tc_t *, const char *); 78c243e490SMarcel Moolenaar const char *atf_tc_get_config_var_wd(const atf_tc_t *, const char *, 79c243e490SMarcel Moolenaar const char *); 80c243e490SMarcel Moolenaar bool atf_tc_get_config_var_as_bool(const atf_tc_t *, const char *); 81c243e490SMarcel Moolenaar bool atf_tc_get_config_var_as_bool_wd(const atf_tc_t *, const char *, 82c243e490SMarcel Moolenaar const bool); 83c243e490SMarcel Moolenaar long atf_tc_get_config_var_as_long(const atf_tc_t *, const char *); 84c243e490SMarcel Moolenaar long atf_tc_get_config_var_as_long_wd(const atf_tc_t *, const char *, 85c243e490SMarcel Moolenaar const long); 86c243e490SMarcel Moolenaar const char *atf_tc_get_md_var(const atf_tc_t *, const char *); 87c243e490SMarcel Moolenaar char **atf_tc_get_md_vars(const atf_tc_t *); 88c243e490SMarcel Moolenaar bool atf_tc_has_config_var(const atf_tc_t *, const char *); 89c243e490SMarcel Moolenaar bool atf_tc_has_md_var(const atf_tc_t *, const char *); 90c243e490SMarcel Moolenaar 91c243e490SMarcel Moolenaar /* Modifiers. */ 92c243e490SMarcel Moolenaar atf_error_t atf_tc_set_md_var(atf_tc_t *, const char *, const char *, ...); 93c243e490SMarcel Moolenaar 94c243e490SMarcel Moolenaar /* --------------------------------------------------------------------- 95c243e490SMarcel Moolenaar * Free functions. 96c243e490SMarcel Moolenaar * --------------------------------------------------------------------- */ 97c243e490SMarcel Moolenaar 98c243e490SMarcel Moolenaar atf_error_t atf_tc_run(const atf_tc_t *, const char *); 99c243e490SMarcel Moolenaar atf_error_t atf_tc_cleanup(const atf_tc_t *); 100c243e490SMarcel Moolenaar 101c243e490SMarcel Moolenaar /* To be run from test case bodies only. */ 102c243e490SMarcel Moolenaar void atf_tc_fail(const char *, ...) 103c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2) 104c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_NORETURN; 105c243e490SMarcel Moolenaar void atf_tc_fail_nonfatal(const char *, ...) 106c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 107c243e490SMarcel Moolenaar void atf_tc_pass(void) 108c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_NORETURN; 109c243e490SMarcel Moolenaar void atf_tc_require_prog(const char *); 110c243e490SMarcel Moolenaar void atf_tc_skip(const char *, ...) 111c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2) 112c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_NORETURN; 113c243e490SMarcel Moolenaar void atf_tc_expect_pass(void); 114c243e490SMarcel Moolenaar void atf_tc_expect_fail(const char *, ...) 115c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 116c243e490SMarcel Moolenaar void atf_tc_expect_exit(const int, const char *, ...) 117c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3); 118c243e490SMarcel Moolenaar void atf_tc_expect_signal(const int, const char *, ...) 119c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3); 120c243e490SMarcel Moolenaar void atf_tc_expect_death(const char *, ...) 121c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 122c243e490SMarcel Moolenaar void atf_tc_expect_timeout(const char *, ...) 123c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 124c243e490SMarcel Moolenaar 125c243e490SMarcel Moolenaar /* To be run from test case bodies only; internal to macros.h. */ 126c243e490SMarcel Moolenaar void atf_tc_fail_check(const char *, const size_t, const char *, ...) 127c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4); 128c243e490SMarcel Moolenaar void atf_tc_fail_requirement(const char *, const size_t, const char *, ...) 129c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4) 130c243e490SMarcel Moolenaar ATF_DEFS_ATTRIBUTE_NORETURN; 131c243e490SMarcel Moolenaar void atf_tc_check_errno(const char *, const size_t, const int, 132c243e490SMarcel Moolenaar const char *, const bool); 133c243e490SMarcel Moolenaar void atf_tc_require_errno(const char *, const size_t, const int, 134c243e490SMarcel Moolenaar const char *, const bool); 135c243e490SMarcel Moolenaar 136*0677dfd1SJulio Merino #endif /* !defined(ATF_C_TC_H) */ 137