1 /* SPDX-License-Identifier: GPL-2.0 */
3 * kselftest.h: kselftest framework return codes to include from
6 * Copyright (c) 2014 Shuah Khan <shuahkh@osg.samsung.com>
7 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
19 /* define kselftest exit codes */
28 unsigned int ksft_pass;
29 unsigned int ksft_fail;
30 unsigned int ksft_xfail;
31 unsigned int ksft_xpass;
32 unsigned int ksft_xskip;
33 unsigned int ksft_error;
36 static struct ksft_count ksft_cnt;
37 static unsigned int ksft_plan;
39 static inline int ksft_test_num(void)
41 return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
42 ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
43 ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
46 static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
47 static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
48 static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
49 static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
50 static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
51 static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
53 static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
54 static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
55 static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
56 static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
57 static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
58 static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
60 static inline void ksft_print_header(void)
62 if (!(getenv("KSFT_TAP_LEVEL")))
63 printf("TAP version 13\n");
66 static inline void ksft_set_plan(unsigned int plan)
69 printf("1..%d\n", ksft_plan);
72 static inline void ksft_print_cnts(void)
74 if (ksft_plan != ksft_test_num())
75 printf("# Planned tests != run tests (%u != %u)\n",
76 ksft_plan, ksft_test_num());
77 printf("# Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
78 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
79 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
80 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
83 static inline void ksft_print_msg(const char *msg, ...)
85 int saved_errno = errno;
95 static inline void ksft_test_result_pass(const char *msg, ...)
97 int saved_errno = errno;
100 ksft_cnt.ksft_pass++;
103 printf("ok %d ", ksft_test_num());
109 static inline void ksft_test_result_fail(const char *msg, ...)
111 int saved_errno = errno;
114 ksft_cnt.ksft_fail++;
117 printf("not ok %d ", ksft_test_num());
123 static inline void ksft_test_result_skip(const char *msg, ...)
125 int saved_errno = errno;
128 ksft_cnt.ksft_xskip++;
131 printf("not ok %d # SKIP ", ksft_test_num());
137 static inline void ksft_test_result_error(const char *msg, ...)
139 int saved_errno = errno;
142 ksft_cnt.ksft_error++;
145 printf("not ok %d # error ", ksft_test_num());
151 static inline int ksft_exit_pass(void)
157 static inline int ksft_exit_fail(void)
159 printf("Bail out!\n");
164 static inline int ksft_exit_fail_msg(const char *msg, ...)
166 int saved_errno = errno;
170 printf("Bail out! ");
179 static inline int ksft_exit_xfail(void)
185 static inline int ksft_exit_xpass(void)
191 static inline int ksft_exit_skip(const char *msg, ...)
194 int saved_errno = errno;
198 printf("not ok %d # SKIP ", 1 + ksft_test_num());
208 #endif /* __KSELFTEST_H */