]> git.saurik.com Git - apple/xnu.git/blame - osfmk/tests/ktest.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / tests / ktest.h
CommitLineData
d9a64523
A
1/*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _TESTS_KTEST_H
30#define _TESTS_KTEST_H
31
32/* Symbol name prefix */
33#define T_SYM(sym) ktest_ ## sym
34
35#include <stdarg.h>
36
37extern unsigned int T_SYM(current_line);
38extern const char * T_SYM(current_file);
39extern const char * T_SYM(current_func);
40extern int T_SYM(testcase_mode);
41extern int T_SYM(testcase_result);
42extern int T_SYM(test_result);
43extern int T_SYM(quiet);
44
45void T_SYM(start)(void);
46void T_SYM(finish)(void);
47void T_SYM(testbegin)(const char * test_name);
48void T_SYM(testend)(void);
49void T_SYM(testskip)(const char * msg, ...);
50void T_SYM(testcase)(int expr);
51void T_SYM(log)(const char * msg, ...);
52void T_SYM(perf)(const char * metric, const char * unit, double value, const char * desc);
53void T_SYM(update_test_result_state)(void);
54void T_SYM(assertion_check)(void);
55
56void T_SYM(set_current_msg)(const char * msg, ...);
57void T_SYM(set_current_expr)(const char * expr_fmt, ...);
58void T_SYM(set_current_var)(const char * name, const char * value_fmt, ...);
59
60typedef union {
0a7de745
A
61 char _char;
62 unsigned char _uchar;
d9a64523 63
0a7de745
A
64 short _short;
65 unsigned short _ushort;
d9a64523 66
0a7de745
A
67 int _int;
68 unsigned int _uint;
d9a64523 69
0a7de745
A
70 long _long;
71 unsigned long _ulong;
d9a64523 72
0a7de745
A
73 long long _llong;
74 unsigned long long _ullong;
d9a64523 75
0a7de745 76 float _float;
d9a64523 77
0a7de745 78 double _double;
d9a64523 79
0a7de745 80 long double _ldouble;
d9a64523 81
0a7de745 82 void* _ptr;
d9a64523
A
83} T_SYM(temp);
84
85extern T_SYM(temp) T_SYM(temp1), T_SYM(temp2), T_SYM(temp3);
86
87#define T_SUCCESS 1
88#define T_FAILURE 0
89
90/* Testcase modes */
91#define T_MAIN 0
92#define T_SETUP 1
93
94/* Testcase result states */
95#define T_RESULT_PASS 0
96#define T_RESULT_FAIL 1
97#define T_RESULT_UXPASS 2
98#define T_RESULT_XFAIL 3
99
100/* Test result states */
101#define T_STATE_UNRESOLVED 0
102#define T_STATE_PASS 1
103#define T_STATE_FAIL 2
104#define T_STATE_SETUPFAIL 3
105
106/*
107 * Helpers
108 */
109
110#define T_TOSTRING_HELPER(x) #x
111#define T_TOSTRING(x) T_TOSTRING_HELPER(x)
112
113#define T_SAVEINFO do {\
114 T_SYM(current_line) = __LINE__;\
115 T_SYM(current_func) = (const char *)__func__;\
116 T_SYM(current_file) = (const char *)__FILE__;\
117} while(0)
118
119#define T_SET_AUX_VARS do {\
0a7de745 120 /* Only used in userspace lib for now */ \
d9a64523
A
121} while(0)
122
123#define T_ASSERTION_CHECK do {\
124 T_SYM(assertion_check)();\
125} while(0)
126
127#define T_EXPECT_BLOCK2(type, fmt, cmp, lhs, rhs, msg, ...) do {\
128 T_SAVEINFO;\
129 T_SYM(temp1).type = (lhs);\
130 T_SYM(temp2).type = (rhs);\
131 T_SYM(set_current_expr)(T_TOSTRING(lhs) " "\
0a7de745
A
132 T_TOSTRING(cmp) " "\
133 T_TOSTRING(rhs));\
d9a64523
A
134 T_SYM(set_current_var)(T_TOSTRING(lhs), fmt, T_SYM(temp1).type);\
135 T_SYM(set_current_var)(T_TOSTRING(rhs), fmt, T_SYM(temp2).type);\
136 T_SET_AUX_VARS;\
137 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
138 T_SYM(testcase)(T_SYM(temp1).type cmp T_SYM(temp2).type);\
139} while(0)
140
141#define T_ASSERT_BLOCK2(type, fmt, cmp, lhs, rhs, msg, ...) do {\
142 T_EXPECT_BLOCK2(type, fmt, cmp, lhs, rhs, msg, ## __VA_ARGS__);\
143 T_ASSERTION_CHECK;\
144} while(0)
145
146/*
147 * Core functions
148 */
149
150/* Denotes start of testing. All prior output is ignored. */
151#define T_START do {\
152 T_SAVEINFO;\
153 T_SYM(start)();\
154} while(0)
155
156/* Denotes end of testing. All subsequent output is ignored. */
157#define T_FINISH do {\
158 T_SAVEINFO;\
159 T_SYM(finish)();\
160} while(0)
161
162/* Denotes beginning of a test. */
163#define T_BEGIN(name) do {\
164 T_SAVEINFO;\
165 T_SYM(testbegin)(name);\
166} while(0)
167
168/* Denotes end of current test. */
169#define T_END do {\
170 T_SAVEINFO;\
171 T_SYM(testend)();\
172} while(0)
173
174/* Denotes beginning of a setup section of the current test. */
175#define T_SETUPBEGIN do {\
176 T_SYM(testcase_mode) = T_SETUP;\
177} while(0)
178
179/* Denotes end of the current setup section of the current test. */
180#define T_SETUPEND do {\
181 T_SYM(testcase_mode) = T_MAIN;\
182} while(0)
183
184/* Denotes end of current test because test was skipped. */
185#define T_SKIP(msg, ...) do {\
186 T_SAVEINFO;\
187 T_SYM(testskip)(msg, ## __VA_ARGS__);\
188} while(0)
189
190/* Returns result of latest testrun. */
191#define T_TESTRESULT (T_SYM(test_result))
192
193/* Return result of latest testcase. */
194#define T_TESTCASERESULT (T_SYM(testcase_result))
195
196/* Flags the next testcase as expected failure. */
197#define T_EXPECTFAIL do {\
198 T_SYM(expectfail) = 1;\
199} while(0)
200
201/* Only emit output for next testcase if it is a FAIL or UXPASS. */
202#define T_QUIET do {\
203 T_SYM(quiet) = 1;\
204} while(0)
205
206/* Logs a message. */
207#define T_LOG(msg, ...) do {\
208 T_SAVEINFO;\
209 T_SYM(log)(msg, ## __VA_ARGS__);\
210} while(0)
211
212/* Explicit pass. */
213#define T_PASS(msg, ...) do {\
214 T_SAVEINFO;\
215 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
216 T_SYM(testcase)(T_SUCCESS);\
217} while(0)
218
219/* Explicit fail. */
220#define T_FAIL(msg, ...) do {\
221 T_SAVEINFO;\
222 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
223 T_SYM(testcase)(T_FAILURE);\
224} while(0)
225
226/* Explicit assert fail. */
227#define T_ASSERT_FAIL(msg, ...) do {\
228 T_SAVEINFO;\
229 T_SET_AUX_VARS;\
230 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
231 T_SYM(testcase)(T_FAILURE);\
232 T_SYM(assertion_fail)();\
233} while(0)
234
235/* Generic expect. */
236#define T_EXPECT(expr, msg, ...) do {\
237 T_SAVEINFO;\
238 T_SYM(temp1)._int = (int)(!!(expr));\
239 T_SYM(set_current_expr)(T_TOSTRING(expr));\
240 T_SET_AUX_VARS;\
241 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
242 T_SYM(testcase)(T_SYM(temp1)._int);\
243} while(0)
244
245/* Generic assert. */
246#define T_ASSERT(expr, msg, ...) do {\
247 T_EXPECT(expr, msg, ## __VA_ARGS__);\
248 T_ASSERTION_CHECK;\
249} while(0)
250
251/*
252 * Convenience functions
253 */
254
255/* null */
256
257#define T_EXPECT_NOTNULL(expr, msg, ...) do {\
258 T_SAVEINFO;\
259 T_SYM(temp1)._int = (int)(!!(expr));\
260 T_SYM(set_current_expr)(T_TOSTRING(expr) " != NULL");\
261 T_SYM(set_current_var)(T_TOSTRING(expr),\
0a7de745
A
262 "%s",\
263 T_SYM(temp1)._int ? "<NOTNULL>" : "NULL");\
d9a64523
A
264 T_SET_AUX_VARS;\
265 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
266 T_SYM(testcase)(T_SYM(temp1)._int);\
267} while(0)
268
269#define T_EXPECT_NULL(expr, msg, ...) do {\
270 T_SAVEINFO;\
271 T_SYM(temp1)._int = (int)(!(expr));\
272 T_SYM(set_current_expr)(T_TOSTRING(expr) " == NULL");\
273 T_SYM(set_current_var)(T_TOSTRING(expr),\
0a7de745
A
274 "%s",\
275 T_SYM(temp1)._int ? "NULL" : "<NOTNULL>");\
d9a64523
A
276 T_SET_AUX_VARS;\
277 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
278 T_SYM(testcase)(T_SYM(temp1)._int);\
279} while(0)
280
281#define T_ASSERT_NOTNULL(expr, msg, ...) do {\
282 T_EXPECT_NOTNULL(expr, msg, ## __VA_ARGS__);\
283 T_ASSERTION_CHECK;\
284} while(0)
285
286#define T_ASSERT_NULL(expr, msg, ...) do {\
287 T_EXPECT_NULL(expr, msg, ## __VA_ARGS__);\
288 T_ASSERTION_CHECK;\
289} while(0)
290
291/* string */
292
293// TODO: check/truncate inputs
294#define T_EXPECT_EQ_STR(lhs, rhs, msg, ...) do {\
295 T_SAVEINFO;\
296 T_SYM(temp1)._ptr = (lhs);\
297 T_SYM(temp2)._ptr = (rhs);\
298 T_SYM(set_current_expr)(T_TOSTRING(lhs) " == " T_TOSTRING(rhs));\
299 T_SYM(set_current_var)(T_TOSTRING(lhs), "%s", T_SYM(temp1)._ptr);\
300 T_SYM(set_current_var)(T_TOSTRING(rhs), "%s", T_SYM(temp2)._ptr);\
301 T_SET_AUX_VARS;\
302 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
303 T_SYM(testcase)(strcmp(T_SYM(temp1)._ptr, T_SYM(temp2)._ptr) == 0);\
304} while(0)
305
306#define T_EXPECT_NE_STR(lhs, rhs, msg, ...) do {\
307 T_SAVEINFO;\
308 T_SYM(temp1)._ptr = (lhs);\
309 T_SYM(temp2)._ptr = (rhs);\
310 T_SYM(set_current_expr)(T_TOSTRING(lhs) " == " T_TOSTRING(rhs));\
311 T_SYM(set_current_var)(T_TOSTRING(lhs), "%s", T_SYM(temp1)._ptr);\
312 T_SYM(set_current_var)(T_TOSTRING(rhs), "%s", T_SYM(temp2)._ptr);\
313 T_SET_AUX_VARS;\
314 T_SYM(set_current_msg)(msg, ## __VA_ARGS__);\
315 T_SYM(testcase)(strcmp(T_SYM(temp1)._ptr, T_SYM(temp2)._ptr) != 0);\
316} while(0)
317
318#define T_ASSERT_EQ_STR(lhs, rhs, msg, ...) do {\
319 T_EXPECT_EQ_STR(lhs, rhs, msg, # __VA_ARGS__);\
320 T_ASSERTION_CHECK;\
321} while(0)
322
323#define T_ASSERT_NE_STR(lhs, rhs, msg, ...) do {\
324 T_EXPECT_NE_STR(lhs, rhs, msg, # __VA_ARGS__);\
325 T_ASSERTION_CHECK;\
326} while(0)
327
328/* char */
329
0a7de745 330#define T_EXPECT_EQ_CHAR(lhs, rhs, msg, ...) \
d9a64523 331 T_EXPECT_BLOCK2(_char, "%c", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 332#define T_EXPECT_NE_CHAR(lhs, rhs, msg, ...) \
d9a64523 333 T_EXPECT_BLOCK2(_char, "%c", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 334#define T_EXPECT_LT_CHAR(lhs, rhs, msg, ...) \
d9a64523 335 T_EXPECT_BLOCK2(_char, "%c", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 336#define T_EXPECT_GT_CHAR(lhs, rhs, msg, ...) \
d9a64523 337 T_EXPECT_BLOCK2(_char, "%c", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 338#define T_EXPECT_LE_CHAR(lhs, rhs, msg, ...) \
d9a64523 339 T_EXPECT_BLOCK2(_char, "%c", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 340#define T_EXPECT_GE_CHAR(lhs, rhs, msg, ...) \
d9a64523
A
341 T_EXPECT_BLOCK2(_char, "%c", >=, lhs, rhs, msg, ## __VA_ARGS__)
342
0a7de745 343#define T_ASSERT_EQ_CHAR(lhs, rhs, msg, ...) \
d9a64523 344 T_ASSERT_BLOCK2(_char, "%c", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 345#define T_ASSERT_NE_CHAR(lhs, rhs, msg, ...) \
d9a64523 346 T_ASSERT_BLOCK2(_char, "%c", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 347#define T_ASSERT_LT_CHAR(lhs, rhs, msg, ...) \
d9a64523 348 T_ASSERT_BLOCK2(_char, "%c", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 349#define T_ASSERT_GT_CHAR(lhs, rhs, msg, ...) \
d9a64523 350 T_ASSERT_BLOCK2(_char, "%c", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 351#define T_ASSERT_LE_CHAR(lhs, rhs, msg, ...) \
d9a64523 352 T_ASSERT_BLOCK2(_char, "%c", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 353#define T_ASSERT_GE_CHAR(lhs, rhs, msg, ...) \
d9a64523
A
354 T_ASSERT_BLOCK2(_char, "%c", >=, lhs, rhs, msg, ## __VA_ARGS__)
355
356/* unsigned char */
357
0a7de745 358#define T_EXPECT_EQ_UCHAR(lhs, rhs, msg, ...) \
d9a64523 359 T_EXPECT_BLOCK2(_uchar, "%c", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 360#define T_EXPECT_NE_UCHAR(lhs, rhs, msg, ...) \
d9a64523 361 T_EXPECT_BLOCK2(_uchar, "%c", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 362#define T_EXPECT_LT_UCHAR(lhs, rhs, msg, ...) \
d9a64523 363 T_EXPECT_BLOCK2(_uchar, "%c", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 364#define T_EXPECT_GT_UCHAR(lhs, rhs, msg, ...) \
d9a64523 365 T_EXPECT_BLOCK2(_uchar, "%c", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 366#define T_EXPECT_LE_UCHAR(lhs, rhs, msg, ...) \
d9a64523 367 T_EXPECT_BLOCK2(_uchar, "%c", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 368#define T_EXPECT_GE_UCHAR(lhs, rhs, msg, ...) \
d9a64523
A
369 T_EXPECT_BLOCK2(_uchar, "%c", >=, lhs, rhs, msg, ## __VA_ARGS__)
370
0a7de745 371#define T_ASSERT_EQ_UCHAR(lhs, rhs, msg, ...) \
d9a64523 372 T_ASSERT_BLOCK2(_uchar, "%c", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 373#define T_ASSERT_NE_UCHAR(lhs, rhs, msg, ...) \
d9a64523 374 T_ASSERT_BLOCK2(_uchar, "%c", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 375#define T_ASSERT_LT_UCHAR(lhs, rhs, msg, ...) \
d9a64523 376 T_ASSERT_BLOCK2(_uchar, "%c", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 377#define T_ASSERT_GT_UCHAR(lhs, rhs, msg, ...) \
d9a64523 378 T_ASSERT_BLOCK2(_uchar, "%c", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 379#define T_ASSERT_LE_UCHAR(lhs, rhs, msg, ...) \
d9a64523 380 T_ASSERT_BLOCK2(_uchar, "%c", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 381#define T_ASSERT_GE_UCHAR(lhs, rhs, msg, ...) \
d9a64523
A
382 T_ASSERT_BLOCK2(_uchar, "%c", >=, lhs, rhs, msg, ## __VA_ARGS__)
383
384/* short */
385
0a7de745 386#define T_EXPECT_EQ_SHORT(lhs, rhs, msg, ...) \
d9a64523 387 T_EXPECT_BLOCK2(_short, "%hi", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 388#define T_EXPECT_NE_SHORT(lhs, rhs, msg, ...) \
d9a64523 389 T_EXPECT_BLOCK2(_short, "%hi", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 390#define T_EXPECT_LT_SHORT(lhs, rhs, msg, ...) \
d9a64523 391 T_EXPECT_BLOCK2(_short, "%hi", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 392#define T_EXPECT_GT_SHORT(lhs, rhs, msg, ...) \
d9a64523 393 T_EXPECT_BLOCK2(_short, "%hi", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 394#define T_EXPECT_LE_SHORT(lhs, rhs, msg, ...) \
d9a64523 395 T_EXPECT_BLOCK2(_short, "%hi", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 396#define T_EXPECT_GE_SHORT(lhs, rhs, msg, ...) \
d9a64523
A
397 T_EXPECT_BLOCK2(_short, "%hi", >=, lhs, rhs, msg, ## __VA_ARGS__)
398
0a7de745 399#define T_ASSERT_EQ_SHORT(lhs, rhs, msg, ...) \
d9a64523 400 T_ASSERT_BLOCK2(_short, "%hi", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 401#define T_ASSERT_NE_SHORT(lhs, rhs, msg, ...) \
d9a64523 402 T_ASSERT_BLOCK2(_short, "%hi", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 403#define T_ASSERT_LT_SHORT(lhs, rhs, msg, ...) \
d9a64523 404 T_ASSERT_BLOCK2(_short, "%hi", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 405#define T_ASSERT_GT_SHORT(lhs, rhs, msg, ...) \
d9a64523 406 T_ASSERT_BLOCK2(_short, "%hi", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 407#define T_ASSERT_LE_SHORT(lhs, rhs, msg, ...) \
d9a64523 408 T_ASSERT_BLOCK2(_short, "%hi", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 409#define T_ASSERT_GE_SHORT(lhs, rhs, msg, ...) \
d9a64523
A
410 T_ASSERT_BLOCK2(_short, "%hi", >=, lhs, rhs, msg, ## __VA_ARGS__)
411
412/* unsigned short */
413
0a7de745 414#define T_EXPECT_EQ_USHORT(lhs, rhs, msg, ...) \
d9a64523 415 T_EXPECT_BLOCK2(_ushort, "%hu", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 416#define T_EXPECT_NE_USHORT(lhs, rhs, msg, ...) \
d9a64523 417 T_EXPECT_BLOCK2(_ushort, "%hu", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 418#define T_EXPECT_LT_USHORT(lhs, rhs, msg, ...) \
d9a64523 419 T_EXPECT_BLOCK2(_ushort, "%hu", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 420#define T_EXPECT_GT_USHORT(lhs, rhs, msg, ...) \
d9a64523 421 T_EXPECT_BLOCK2(_ushort, "%hu", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 422#define T_EXPECT_LE_USHORT(lhs, rhs, msg, ...) \
d9a64523 423 T_EXPECT_BLOCK2(_ushort, "%hu", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 424#define T_EXPECT_GE_USHORT(lhs, rhs, msg, ...) \
d9a64523
A
425 T_EXPECT_BLOCK2(_ushort, "%hu", >=, lhs, rhs, msg, ## __VA_ARGS__)
426
0a7de745 427#define T_ASSERT_EQ_USHORT(lhs, rhs, msg, ...) \
d9a64523 428 T_ASSERT_BLOCK2(_ushort, "%hu", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 429#define T_ASSERT_NE_USHORT(lhs, rhs, msg, ...) \
d9a64523 430 T_ASSERT_BLOCK2(_ushort, "%hu", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 431#define T_ASSERT_LT_USHORT(lhs, rhs, msg, ...) \
d9a64523 432 T_ASSERT_BLOCK2(_ushort, "%hu", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 433#define T_ASSERT_GT_USHORT(lhs, rhs, msg, ...) \
d9a64523 434 T_ASSERT_BLOCK2(_ushort, "%hu", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 435#define T_ASSERT_LE_USHORT(lhs, rhs, msg, ...) \
d9a64523 436 T_ASSERT_BLOCK2(_ushort, "%hu", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 437#define T_ASSERT_GE_USHORT(lhs, rhs, msg, ...) \
d9a64523
A
438 T_ASSERT_BLOCK2(_ushort, "%hu", >=, lhs, rhs, msg, ## __VA_ARGS__)
439
440/* int */
441
0a7de745 442#define T_EXPECT_EQ_INT(lhs, rhs, msg, ...) \
d9a64523 443 T_EXPECT_BLOCK2(_int, "%d", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 444#define T_EXPECT_NE_INT(lhs, rhs, msg, ...) \
d9a64523 445 T_EXPECT_BLOCK2(_int, "%d", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 446#define T_EXPECT_LT_INT(lhs, rhs, msg, ...) \
d9a64523 447 T_EXPECT_BLOCK2(_int, "%d", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 448#define T_EXPECT_GT_INT(lhs, rhs, msg, ...) \
d9a64523 449 T_EXPECT_BLOCK2(_int, "%d", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 450#define T_EXPECT_LE_INT(lhs, rhs, msg, ...) \
d9a64523 451 T_EXPECT_BLOCK2(_int, "%d", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 452#define T_EXPECT_GE_INT(lhs, rhs, msg, ...) \
d9a64523
A
453 T_EXPECT_BLOCK2(_int, "%d", >=, lhs, rhs, msg, ## __VA_ARGS__)
454
0a7de745 455#define T_ASSERT_EQ_INT(lhs, rhs, msg, ...) \
d9a64523 456 T_ASSERT_BLOCK2(_int, "%d", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 457#define T_ASSERT_NE_INT(lhs, rhs, msg, ...) \
d9a64523 458 T_ASSERT_BLOCK2(_int, "%d", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 459#define T_ASSERT_LT_INT(lhs, rhs, msg, ...) \
d9a64523 460 T_ASSERT_BLOCK2(_int, "%d", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 461#define T_ASSERT_GT_INT(lhs, rhs, msg, ...) \
d9a64523 462 T_ASSERT_BLOCK2(_int, "%d", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 463#define T_ASSERT_LE_INT(lhs, rhs, msg, ...) \
d9a64523 464 T_ASSERT_BLOCK2(_int, "%d", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 465#define T_ASSERT_GE_INT(lhs, rhs, msg, ...) \
d9a64523
A
466 T_ASSERT_BLOCK2(_int, "%d", >=, lhs, rhs, msg, ## __VA_ARGS__)
467
468/* unsigned int */
469
0a7de745 470#define T_EXPECT_EQ_UINT(lhs, rhs, msg, ...) \
d9a64523 471 T_EXPECT_BLOCK2(_uint, "%u", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 472#define T_EXPECT_NE_UINT(lhs, rhs, msg, ...) \
d9a64523 473 T_EXPECT_BLOCK2(_uint, "%u", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 474#define T_EXPECT_LT_UINT(lhs, rhs, msg, ...) \
d9a64523 475 T_EXPECT_BLOCK2(_uint, "%u", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 476#define T_EXPECT_GT_UINT(lhs, rhs, msg, ...) \
d9a64523 477 T_EXPECT_BLOCK2(_uint, "%u", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 478#define T_EXPECT_LE_UINT(lhs, rhs, msg, ...) \
d9a64523 479 T_EXPECT_BLOCK2(_uint, "%u", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 480#define T_EXPECT_GE_UINT(lhs, rhs, msg, ...) \
d9a64523
A
481 T_EXPECT_BLOCK2(_uint, "%u", >=, lhs, rhs, msg, ## __VA_ARGS__)
482
0a7de745 483#define T_ASSERT_EQ_UINT(lhs, rhs, msg, ...) \
d9a64523 484 T_ASSERT_BLOCK2(_uint, "%u", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 485#define T_ASSERT_NE_UINT(lhs, rhs, msg, ...) \
d9a64523 486 T_ASSERT_BLOCK2(_uint, "%u", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 487#define T_ASSERT_LT_UINT(lhs, rhs, msg, ...) \
d9a64523 488 T_ASSERT_BLOCK2(_uint, "%u", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 489#define T_ASSERT_GT_UINT(lhs, rhs, msg, ...) \
d9a64523 490 T_ASSERT_BLOCK2(_uint, "%u", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 491#define T_ASSERT_LE_UINT(lhs, rhs, msg, ...) \
d9a64523 492 T_ASSERT_BLOCK2(_uint, "%u", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 493#define T_ASSERT_GE_UINT(lhs, rhs, msg, ...) \
d9a64523
A
494 T_ASSERT_BLOCK2(_uint, "%u", >=, lhs, rhs, msg, ## __VA_ARGS__)
495
496/* long */
497
0a7de745 498#define T_EXPECT_EQ_LONG(lhs, rhs, msg, ...) \
d9a64523 499 T_EXPECT_BLOCK2(_long, "%li", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 500#define T_EXPECT_NE_LONG(lhs, rhs, msg, ...) \
d9a64523 501 T_EXPECT_BLOCK2(_long, "%li", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 502#define T_EXPECT_LT_LONG(lhs, rhs, msg, ...) \
d9a64523 503 T_EXPECT_BLOCK2(_long, "%li", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 504#define T_EXPECT_GT_LONG(lhs, rhs, msg, ...) \
d9a64523 505 T_EXPECT_BLOCK2(_long, "%li", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 506#define T_EXPECT_LE_LONG(lhs, rhs, msg, ...) \
d9a64523 507 T_EXPECT_BLOCK2(_long, "%li", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 508#define T_EXPECT_GE_LONG(lhs, rhs, msg, ...) \
d9a64523
A
509 T_EXPECT_BLOCK2(_long, "%li", >=, lhs, rhs, msg, ## __VA_ARGS__)
510
0a7de745 511#define T_ASSERT_EQ_LONG(lhs, rhs, msg, ...) \
d9a64523 512 T_ASSERT_BLOCK2(_long, "%li", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 513#define T_ASSERT_NE_LONG(lhs, rhs, msg, ...) \
d9a64523 514 T_ASSERT_BLOCK2(_long, "%li", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 515#define T_ASSERT_LT_LONG(lhs, rhs, msg, ...) \
d9a64523 516 T_ASSERT_BLOCK2(_long, "%li", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 517#define T_ASSERT_GT_LONG(lhs, rhs, msg, ...) \
d9a64523 518 T_ASSERT_BLOCK2(_long, "%li", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 519#define T_ASSERT_LE_LONG(lhs, rhs, msg, ...) \
d9a64523 520 T_ASSERT_BLOCK2(_long, "%li", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 521#define T_ASSERT_GE_LONG(lhs, rhs, msg, ...) \
d9a64523
A
522 T_ASSERT_BLOCK2(_long, "%li", >=, lhs, rhs, msg, ## __VA_ARGS__)
523
524/* unsigned long */
525
0a7de745 526#define T_EXPECT_EQ_ULONG(lhs, rhs, msg, ...) \
d9a64523 527 T_EXPECT_BLOCK2(_ulong, "%lu", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 528#define T_EXPECT_NE_ULONG(lhs, rhs, msg, ...) \
d9a64523 529 T_EXPECT_BLOCK2(_ulong, "%lu", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 530#define T_EXPECT_LT_ULONG(lhs, rhs, msg, ...) \
d9a64523 531 T_EXPECT_BLOCK2(_ulong, "%lu", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 532#define T_EXPECT_GT_ULONG(lhs, rhs, msg, ...) \
d9a64523 533 T_EXPECT_BLOCK2(_ulong, "%lu", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 534#define T_EXPECT_LE_ULONG(lhs, rhs, msg, ...) \
d9a64523 535 T_EXPECT_BLOCK2(_ulong, "%lu", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 536#define T_EXPECT_GE_ULONG(lhs, rhs, msg, ...) \
d9a64523
A
537 T_EXPECT_BLOCK2(_ulong, "%lu", >=, lhs, rhs, msg, ## __VA_ARGS__)
538
0a7de745 539#define T_ASSERT_EQ_ULONG(lhs, rhs, msg, ...) \
d9a64523 540 T_ASSERT_BLOCK2(_ulong, "%lu", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 541#define T_ASSERT_NE_ULONG(lhs, rhs, msg, ...) \
d9a64523 542 T_ASSERT_BLOCK2(_ulong, "%lu", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 543#define T_ASSERT_LT_ULONG(lhs, rhs, msg, ...) \
d9a64523 544 T_ASSERT_BLOCK2(_ulong, "%lu", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 545#define T_ASSERT_GT_ULONG(lhs, rhs, msg, ...) \
d9a64523 546 T_ASSERT_BLOCK2(_ulong, "%lu", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 547#define T_ASSERT_LE_ULONG(lhs, rhs, msg, ...) \
d9a64523 548 T_ASSERT_BLOCK2(_ulong, "%lu", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 549#define T_ASSERT_GE_ULONG(lhs, rhs, msg, ...) \
d9a64523
A
550 T_ASSERT_BLOCK2(_ulong, "%lu", >=, lhs, rhs, msg, ## __VA_ARGS__)
551
552/* long long */
553
0a7de745 554#define T_EXPECT_EQ_LLONG(lhs, rhs, msg, ...) \
d9a64523 555 T_EXPECT_BLOCK2(_llong, "%lli", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 556#define T_EXPECT_NE_LLONG(lhs, rhs, msg, ...) \
d9a64523 557 T_EXPECT_BLOCK2(_llong, "%lli", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 558#define T_EXPECT_LT_LLONG(lhs, rhs, msg, ...) \
d9a64523 559 T_EXPECT_BLOCK2(_llong, "%lli", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 560#define T_EXPECT_GT_LLONG(lhs, rhs, msg, ...) \
d9a64523 561 T_EXPECT_BLOCK2(_llong, "%lli", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 562#define T_EXPECT_LE_LLONG(lhs, rhs, msg, ...) \
d9a64523 563 T_EXPECT_BLOCK2(_llong, "%lli", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 564#define T_EXPECT_GE_LLONG(lhs, rhs, msg, ...) \
d9a64523
A
565 T_EXPECT_BLOCK2(_llong, "%lli", >=, lhs, rhs, msg, ## __VA_ARGS__)
566
0a7de745 567#define T_ASSERT_EQ_LLONG(lhs, rhs, msg, ...) \
d9a64523 568 T_ASSERT_BLOCK2(_llong, "%lli", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 569#define T_ASSERT_NE_LLONG(lhs, rhs, msg, ...) \
d9a64523 570 T_ASSERT_BLOCK2(_llong, "%lli", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 571#define T_ASSERT_LT_LLONG(lhs, rhs, msg, ...) \
d9a64523 572 T_ASSERT_BLOCK2(_llong, "%lli", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 573#define T_ASSERT_GT_LLONG(lhs, rhs, msg, ...) \
d9a64523 574 T_ASSERT_BLOCK2(_llong, "%lli", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 575#define T_ASSERT_LE_LLONG(lhs, rhs, msg, ...) \
d9a64523 576 T_ASSERT_BLOCK2(_llong, "%lli", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 577#define T_ASSERT_GE_LLONG(lhs, rhs, msg, ...) \
d9a64523
A
578 T_ASSERT_BLOCK2(_llong, "%lli", >=, lhs, rhs, msg, ## __VA_ARGS__)
579
580/* unsigned long long */
581
0a7de745 582#define T_EXPECT_EQ_ULLONG(lhs, rhs, msg, ...) \
d9a64523 583 T_EXPECT_BLOCK2(_ullong, "%llu", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 584#define T_EXPECT_NE_ULLONG(lhs, rhs, msg, ...) \
d9a64523 585 T_EXPECT_BLOCK2(_ullong, "%llu", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 586#define T_EXPECT_LT_ULLONG(lhs, rhs, msg, ...) \
d9a64523 587 T_EXPECT_BLOCK2(_ullong, "%llu", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 588#define T_EXPECT_GT_ULLONG(lhs, rhs, msg, ...) \
d9a64523 589 T_EXPECT_BLOCK2(_ullong, "%llu", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 590#define T_EXPECT_LE_ULLONG(lhs, rhs, msg, ...) \
d9a64523 591 T_EXPECT_BLOCK2(_ullong, "%llu", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 592#define T_EXPECT_GE_ULLONG(lhs, rhs, msg, ...) \
d9a64523
A
593 T_EXPECT_BLOCK2(_ullong, "%llu", >=, lhs, rhs, msg, ## __VA_ARGS__)
594
0a7de745 595#define T_ASSERT_EQ_ULLONG(lhs, rhs, msg, ...) \
d9a64523 596 T_ASSERT_BLOCK2(_ullong, "%llu", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 597#define T_ASSERT_NE_ULLONG(lhs, rhs, msg, ...) \
d9a64523 598 T_ASSERT_BLOCK2(_ullong, "%llu", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 599#define T_ASSERT_LT_ULLONG(lhs, rhs, msg, ...) \
d9a64523 600 T_ASSERT_BLOCK2(_ullong, "%llu", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 601#define T_ASSERT_GT_ULLONG(lhs, rhs, msg, ...) \
d9a64523 602 T_ASSERT_BLOCK2(_ullong, "%llu", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 603#define T_ASSERT_LE_ULLONG(lhs, rhs, msg, ...) \
d9a64523 604 T_ASSERT_BLOCK2(_ullong, "%llu", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 605#define T_ASSERT_GE_ULLONG(lhs, rhs, msg, ...) \
d9a64523
A
606 T_ASSERT_BLOCK2(_ullong, "%llu", >=, lhs, rhs, msg, ## __VA_ARGS__)
607
608/* pointer */
609
0a7de745 610#define T_EXPECT_EQ_PTR(lhs, rhs, msg, ...) \
d9a64523 611 T_EXPECT_BLOCK2(_ptr, "%p", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 612#define T_EXPECT_NE_PTR(lhs, rhs, msg, ...) \
d9a64523 613 T_EXPECT_BLOCK2(_ptr, "%p", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 614#define T_EXPECT_LT_PTR(lhs, rhs, msg, ...) \
d9a64523 615 T_EXPECT_BLOCK2(_ptr, "%p", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 616#define T_EXPECT_GT_PTR(lhs, rhs, msg, ...) \
d9a64523 617 T_EXPECT_BLOCK2(_ptr, "%p", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 618#define T_EXPECT_LE_PTR(lhs, rhs, msg, ...) \
d9a64523 619 T_EXPECT_BLOCK2(_ptr, "%p", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 620#define T_EXPECT_GE_PTR(lhs, rhs, msg, ...) \
d9a64523
A
621 T_EXPECT_BLOCK2(_ptr, "%p", >=, lhs, rhs, msg, ## __VA_ARGS__)
622
0a7de745 623#define T_ASSERT_EQ_PTR(lhs, rhs, msg, ...) \
d9a64523 624 T_ASSERT_BLOCK2(_ptr, "%p", ==, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 625#define T_ASSERT_NE_PTR(lhs, rhs, msg, ...) \
d9a64523 626 T_ASSERT_BLOCK2(_ptr, "%p", !=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 627#define T_ASSERT_LT_PTR(lhs, rhs, msg, ...) \
d9a64523 628 T_ASSERT_BLOCK2(_ptr, "%p", <, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 629#define T_ASSERT_GT_PTR(lhs, rhs, msg, ...) \
d9a64523 630 T_ASSERT_BLOCK2(_ptr, "%p", >, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 631#define T_ASSERT_LE_PTR(lhs, rhs, msg, ...) \
d9a64523 632 T_ASSERT_BLOCK2(_ptr, "%p", <=, lhs, rhs, msg, ## __VA_ARGS__)
0a7de745 633#define T_ASSERT_GE_PTR(lhs, rhs, msg, ...) \
d9a64523
A
634 T_ASSERT_BLOCK2(_ptr, "%p", >=, lhs, rhs, msg, ## __VA_ARGS__)
635
636/*
637 * Log a perfdata measurement. For example:
638 * T_PERF("name_of_metric", 3234, "nsec", "time since first test run")
639 */
640#define T_PERF(metric, value, unit, desc) \
641 do { \
0a7de745
A
642 T_SAVEINFO; \
643 T_SYM(perf)(metric, unit, value, desc); \
d9a64523
A
644 } while (0)
645
646#endif /* _TESTS_KTEST_H */