xref: /minix3/external/bsd/atf/dist/atf-c/tc.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
111be35a1SLionel Sambuc /*
211be35a1SLionel Sambuc  * Automated Testing Framework (atf)
311be35a1SLionel Sambuc  *
411be35a1SLionel Sambuc  * Copyright (c) 2008 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc  * are met:
1011be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc  *
1611be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc  */
2911be35a1SLionel Sambuc 
3011be35a1SLionel Sambuc #if !defined(ATF_C_TC_H)
3111be35a1SLionel Sambuc #define ATF_C_TC_H
3211be35a1SLionel Sambuc 
3311be35a1SLionel Sambuc #include <stdbool.h>
3411be35a1SLionel Sambuc #include <stddef.h>
3511be35a1SLionel Sambuc 
3611be35a1SLionel Sambuc #include <atf-c/defs.h>
3711be35a1SLionel Sambuc #include <atf-c/error_fwd.h>
3811be35a1SLionel Sambuc 
3911be35a1SLionel Sambuc struct atf_tc;
4011be35a1SLionel Sambuc 
4111be35a1SLionel Sambuc typedef void (*atf_tc_head_t)(struct atf_tc *);
4211be35a1SLionel Sambuc typedef void (*atf_tc_body_t)(const struct atf_tc *);
4311be35a1SLionel Sambuc typedef void (*atf_tc_cleanup_t)(const struct atf_tc *);
4411be35a1SLionel Sambuc 
4511be35a1SLionel Sambuc /* ---------------------------------------------------------------------
4611be35a1SLionel Sambuc  * The "atf_tc_pack" type.
4711be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
4811be35a1SLionel Sambuc 
4911be35a1SLionel Sambuc /* For static initialization only. */
5011be35a1SLionel Sambuc struct atf_tc_pack {
5111be35a1SLionel Sambuc     const char *m_ident;
5211be35a1SLionel Sambuc 
5311be35a1SLionel Sambuc     const char *const *m_config;
5411be35a1SLionel Sambuc 
5511be35a1SLionel Sambuc     atf_tc_head_t m_head;
5611be35a1SLionel Sambuc     atf_tc_body_t m_body;
5711be35a1SLionel Sambuc     atf_tc_cleanup_t m_cleanup;
5811be35a1SLionel Sambuc };
5911be35a1SLionel Sambuc typedef const struct atf_tc_pack atf_tc_pack_t;
6011be35a1SLionel Sambuc 
6111be35a1SLionel Sambuc /* ---------------------------------------------------------------------
6211be35a1SLionel Sambuc  * The "atf_tc" type.
6311be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
6411be35a1SLionel Sambuc 
6511be35a1SLionel Sambuc struct atf_tc_impl;
6611be35a1SLionel Sambuc struct atf_tc {
6711be35a1SLionel Sambuc     struct atf_tc_impl *pimpl;
6811be35a1SLionel Sambuc };
6911be35a1SLionel Sambuc typedef struct atf_tc atf_tc_t;
7011be35a1SLionel Sambuc 
7111be35a1SLionel Sambuc /* Constructors/destructors. */
7211be35a1SLionel Sambuc atf_error_t atf_tc_init(atf_tc_t *, const char *, atf_tc_head_t,
7311be35a1SLionel Sambuc                         atf_tc_body_t, atf_tc_cleanup_t,
7411be35a1SLionel Sambuc                         const char *const *);
7511be35a1SLionel Sambuc atf_error_t atf_tc_init_pack(atf_tc_t *, atf_tc_pack_t *,
7611be35a1SLionel Sambuc                              const char *const *);
7711be35a1SLionel Sambuc void atf_tc_fini(atf_tc_t *);
7811be35a1SLionel Sambuc 
7911be35a1SLionel Sambuc /* Getters. */
8011be35a1SLionel Sambuc const char *atf_tc_get_ident(const atf_tc_t *);
8111be35a1SLionel Sambuc const char *atf_tc_get_config_var(const atf_tc_t *, const char *);
8211be35a1SLionel Sambuc const char *atf_tc_get_config_var_wd(const atf_tc_t *, const char *,
8311be35a1SLionel Sambuc                                      const char *);
8411be35a1SLionel Sambuc bool atf_tc_get_config_var_as_bool(const atf_tc_t *, const char *);
8511be35a1SLionel Sambuc bool atf_tc_get_config_var_as_bool_wd(const atf_tc_t *, const char *,
8611be35a1SLionel Sambuc                                       const bool);
8711be35a1SLionel Sambuc long atf_tc_get_config_var_as_long(const atf_tc_t *, const char *);
8811be35a1SLionel Sambuc long atf_tc_get_config_var_as_long_wd(const atf_tc_t *, const char *,
8911be35a1SLionel Sambuc                                       const long);
9011be35a1SLionel Sambuc const char *atf_tc_get_md_var(const atf_tc_t *, const char *);
9111be35a1SLionel Sambuc char **atf_tc_get_md_vars(const atf_tc_t *);
9211be35a1SLionel Sambuc bool atf_tc_has_config_var(const atf_tc_t *, const char *);
9311be35a1SLionel Sambuc bool atf_tc_has_md_var(const atf_tc_t *, const char *);
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc /* Modifiers. */
96*0a6a1f1dSLionel Sambuc atf_error_t atf_tc_set_md_var(atf_tc_t *, const char *, const char *, ...)
97*0a6a1f1dSLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4);
9811be35a1SLionel Sambuc 
9911be35a1SLionel Sambuc /* ---------------------------------------------------------------------
10011be35a1SLionel Sambuc  * Free functions.
10111be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
10211be35a1SLionel Sambuc 
10311be35a1SLionel Sambuc atf_error_t atf_tc_run(const atf_tc_t *, const char *);
10411be35a1SLionel Sambuc atf_error_t atf_tc_cleanup(const atf_tc_t *);
10511be35a1SLionel Sambuc 
10611be35a1SLionel Sambuc /* To be run from test case bodies only. */
10711be35a1SLionel Sambuc void atf_tc_fail(const char *, ...)
10811be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2)
10911be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_NORETURN;
11011be35a1SLionel Sambuc void atf_tc_fail_nonfatal(const char *, ...)
11111be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
11211be35a1SLionel Sambuc void atf_tc_pass(void)
11311be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_NORETURN;
11411be35a1SLionel Sambuc void atf_tc_require_prog(const char *);
11511be35a1SLionel Sambuc void atf_tc_skip(const char *, ...)
11611be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2)
11711be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_NORETURN;
11811be35a1SLionel Sambuc void atf_tc_expect_pass(void);
11911be35a1SLionel Sambuc void atf_tc_expect_fail(const char *, ...)
12011be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
12111be35a1SLionel Sambuc void atf_tc_expect_exit(const int, const char *, ...)
12211be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3);
12311be35a1SLionel Sambuc void atf_tc_expect_signal(const int, const char *, ...)
12411be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(2, 3);
12511be35a1SLionel Sambuc void atf_tc_expect_death(const char *, ...)
12611be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
12711be35a1SLionel Sambuc void atf_tc_expect_timeout(const char *, ...)
12811be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(1, 2);
12911be35a1SLionel Sambuc 
13011be35a1SLionel Sambuc /* To be run from test case bodies only; internal to macros.h. */
13111be35a1SLionel Sambuc void atf_tc_fail_check(const char *, const size_t, const char *, ...)
13211be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4);
13311be35a1SLionel Sambuc void atf_tc_fail_requirement(const char *, const size_t, const char *, ...)
13411be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_FORMAT_PRINTF(3, 4)
13511be35a1SLionel Sambuc     ATF_DEFS_ATTRIBUTE_NORETURN;
13611be35a1SLionel Sambuc void atf_tc_check_errno(const char *, const size_t, const int,
13711be35a1SLionel Sambuc                         const char *, const bool);
13811be35a1SLionel Sambuc void atf_tc_require_errno(const char *, const size_t, const int,
13911be35a1SLionel Sambuc                           const char *, const bool);
14011be35a1SLionel Sambuc 
14111be35a1SLionel Sambuc #endif /* ATF_C_TC_H */
142