2 * Simple unit test library for driver model
4 * Copyright (c) 2013 Google, Inc
6 * SPDX-License-Identifier: GPL-2.0+
15 * ut_fail() - Record failure of a unit test
18 * @fname: Filename where the error occured
19 * @line: Line number where the error occured
20 * @func: Function name where the error occured
21 * @cond: The condition that failed
23 void ut_fail(struct dm_test_state *dms, const char *fname, int line,
24 const char *func, const char *cond);
27 * ut_failf() - Record failure of a unit test
30 * @fname: Filename where the error occured
31 * @line: Line number where the error occured
32 * @func: Function name where the error occured
33 * @cond: The condition that failed
34 * @fmt: printf() format string for the error, followed by args
36 void ut_failf(struct dm_test_state *dms, const char *fname, int line,
37 const char *func, const char *cond, const char *fmt, ...)
38 __attribute__ ((format (__printf__, 6, 7)));
41 /* Assert that a condition is non-zero */
42 #define ut_assert(cond) \
44 ut_fail(dms, __FILE__, __LINE__, __func__, #cond); \
48 /* Assert that a condition is non-zero, with printf() string */
49 #define ut_assertf(cond, fmt, args...) \
51 ut_failf(dms, __FILE__, __LINE__, __func__, #cond, \
56 /* Assert that two int expressions are equal */
57 #define ut_asserteq(expr1, expr2) { \
58 unsigned int val1 = (expr1), val2 = (expr2); \
61 ut_failf(dms, __FILE__, __LINE__, __func__, \
62 #expr1 " == " #expr2, \
63 "Expected %d, got %d", val1, val2); \
68 /* Assert that two string expressions are equal */
69 #define ut_asserteq_str(expr1, expr2) { \
70 const char *val1 = (expr1), *val2 = (expr2); \
72 if (strcmp(val1, val2)) { \
73 ut_failf(dms, __FILE__, __LINE__, __func__, \
74 #expr1 " = " #expr2, \
75 "Expected \"%s\", got \"%s\"", val1, val2); \
80 /* Assert that two pointers are equal */
81 #define ut_asserteq_ptr(expr1, expr2) { \
82 const void *val1 = (expr1), *val2 = (expr2); \
85 ut_failf(dms, __FILE__, __LINE__, __func__, \
86 #expr1 " = " #expr2, \
87 "Expected %p, got %p", val1, val2); \
92 /* Assert that an operation succeeds (returns 0) */
93 #define ut_assertok(cond) ut_asserteq(0, cond)