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