13#ifndef ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
14#define ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
33#if CONFIG_ZTEST_ASSERT_VERBOSE == 0
35static inline bool z_zassert_(
bool cond,
const char *file,
int line)
47#define z_zassert(cond, default_msg, file, line, func, msg, ...) z_zassert_(cond, file, line)
49static inline bool z_zassume_(
bool cond,
const char *file,
int line)
61#define z_zassume(cond, default_msg, file, line, func, msg, ...) z_zassume_(cond, file, line)
63static inline bool z_zexpect_(
bool cond,
const char *file,
int line)
75#define z_zexpect(cond, default_msg, file, line, func, msg, ...) z_zexpect_(cond, file, line)
79static inline __printf_like(6, 7)
bool z_zassert(
bool cond, const
char *default_msg,
80 const
char *file,
int line, const
char *func,
87 PRINT_DATA(
"\n Assertion failed at %s:%d: %s: %s\n",
95#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
97 PRINT_DATA(
"\n Assertion succeeded at %s:%d (%s)\n",
104static inline __printf_like(6, 7)
bool z_zassume(
bool cond, const
char *default_msg,
105 const
char *file,
int line, const
char *func,
106 const
char *msg, ...)
111 va_start(vargs, msg);
112 PRINT_DATA(
"\n Assumption failed at %s:%d: %s: %s\n",
120#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
122 PRINT_DATA(
"\n Assumption succeeded at %s:%d (%s)\n",
129static inline __printf_like(6, 7)
bool z_zexpect(
bool cond, const
char *default_msg,
130 const
char *file,
int line, const
char *func,
131 const
char *msg, ...)
136 va_start(vargs, msg);
137 PRINT_DATA(
"\n Expectation failed at %s:%d: %s: %s\n",
145#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
147 PRINT_DATA(
"\n Expectation succeeded at %s:%d (%s)\n",
179#define _zassert_base(cond, default_msg, msg, ...) \
181 bool _msg = (msg != NULL); \
183 z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
184 __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
188 COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
193#define _zassert_va(cond, default_msg, msg, ...) \
194 _zassert_base(cond, default_msg, msg, ##__VA_ARGS__)
196#define zassert(cond, default_msg, ...) \
197 _zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
217#define _zassume_base(cond, default_msg, msg, ...) \
219 bool _msg = (msg != NULL); \
221 z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
222 __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
226 COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
231#define _zassume_va(cond, default_msg, msg, ...) \
232 _zassume_base(cond, default_msg, msg, ##__VA_ARGS__)
234#define zassume(cond, default_msg, ...) \
235 _zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
247#define _zexpect_base(cond, default_msg, msg, ...) \
249 bool _msg = (msg != NULL); \
251 z_zexpect(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
252 __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
256 COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
261#define _zexpect_va(cond, default_msg, msg, ...) \
262 _zexpect_base(cond, default_msg, msg, ##__VA_ARGS__)
264#define zexpect(cond, default_msg, ...) \
265 _zexpect_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
271#define zassert_unreachable(...) zassert(0, "Reached unreachable code", ##__VA_ARGS__)
278#define zassert_true(cond, ...) zassert(cond, #cond " is false", ##__VA_ARGS__)
285#define zassert_false(cond, ...) zassert(!(cond), #cond " is true", ##__VA_ARGS__)
292#define zassert_ok(cond, ...) zassert(!(cond), #cond " is non-zero", ##__VA_ARGS__)
299#define zassert_not_ok(cond, ...) zassert(!!(cond), #cond " is zero", ##__VA_ARGS__)
306#define zassert_is_null(ptr, ...) zassert((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
313#define zassert_not_null(ptr, ...) zassert((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
324#define zassert_equal(a, b, ...) zassert((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
335#define zassert_not_equal(a, b, ...) zassert((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
346#define zassert_equal_ptr(a, b, ...) \
347 zassert((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
357#define zassert_within(a, b, d, ...) \
358 zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
370#define zassert_between_inclusive(a, l, u, ...) \
371 zassert(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
385#define zassert_mem_equal(...) zassert_mem_equal__(__VA_ARGS__)
398#define zassert_mem_equal__(buf, exp, size, ...) \
399 zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
408#define zassert_str_equal(s1, s2, ...) \
409 zassert(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
432#define zassume_true(cond, ...) zassume(cond, #cond " is false", ##__VA_ARGS__)
442#define zassume_false(cond, ...) zassume(!(cond), #cond " is true", ##__VA_ARGS__)
452#define zassume_ok(cond, ...) zassume(!(cond), #cond " is non-zero", ##__VA_ARGS__)
462#define zassume_not_ok(cond, ...) zassume(!!(cond), #cond " is zero", ##__VA_ARGS__)
472#define zassume_is_null(ptr, ...) zassume((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
482#define zassume_not_null(ptr, ...) zassume((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
494#define zassume_equal(a, b, ...) zassume((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
506#define zassume_not_equal(a, b, ...) zassume((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
518#define zassume_equal_ptr(a, b, ...) \
519 zassume((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
531#define zassume_within(a, b, d, ...) \
532 zassume(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
546#define zassume_between_inclusive(a, l, u, ...) \
547 zassume(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
561#define zassume_mem_equal(...) zassume_mem_equal__(__VA_ARGS__)
576#define zassume_mem_equal__(buf, exp, size, ...) \
577 zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
586#define zassume_str_equal(s1, s2, ...) \
587 zassume(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
608#define zexpect_true(cond, ...) zexpect(cond, #cond " is false", ##__VA_ARGS__)
616#define zexpect_false(cond, ...) zexpect(!(cond), #cond " is true", ##__VA_ARGS__)
625#define zexpect_ok(cond, ...) zexpect(!(cond), #cond " is non-zero", ##__VA_ARGS__)
634#define zexpect_not_ok(cond, ...) zexpect(!!(cond), #cond " is zero", ##__VA_ARGS__)
642#define zexpect_is_null(ptr, ...) zexpect((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
650#define zexpect_not_null(ptr, ...) zexpect((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
659#define zexpect_equal(a, b, ...) zexpect((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
671#define zexpect_not_equal(a, b, ...) zexpect((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
682#define zexpect_equal_ptr(a, b, ...) \
683 zexpect((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
694#define zexpect_within(a, b, delta, ...) \
695 zexpect(((a) >= ((b) - (delta))) && ((a) <= ((b) + (delta))), \
696 #a " not within " #b " +/- " #delta, ##__VA_ARGS__)
707#define zexpect_between_inclusive(a, lower, upper, ...) \
708 zexpect(((a) >= (lower)) && ((a) <= (upper)), \
709 #a " not between " #lower " and " #upper " inclusive", ##__VA_ARGS__)
720#define zexpect_mem_equal(buf, exp, size, ...) \
721 zexpect(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
731#define zexpect_str_equal(s1, s2, ...) \
732 zexpect(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
static void vprintk(const char *fmt, va_list ap)
Definition printk.h:56
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition printk.h:51
#define bool
Definition stdbool.h:13
#define PRINT_DATA(fmt,...)
Definition tc_util.h:25
const char * ztest_relative_filename(const char *file)
void ztest_skip_failed_assumption(void)
void ztest_test_expect_fail(void)
void ztest_test_fail(void)
void ztest_test_skip(void)