tc.h revision 275988
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
35struct atf_tc;
36
37typedef void (*atf_tc_head_t)(struct atf_tc *);
38typedef void (*atf_tc_body_t)(const struct atf_tc *);
39typedef void (*atf_tc_cleanup_t)(const struct atf_tc *);
40
41/* ---------------------------------------------------------------------
42 * The "atf_tc_pack" type.
43 * --------------------------------------------------------------------- */
44
45/* For static initialization only. */
46struct 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};
55typedef const struct atf_tc_pack atf_tc_pack_t;
56
57/* ---------------------------------------------------------------------
58 * The "atf_tc" type.
59 * --------------------------------------------------------------------- */
60
61struct atf_tc_impl;
62struct atf_tc {
63    struct atf_tc_impl *pimpl;
64};
65typedef struct atf_tc atf_tc_t;
66
67/* Constructors/destructors. */
68atf_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 *);
71atf_error_t atf_tc_init_pack(atf_tc_t *, atf_tc_pack_t *,
72                             const char *const *);
73void atf_tc_fini(atf_tc_t *);
74
75/* Getters. */
76const char *atf_tc_get_ident(const atf_tc_t *);
77const char *atf_tc_get_config_var(const atf_tc_t *, const char *);
78const char *atf_tc_get_config_var_wd(const atf_tc_t *, const char *,
79                                     const char *);
80bool atf_tc_get_config_var_as_bool(const atf_tc_t *, const char *);
81bool atf_tc_get_config_var_as_bool_wd(const atf_tc_t *, const char *,
82                                      const bool);
83long atf_tc_get_config_var_as_long(const atf_tc_t *, const char *);
84long atf_tc_get_config_var_as_long_wd(const atf_tc_t *, const char *,
85                                      const long);
86const char *atf_tc_get_md_var(const atf_tc_t *, const char *);
87char **atf_tc_get_md_vars(const atf_tc_t *);
88bool atf_tc_has_config_var(const atf_tc_t *, const char *);
89bool atf_tc_has_md_var(const atf_tc_t *, const char *);
90
91/* Modifiers. */
92atf_error_t atf_tc_set_md_var(atf_tc_t *, const char *, const char *, ...);
93
94/* ---------------------------------------------------------------------
95 * Free functions.
96 * --------------------------------------------------------------------- */
97
98atf_error_t atf_tc_run(const atf_tc_t *, const char *);
99atf_error_t atf_tc_cleanup(const atf_tc_t *);
100
101/* To be run from test case bodies only. */
102void atf_tc_fail(const char *, ...)
103    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2)
104    ATF_DEFS_ATTRIBUTE_NORETURN;
105void atf_tc_fail_nonfatal(const char *, ...)
106    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
107void atf_tc_pass(void)
108    ATF_DEFS_ATTRIBUTE_NORETURN;
109void atf_tc_require_prog(const char *);
110void atf_tc_skip(const char *, ...)
111    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2)
112    ATF_DEFS_ATTRIBUTE_NORETURN;
113void atf_tc_expect_pass(void);
114void atf_tc_expect_fail(const char *, ...)
115    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
116void atf_tc_expect_exit(const int, const char *, ...)
117    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3);
118void atf_tc_expect_signal(const int, const char *, ...)
119    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3);
120void atf_tc_expect_death(const char *, ...)
121    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
122void 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. */
126void atf_tc_fail_check(const char *, const size_t, const char *, ...)
127    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4);
128void atf_tc_fail_requirement(const char *, const size_t, const char *, ...)
129    ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4)
130    ATF_DEFS_ATTRIBUTE_NORETURN;
131void atf_tc_check_errno(const char *, const size_t, const int,
132                        const char *, const bool);
133void 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