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.
18 /* define kselftest exit codes */
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;
36 static unsigned int ksft_plan;
38 static inline int ksft_test_num(void)
40 return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
41 ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
42 ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
45 static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
46 static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
47 static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
48 static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
49 static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
50 static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
52 static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
53 static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
54 static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
55 static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
56 static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
57 static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
59 static inline void ksft_print_header(void)
61 if (!(getenv("KSFT_TAP_LEVEL")))
62 printf("TAP version 13\n");
65 static inline void ksft_set_plan(unsigned int plan)
68 printf("1..%d\n", ksft_plan);
71 static inline void ksft_print_cnts(void)
73 if (ksft_plan != ksft_test_num())
74 printf("# Planned tests != run tests (%u != %u)\n",
75 ksft_plan, ksft_test_num());
76 printf("# Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
77 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
78 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
79 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
82 static inline void ksft_print_msg(const char *msg, ...)
92 static inline void ksft_test_result_pass(const char *msg, ...)
99 printf("ok %d ", ksft_test_num());
104 static inline void ksft_test_result_fail(const char *msg, ...)
108 ksft_cnt.ksft_fail++;
111 printf("not ok %d ", ksft_test_num());
116 static inline void ksft_test_result_skip(const char *msg, ...)
120 ksft_cnt.ksft_xskip++;
123 printf("not ok %d # SKIP ", ksft_test_num());
128 static inline void ksft_test_result_error(const char *msg, ...)
132 ksft_cnt.ksft_error++;
135 printf("not ok %d # error ", ksft_test_num());
140 static inline int ksft_exit_pass(void)
146 static inline int ksft_exit_fail(void)
148 printf("Bail out!\n");
153 static inline int ksft_exit_fail_msg(const char *msg, ...)
158 printf("Bail out! ");
166 static inline int ksft_exit_xfail(void)
172 static inline int ksft_exit_xpass(void)
178 static inline int ksft_exit_skip(const char *msg, ...)
184 printf("not ok %d # SKIP ", 1 + ksft_test_num());
193 #endif /* __KSELFTEST_H */