]> Git Repo - linux.git/blame - tools/testing/selftests/kselftest.h
x86/MCE/AMD: Fix the thresholding machinery initialization order
[linux.git] / tools / testing / selftests / kselftest.h
CommitLineData
7c466b97 1/* SPDX-License-Identifier: GPL-2.0 */
7fb2c3ea
SK
2/*
3 * kselftest.h: kselftest framework return codes to include from
4 * selftests.
5 *
6 * Copyright (c) 2014 Shuah Khan <[email protected]>
7 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
8 *
7fb2c3ea
SK
9 */
10#ifndef __KSELFTEST_H
11#define __KSELFTEST_H
12
13#include <stdlib.h>
14#include <unistd.h>
151b2732 15#include <stdarg.h>
7fb2c3ea 16
4100e675
DH
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
3c07aaef 22#define KSFT_SKIP 4
4100e675 23
7fb2c3ea
SK
24/* counters */
25struct ksft_count {
26 unsigned int ksft_pass;
27 unsigned int ksft_fail;
28 unsigned int ksft_xfail;
29 unsigned int ksft_xpass;
30 unsigned int ksft_xskip;
c0bb2cf4 31 unsigned int ksft_error;
7fb2c3ea
SK
32};
33
34static struct ksft_count ksft_cnt;
35
b6a4b66d
PE
36static inline int ksft_test_num(void)
37{
38 return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
39 ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
c0bb2cf4 40 ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
b6a4b66d
PE
41}
42
7fb2c3ea
SK
43static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
44static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
45static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
46static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
47static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
c0bb2cf4 48static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
7fb2c3ea 49
1d3ee8be
SK
50static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
51static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
52static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
53static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
54static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
c0bb2cf4 55static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
1d3ee8be 56
b6a4b66d
PE
57static inline void ksft_print_header(void)
58{
10f531f6
SK
59 if (!(getenv("KSFT_TAP_LEVEL")))
60 printf("TAP version 13\n");
b6a4b66d
PE
61}
62
7fb2c3ea
SK
63static inline void ksft_print_cnts(void)
64{
c0bb2cf4 65 printf("Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
1d3ee8be
SK
66 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
67 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
c0bb2cf4 68 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
b6a4b66d
PE
69 printf("1..%d\n", ksft_test_num());
70}
71
ab52a484
PE
72static inline void ksft_print_msg(const char *msg, ...)
73{
74 va_list args;
75
76 va_start(args, msg);
77 printf("# ");
78 vprintf(msg, args);
79 va_end(args);
80}
81
151b2732 82static inline void ksft_test_result_pass(const char *msg, ...)
b6a4b66d 83{
151b2732
PE
84 va_list args;
85
b6a4b66d 86 ksft_cnt.ksft_pass++;
151b2732
PE
87
88 va_start(args, msg);
89 printf("ok %d ", ksft_test_num());
90 vprintf(msg, args);
91 va_end(args);
b6a4b66d
PE
92}
93
151b2732 94static inline void ksft_test_result_fail(const char *msg, ...)
b6a4b66d 95{
151b2732
PE
96 va_list args;
97
b6a4b66d 98 ksft_cnt.ksft_fail++;
151b2732
PE
99
100 va_start(args, msg);
101 printf("not ok %d ", ksft_test_num());
102 vprintf(msg, args);
103 va_end(args);
b6a4b66d
PE
104}
105
151b2732 106static inline void ksft_test_result_skip(const char *msg, ...)
b6a4b66d 107{
151b2732
PE
108 va_list args;
109
b6a4b66d 110 ksft_cnt.ksft_xskip++;
151b2732
PE
111
112 va_start(args, msg);
113 printf("ok %d # skip ", ksft_test_num());
114 vprintf(msg, args);
115 va_end(args);
7fb2c3ea
SK
116}
117
c0bb2cf4
SK
118static inline void ksft_test_result_error(const char *msg, ...)
119{
120 va_list args;
121
122 ksft_cnt.ksft_error++;
123
124 va_start(args, msg);
125 printf("not ok %d # error ", ksft_test_num());
126 vprintf(msg, args);
127 va_end(args);
128}
129
7fb2c3ea
SK
130static inline int ksft_exit_pass(void)
131{
b6a4b66d 132 ksft_print_cnts();
4100e675 133 exit(KSFT_PASS);
7fb2c3ea 134}
b6a4b66d 135
7fb2c3ea
SK
136static inline int ksft_exit_fail(void)
137{
b6a4b66d
PE
138 printf("Bail out!\n");
139 ksft_print_cnts();
4100e675 140 exit(KSFT_FAIL);
7fb2c3ea 141}
b6a4b66d 142
151b2732 143static inline int ksft_exit_fail_msg(const char *msg, ...)
b6a4b66d 144{
151b2732
PE
145 va_list args;
146
147 va_start(args, msg);
148 printf("Bail out! ");
149 vprintf(msg, args);
150 va_end(args);
151
b6a4b66d
PE
152 ksft_print_cnts();
153 exit(KSFT_FAIL);
154}
155
7fb2c3ea
SK
156static inline int ksft_exit_xfail(void)
157{
b6a4b66d 158 ksft_print_cnts();
4100e675 159 exit(KSFT_XFAIL);
7fb2c3ea 160}
b6a4b66d 161
7fb2c3ea
SK
162static inline int ksft_exit_xpass(void)
163{
b6a4b66d 164 ksft_print_cnts();
4100e675 165 exit(KSFT_XPASS);
7fb2c3ea 166}
b6a4b66d 167
151b2732 168static inline int ksft_exit_skip(const char *msg, ...)
7fb2c3ea 169{
151b2732
PE
170 if (msg) {
171 va_list args;
172
173 va_start(args, msg);
174 printf("1..%d # Skipped: ", ksft_test_num());
175 vprintf(msg, args);
176 va_end(args);
177 } else {
54f57baa 178 ksft_print_cnts();
151b2732 179 }
4100e675 180 exit(KSFT_SKIP);
7fb2c3ea
SK
181}
182
183#endif /* __KSELFTEST_H */
This page took 0.26216 seconds and 4 git commands to generate.