1 /* $NetBSD: tc.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(ATF_C_TC_H) 33 #define ATF_C_TC_H 34 35 #include <stdbool.h> 36 #include <stddef.h> 37 38 #include <atf-c/defs.h> 39 #include <atf-c/error_fwd.h> 40 41 struct atf_tc; 42 43 typedef void (*atf_tc_head_t)(struct atf_tc *); 44 typedef void (*atf_tc_body_t)(const struct atf_tc *); 45 typedef void (*atf_tc_cleanup_t)(const struct atf_tc *); 46 47 /* --------------------------------------------------------------------- 48 * The "atf_tc_pack" type. 49 * --------------------------------------------------------------------- */ 50 51 /* For static initialization only. */ 52 struct atf_tc_pack { 53 const char *m_ident; 54 55 const char *const *m_config; 56 57 atf_tc_head_t m_head; 58 atf_tc_body_t m_body; 59 atf_tc_cleanup_t m_cleanup; 60 }; 61 typedef const struct atf_tc_pack atf_tc_pack_t; 62 63 /* --------------------------------------------------------------------- 64 * The "atf_tc" type. 65 * --------------------------------------------------------------------- */ 66 67 struct atf_tc_impl; 68 struct atf_tc { 69 struct atf_tc_impl *pimpl; 70 }; 71 typedef struct atf_tc atf_tc_t; 72 73 /* Constructors/destructors. */ 74 atf_error_t atf_tc_init(atf_tc_t *, const char *, atf_tc_head_t, 75 atf_tc_body_t, atf_tc_cleanup_t, 76 const char *const *); 77 atf_error_t atf_tc_init_pack(atf_tc_t *, atf_tc_pack_t *, 78 const char *const *); 79 void atf_tc_fini(atf_tc_t *); 80 81 /* Getters. */ 82 const char *atf_tc_get_ident(const atf_tc_t *); 83 const char *atf_tc_get_config_var(const atf_tc_t *, const char *); 84 const char *atf_tc_get_config_var_wd(const atf_tc_t *, const char *, 85 const char *); 86 bool atf_tc_get_config_var_as_bool(const atf_tc_t *, const char *); 87 bool atf_tc_get_config_var_as_bool_wd(const atf_tc_t *, const char *, 88 const bool); 89 long atf_tc_get_config_var_as_long(const atf_tc_t *, const char *); 90 long atf_tc_get_config_var_as_long_wd(const atf_tc_t *, const char *, 91 const long); 92 const char *atf_tc_get_md_var(const atf_tc_t *, const char *); 93 char **atf_tc_get_md_vars(const atf_tc_t *); 94 bool atf_tc_has_config_var(const atf_tc_t *, const char *); 95 bool atf_tc_has_md_var(const atf_tc_t *, const char *); 96 97 /* Modifiers. */ 98 atf_error_t atf_tc_set_md_var(atf_tc_t *, const char *, const char *, ...); 99 100 /* --------------------------------------------------------------------- 101 * Free functions. 102 * --------------------------------------------------------------------- */ 103 104 atf_error_t atf_tc_run(const atf_tc_t *, const char *); 105 atf_error_t atf_tc_cleanup(const atf_tc_t *); 106 107 /* To be run from test case bodies only. */ 108 void atf_tc_fail(const char *, ...) 109 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2) 110 ATF_DEFS_ATTRIBUTE_NORETURN; 111 void atf_tc_fail_nonfatal(const char *, ...) 112 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 113 void atf_tc_pass(void) 114 ATF_DEFS_ATTRIBUTE_NORETURN; 115 void atf_tc_require_prog(const char *); 116 void atf_tc_skip(const char *, ...) 117 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2) 118 ATF_DEFS_ATTRIBUTE_NORETURN; 119 void atf_tc_expect_pass(void); 120 void atf_tc_expect_fail(const char *, ...) 121 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 122 void atf_tc_expect_exit(const int, const char *, ...) 123 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3); 124 void atf_tc_expect_signal(const int, const char *, ...) 125 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3); 126 void atf_tc_expect_death(const char *, ...) 127 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 128 void atf_tc_expect_timeout(const char *, ...) 129 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2); 130 131 /* To be run from test case bodies only; internal to macros.h. */ 132 void atf_tc_fail_check(const char *, const size_t, const char *, ...) 133 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4); 134 void atf_tc_fail_requirement(const char *, const size_t, const char *, ...) 135 ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4) 136 ATF_DEFS_ATTRIBUTE_NORETURN; 137 void atf_tc_check_errno(const char *, const size_t, const int, 138 const char *, const bool); 139 void atf_tc_require_errno(const char *, const size_t, const int, 140 const char *, const bool); 141 142 #endif /* ATF_C_TC_H */ 143