summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/sys/atf-c.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/sys/atf-c.h')
-rw-r--r--src/regress/lib/libc/sys/atf-c.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/regress/lib/libc/sys/atf-c.h b/src/regress/lib/libc/sys/atf-c.h
new file mode 100644
index 0000000000..740881485d
--- /dev/null
+++ b/src/regress/lib/libc/sys/atf-c.h
@@ -0,0 +1,100 @@
1/* $OpenBSD: atf-c.h,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */
2/*
3 * Copyright (c) 2019 Moritz Buhl <openbsd@moritzbuhl.de>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#if !defined(ATF_C_H)
19#define ATF_C_H
20
21#include <pwd.h>
22#include <stdio.h>
23#include <string.h>
24#include <unistd.h>
25
26
27int atf_test(int, int);
28void atf_require(int, int, const char *, const char *, const int, char *, ...);
29void atf_tc_fail(char *, ...)
30 __attribute__((__noreturn__, __format__ (printf, 1, 2)));
31
32#define ATF_INSPECT_TEST 1
33#define ATF_RUN_TEST 2
34#define ATF_CLEANUP_TEST 3
35
36#define ATF_TC_FUNCTIONS(fn) \
37void atf_head_##fn(void); \
38void atf_body_##fn(void); \
39void atf_cleanup_##fn(void);
40
41#define ATF_TC(fn) \
42ATF_TC_FUNCTIONS(fn) \
43void atf_cleanup_##fn(void) { return; }
44
45#define ATF_TC_WITH_CLEANUP(fn) \
46ATF_TC_FUNCTIONS(fn)
47
48#define ATF_TC_HEAD(fn, tc) void atf_head_##fn(void)
49#define ATF_TC_BODY(fn, tc) void atf_body_##fn(void)
50#define ATF_TC_CLEANUP(fn, tc) void atf_cleanup_##fn(void)
51
52#define ATF_TP_ADD_TCS(tp) int atf_test(int tst, int what)
53#define ATF_TP_ADD_TC(tp, fn) tst--; \
54 if (tst == 0) { \
55 if (what == ATF_INSPECT_TEST) \
56 atf_head_##fn(); \
57 else if (what == ATF_RUN_TEST) \
58 atf_body_##fn(); \
59 else if (what == ATF_CLEANUP_TEST) \
60 atf_cleanup_##fn(); \
61 return 0; \
62 }
63
64#define atf_no_error() (-tst)
65
66#define ATF_INSPECT(i) atf_test(i, ATF_INSPECT_TEST)
67#define ATF_RUN(i) atf_test(i, ATF_RUN_TEST)
68#define ATF_CLEANUP(i) atf_test(i, ATF_CLEANUP_TEST)
69
70#define atf_tc_set_md_var(tc, attr, fmt, ...) \
71 if (strcmp(attr, "descr") == 0) \
72 printf("DESCR=\"" fmt "\"\n", ##__VA_ARGS__); \
73 else if (strcmp(attr, "require.user") == 0) \
74 printf("REQ_USER=" fmt "\n", ##__VA_ARGS__);
75
76#define ATF_CHECK ATF_REQUIRE
77#define ATF_CHECK_MSG ATF_REQUIRE_MSG
78#define ATF_CHECK_EQ ATF_REQUIRE_EQ
79
80#define atf_req(exp, err, msg, ...) \
81 atf_require(exp, err, #exp, __FILE__, __LINE__, NULL)
82#define ATF_REQUIRE(exp) atf_req(exp, -1, NULL)
83#define ATF_REQUIRE_ERRNO(no, exp) atf_req(exp, no, NULL)
84#define ATF_REQUIRE_MSG(exp, fmt, ...) atf_req(exp, -1, fmt, ##__VA_ARGS__)
85#define ATF_REQUIRE_EQ(a, b) atf_req((a) == (b), -1, NULL)
86#define ATF_REQUIRE_EQ_MSG(a, b, fmt, ...) \
87 atf_req((a) == (b), -1, fmt, ##__VA_ARGS__)
88
89#define atf_tc_fail_nonfatal(fmt, ...) atf_tc_fail(fmt, ##__VA_ARGS__)
90#define atf_tc_expect_fail(fmt, ...) \
91 atf_tc_fail(fmt "\nEXPECTED_FAIL", ##__VA_ARGS__)
92#define atf_tc_skip(fmt, ...) \
93 atf_tc_fail(fmt "\nSKIPPING", ##__VA_ARGS__)
94#define atf_tc_pass() exit(0)
95
96#define atf_tc_get_config_var(a, b) "."
97
98#define atf_utils_fork() fork()
99
100#endif /* !defined(ATF_C_H) */