xref: /netbsd-src/external/bsd/atf/dist/atf-c/tc.h (revision 4e6df137e8e14049b5a701d249962c480449c141)
1 /*
2  * Automated Testing Framework (atf)
3  *
4  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #if !defined(ATF_C_TC_H)
31 #define ATF_C_TC_H
32 
33 #include <atf-c/defs.h>
34 #include <atf-c/error_fwd.h>
35 #include <atf-c/map.h>
36 #include <atf-c/object.h>
37 
38 struct atf_dynstr;
39 struct atf_fs_path;
40 struct atf_tc;
41 struct atf_tcr;
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 atf_map_t *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 {
68     atf_object_t m_object;
69 
70     const char *m_ident;
71 
72     atf_map_t m_vars;
73     const atf_map_t *m_config;
74 
75     atf_tc_head_t m_head;
76     atf_tc_body_t m_body;
77     atf_tc_cleanup_t m_cleanup;
78 };
79 typedef struct atf_tc atf_tc_t;
80 
81 /* Constructors/destructors. */
82 atf_error_t atf_tc_init(atf_tc_t *, const char *, atf_tc_head_t,
83                         atf_tc_body_t, atf_tc_cleanup_t,
84                         const atf_map_t *);
85 atf_error_t atf_tc_init_pack(atf_tc_t *, atf_tc_pack_t *,
86                              const atf_map_t *);
87 void atf_tc_fini(atf_tc_t *);
88 
89 /* Getters. */
90 const char *atf_tc_get_ident(const atf_tc_t *);
91 const char *atf_tc_get_config_var(const atf_tc_t *, const char *);
92 const char *atf_tc_get_config_var_wd(const atf_tc_t *, const char *,
93                                      const char *);
94 const char *atf_tc_get_md_var(const atf_tc_t *, const char *);
95 bool atf_tc_has_config_var(const atf_tc_t *, const char *);
96 bool atf_tc_has_md_var(const atf_tc_t *, const char *);
97 
98 /* Modifiers. */
99 atf_error_t atf_tc_set_md_var(atf_tc_t *, const char *, const char *, ...);
100 
101 /* ---------------------------------------------------------------------
102  * Free functions.
103  * --------------------------------------------------------------------- */
104 
105 atf_error_t atf_tc_run(const atf_tc_t *, struct atf_tcr *,
106                        int, int, const struct atf_fs_path *);
107 
108 /* To be run from test case bodies only. */
109 void atf_tc_fail(const char *, ...) ATF_DEFS_ATTRIBUTE_NORETURN;
110 void atf_tc_fail_nonfatal(const char *, ...);
111 void atf_tc_pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;
112 void atf_tc_require_prog(const char *);
113 void atf_tc_skip(const char *, ...) ATF_DEFS_ATTRIBUTE_NORETURN;
114 
115 /* To be run from test case bodies only; internal to macros.h. */
116 void atf_tc_fail_check(const char *, int, const char *, ...);
117 void atf_tc_fail_requirement(const char *, int, const char *, ...)
118      ATF_DEFS_ATTRIBUTE_NORETURN;
119 
120 #endif /* ATF_C_TC_H */
121