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