Merge tag 'dmaengine-fix-4.17-rc6' of git://git.infradead.org/users/vkoul/slave-dma
[linux-2.6-block.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 <shuahkh@osg.samsung.com>
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
11867a77
SK
22/* Treat skip as pass */
23#define KSFT_SKIP KSFT_PASS
4100e675 24
7fb2c3ea
SK
25/* counters */
26struct 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;
c0bb2cf4 32 unsigned int ksft_error;
7fb2c3ea
SK
33};
34
35static struct ksft_count ksft_cnt;
36
b6a4b66d
PE
37static inline int ksft_test_num(void)
38{
39 return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
40 ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
c0bb2cf4 41 ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
b6a4b66d
PE
42}
43
7fb2c3ea
SK
44static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
45static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
46static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
47static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
48static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
c0bb2cf4 49static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
7fb2c3ea 50
1d3ee8be
SK
51static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
52static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
53static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
54static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
55static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
c0bb2cf4 56static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
1d3ee8be 57
b6a4b66d
PE
58static inline void ksft_print_header(void)
59{
10f531f6
SK
60 if (!(getenv("KSFT_TAP_LEVEL")))
61 printf("TAP version 13\n");
b6a4b66d
PE
62}
63
7fb2c3ea
SK
64static inline void ksft_print_cnts(void)
65{
c0bb2cf4 66 printf("Pass %d Fail %d Xfail %d Xpass %d Skip %d Error %d\n",
1d3ee8be
SK
67 ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
68 ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
c0bb2cf4 69 ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
b6a4b66d
PE
70 printf("1..%d\n", ksft_test_num());
71}
72
ab52a484
PE
73static inline void ksft_print_msg(const char *msg, ...)
74{
75 va_list args;
76
77 va_start(args, msg);
78 printf("# ");
79 vprintf(msg, args);
80 va_end(args);
81}
82
151b2732 83static inline void ksft_test_result_pass(const char *msg, ...)
b6a4b66d 84{
151b2732
PE
85 va_list args;
86
b6a4b66d 87 ksft_cnt.ksft_pass++;
151b2732
PE
88
89 va_start(args, msg);
90 printf("ok %d ", ksft_test_num());
91 vprintf(msg, args);
92 va_end(args);
b6a4b66d
PE
93}
94
151b2732 95static inline void ksft_test_result_fail(const char *msg, ...)
b6a4b66d 96{
151b2732
PE
97 va_list args;
98
b6a4b66d 99 ksft_cnt.ksft_fail++;
151b2732
PE
100
101 va_start(args, msg);
102 printf("not ok %d ", ksft_test_num());
103 vprintf(msg, args);
104 va_end(args);
b6a4b66d
PE
105}
106
151b2732 107static inline void ksft_test_result_skip(const char *msg, ...)
b6a4b66d 108{
151b2732
PE
109 va_list args;
110
b6a4b66d 111 ksft_cnt.ksft_xskip++;
151b2732
PE
112
113 va_start(args, msg);
114 printf("ok %d # skip ", ksft_test_num());
115 vprintf(msg, args);
116 va_end(args);
7fb2c3ea
SK
117}
118
c0bb2cf4
SK
119static inline void ksft_test_result_error(const char *msg, ...)
120{
121 va_list args;
122
123 ksft_cnt.ksft_error++;
124
125 va_start(args, msg);
126 printf("not ok %d # error ", ksft_test_num());
127 vprintf(msg, args);
128 va_end(args);
129}
130
7fb2c3ea
SK
131static inline int ksft_exit_pass(void)
132{
b6a4b66d 133 ksft_print_cnts();
4100e675 134 exit(KSFT_PASS);
7fb2c3ea 135}
b6a4b66d 136
7fb2c3ea
SK
137static inline int ksft_exit_fail(void)
138{
b6a4b66d
PE
139 printf("Bail out!\n");
140 ksft_print_cnts();
4100e675 141 exit(KSFT_FAIL);
7fb2c3ea 142}
b6a4b66d 143
151b2732 144static inline int ksft_exit_fail_msg(const char *msg, ...)
b6a4b66d 145{
151b2732
PE
146 va_list args;
147
148 va_start(args, msg);
149 printf("Bail out! ");
150 vprintf(msg, args);
151 va_end(args);
152
b6a4b66d
PE
153 ksft_print_cnts();
154 exit(KSFT_FAIL);
155}
156
7fb2c3ea
SK
157static inline int ksft_exit_xfail(void)
158{
b6a4b66d 159 ksft_print_cnts();
4100e675 160 exit(KSFT_XFAIL);
7fb2c3ea 161}
b6a4b66d 162
7fb2c3ea
SK
163static inline int ksft_exit_xpass(void)
164{
b6a4b66d 165 ksft_print_cnts();
4100e675 166 exit(KSFT_XPASS);
7fb2c3ea 167}
b6a4b66d 168
151b2732 169static inline int ksft_exit_skip(const char *msg, ...)
7fb2c3ea 170{
151b2732
PE
171 if (msg) {
172 va_list args;
173
174 va_start(args, msg);
175 printf("1..%d # Skipped: ", ksft_test_num());
176 vprintf(msg, args);
177 va_end(args);
178 } else {
54f57baa 179 ksft_print_cnts();
151b2732 180 }
4100e675 181 exit(KSFT_SKIP);
7fb2c3ea
SK
182}
183
184#endif /* __KSELFTEST_H */