13#ifndef ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
14#define ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
28#if CONFIG_ZTEST_ASSERT_VERBOSE == 0
30static inline bool z_zassert_(
bool cond,
const char *file,
int line)
33 PRINT(
"\n Assertion failed at %s:%d\n",
42#define z_zassert(cond, default_msg, file, line, func, msg, ...) \
43 z_zassert_(cond, file, line)
47static inline bool z_zassert(
bool cond,
48 const char *default_msg,
50 int line,
const char *func,
57 PRINT(
"\n Assertion failed at %s:%d: %s: %s\n",
65#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
67 PRINT(
"\n Assertion succeeded at %s:%d (%s)\n",
100#define zassert(cond, default_msg, msg, ...) do { \
101 bool _ret = z_zassert(cond, msg ? ("(" default_msg ")") : (default_msg), \
102 __FILE__, __LINE__, __func__, \
103 msg ? msg : "", ##__VA_ARGS__); \
106 COND_CODE_1(KERNEL, \
107 (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
116#define zassert_unreachable(msg, ...) zassert(0, "Reached unreachable code", \
124#define zassert_true(cond, msg, ...) zassert(cond, #cond " is false", \
132#define zassert_false(cond, msg, ...) zassert(!(cond), #cond " is true", \
140#define zassert_ok(cond, msg, ...) zassert(!(cond), #cond " is non-zero", \
148#define zassert_is_null(ptr, msg, ...) zassert((ptr) == NULL, \
149 #ptr " is not NULL", \
157#define zassert_not_null(ptr, msg, ...) zassert((ptr) != NULL, \
158 #ptr " is NULL", msg, \
170#define zassert_equal(a, b, msg, ...) zassert((a) == (b), \
171 #a " not equal to " #b, \
183#define zassert_not_equal(a, b, msg, ...) zassert((a) != (b), \
184 #a " equal to " #b, \
196#define zassert_equal_ptr(a, b, msg, ...) \
197 zassert((void *)(a) == (void *)(b), #a " not equal to " #b, \
208#define zassert_within(a, b, d, msg, ...) \
209 zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), \
210 #a " not within " #b " +/- " #d, \
224#define zassert_mem_equal(...) \
225 zassert_mem_equal__(__VA_ARGS__)
238#define zassert_mem_equal__(buf, exp, size, msg, ...) \
239 zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, \
static void vprintk(const char *fmt, va_list ap)
Definition: printk.h:71
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition: printk.h:66
#define PRINT
Definition: ztest.h:56
const char * ztest_relative_filename(const char *file)
void ztest_test_fail(void)