proc: test /proc/thread-self symlink
[linux/fpc-iii.git] / tools / testing / selftests / kselftest.h
blob15e6b75fc3a5e499fb7bcc981b6f19059406c2f6
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * kselftest.h: kselftest framework return codes to include from
4 * selftests.
6 * Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com>
7 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
9 */
10 #ifndef __KSELFTEST_H
11 #define __KSELFTEST_H
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <stdarg.h>
17 /* define kselftest exit codes */
18 #define KSFT_PASS 0
19 #define KSFT_FAIL 1
20 #define KSFT_XFAIL 2
21 #define KSFT_XPASS 3
22 /* Treat skip as pass */
23 #define KSFT_SKIP 4
25 /* counters */
26 struct ksft_count {
27 unsigned int ksft_pass;
28 unsigned int ksft_fail;
29 unsigned int ksft_xfail;
30 unsigned int ksft_xpass;
31 unsigned int ksft_xskip;
32 unsigned int ksft_error;
35 static struct ksft_count ksft_cnt;
37 static inline int ksft_test_num(void)
39 return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
40 ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
41 ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
44 static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
45 static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
46 static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
47 static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
48 static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
49 static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
51 static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
52 static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
53 static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
54 static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
55 static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
56 static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
58 static inline void ksft_print_header(void)
60 if (!(getenv("KSFT_TAP_LEVEL")))
61 printf("TAP version 13\n");
64 static inline void ksft_print_cnts(void)
66 printf("Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
67 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
68 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
69 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
70 printf("1..%d\n", ksft_test_num());
73 static inline void ksft_print_msg(const char *msg, ...)
75 va_list args;
77 va_start(args, msg);
78 printf("# ");
79 vprintf(msg, args);
80 va_end(args);
83 static inline void ksft_test_result_pass(const char *msg, ...)
85 va_list args;
87 ksft_cnt.ksft_pass++;
89 va_start(args, msg);
90 printf("ok %d ", ksft_test_num());
91 vprintf(msg, args);
92 va_end(args);
95 static inline void ksft_test_result_fail(const char *msg, ...)
97 va_list args;
99 ksft_cnt.ksft_fail++;
101 va_start(args, msg);
102 printf("not ok %d ", ksft_test_num());
103 vprintf(msg, args);
104 va_end(args);
107 static inline void ksft_test_result_skip(const char *msg, ...)
109 va_list args;
111 ksft_cnt.ksft_xskip++;
113 va_start(args, msg);
114 printf("ok %d # skip ", ksft_test_num());
115 vprintf(msg, args);
116 va_end(args);
119 static inline void ksft_test_result_error(const char *msg, ...)
121 va_list args;
123 ksft_cnt.ksft_error++;
125 va_start(args, msg);
126 printf("not ok %d # error ", ksft_test_num());
127 vprintf(msg, args);
128 va_end(args);
131 static inline int ksft_exit_pass(void)
133 ksft_print_cnts();
134 exit(KSFT_PASS);
137 static inline int ksft_exit_fail(void)
139 printf("Bail out!\n");
140 ksft_print_cnts();
141 exit(KSFT_FAIL);
144 static inline int ksft_exit_fail_msg(const char *msg, ...)
146 va_list args;
148 va_start(args, msg);
149 printf("Bail out! ");
150 vprintf(msg, args);
151 va_end(args);
153 ksft_print_cnts();
154 exit(KSFT_FAIL);
157 static inline int ksft_exit_xfail(void)
159 ksft_print_cnts();
160 exit(KSFT_XFAIL);
163 static inline int ksft_exit_xpass(void)
165 ksft_print_cnts();
166 exit(KSFT_XPASS);
169 static inline int ksft_exit_skip(const char *msg, ...)
171 if (msg) {
172 va_list args;
174 va_start(args, msg);
175 printf("1..%d # Skipped: ", ksft_test_num());
176 vprintf(msg, args);
177 va_end(args);
178 } else {
179 ksft_print_cnts();
181 exit(KSFT_SKIP);
184 #endif /* __KSELFTEST_H */