13#ifndef ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
14#define ZEPHYR_TESTSUITE_ZTEST_ASSERT_H_
32#if CONFIG_ZTEST_ASSERT_VERBOSE == 0
34static inline bool z_zassert_(
bool cond,
const char *file,
int line)
45#define z_zassert(cond, default_msg, file, line, func, msg, ...) z_zassert_(cond, file, line)
47static inline bool z_zassume_(
bool cond,
const char *file,
int line)
58#define z_zassume(cond, default_msg, file, line, func, msg, ...) z_zassume_(cond, file, line)
60static inline bool z_zexpect_(
bool cond,
const char *file,
int line)
71#define z_zexpect(cond, default_msg, file, line, func, msg, ...) z_zexpect_(cond, file, line)
75static inline bool z_zassert(
bool cond,
const char *default_msg,
const char *file,
int line,
76 const char *func,
const char *msg, ...)
83 line, func, default_msg);
90#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
99static inline bool z_zassume(
bool cond,
const char *default_msg,
const char *file,
int line,
100 const char *func,
const char *msg, ...)
105 va_start(vargs, msg);
107 line, func, default_msg);
114#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
123static inline bool z_zexpect(
bool cond,
const char *default_msg,
const char *file,
int line,
124 const char *func,
const char *msg, ...)
129 va_start(vargs, msg);
131 line, func, default_msg);
138#if CONFIG_ZTEST_ASSERT_VERBOSE == 2
172#define _zassert_base(cond, default_msg, msg, ...) \
174 bool _msg = (msg != NULL); \
175 bool _ret = z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
176 __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
180 COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
185#define _zassert_va(cond, default_msg, msg, ...) \
186 _zassert_base(cond, default_msg, msg, ##__VA_ARGS__)
188#define zassert(cond, default_msg, ...) \
189 _zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
209#define _zassume_base(cond, default_msg, msg, ...) \
211 bool _msg = (msg != NULL); \
212 bool _ret = z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\
213 __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
217 COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
222#define _zassume_va(cond, default_msg, msg, ...) \
223 _zassume_base(cond, default_msg, msg, ##__VA_ARGS__)
225#define zassume(cond, default_msg, ...) \
226 _zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
238#define _zexpect_base(cond, default_msg, msg, ...) \
240 bool _msg = (msg != NULL); \
242 z_zexpect(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__, \
243 __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__); \
247 COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))), \
252#define _zexpect_va(cond, default_msg, msg, ...) \
253 _zexpect_base(cond, default_msg, msg, ##__VA_ARGS__)
255#define zexpect(cond, default_msg, ...) \
256 _zexpect_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
262#define zassert_unreachable(...) zassert(0, "Reached unreachable code", ##__VA_ARGS__)
269#define zassert_true(cond, ...) zassert(cond, #cond " is false", ##__VA_ARGS__)
276#define zassert_false(cond, ...) zassert(!(cond), #cond " is true", ##__VA_ARGS__)
283#define zassert_ok(cond, ...) zassert(!(cond), #cond " is non-zero", ##__VA_ARGS__)
290#define zassert_not_ok(cond, ...) zassert(!!(cond), #cond " is zero", ##__VA_ARGS__)
297#define zassert_is_null(ptr, ...) zassert((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
304#define zassert_not_null(ptr, ...) zassert((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
315#define zassert_equal(a, b, ...) zassert((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
326#define zassert_not_equal(a, b, ...) zassert((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
337#define zassert_equal_ptr(a, b, ...) \
338 zassert((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
348#define zassert_within(a, b, d, ...) \
349 zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
361#define zassert_between_inclusive(a, l, u, ...) \
362 zassert(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
376#define zassert_mem_equal(...) zassert_mem_equal__(__VA_ARGS__)
389#define zassert_mem_equal__(buf, exp, size, ...) \
390 zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
399#define zassert_str_equal(s1, s2, ...) \
400 zassert(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
423#define zassume_true(cond, ...) zassume(cond, #cond " is false", ##__VA_ARGS__)
433#define zassume_false(cond, ...) zassume(!(cond), #cond " is true", ##__VA_ARGS__)
443#define zassume_ok(cond, ...) zassume(!(cond), #cond " is non-zero", ##__VA_ARGS__)
453#define zassume_not_ok(cond, ...) zassume(!!(cond), #cond " is zero", ##__VA_ARGS__)
463#define zassume_is_null(ptr, ...) zassume((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
473#define zassume_not_null(ptr, ...) zassume((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
485#define zassume_equal(a, b, ...) zassume((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
497#define zassume_not_equal(a, b, ...) zassume((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
509#define zassume_equal_ptr(a, b, ...) \
510 zassume((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
522#define zassume_within(a, b, d, ...) \
523 zassume(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
537#define zassume_between_inclusive(a, l, u, ...) \
538 zassume(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
552#define zassume_mem_equal(...) zassume_mem_equal__(__VA_ARGS__)
567#define zassume_mem_equal__(buf, exp, size, ...) \
568 zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
577#define zassume_str_equal(s1, s2, ...) \
578 zassume(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
599#define zexpect_true(cond, ...) zexpect(cond, #cond " is false", ##__VA_ARGS__)
607#define zexpect_false(cond, ...) zexpect(!(cond), #cond " is true", ##__VA_ARGS__)
616#define zexpect_ok(cond, ...) zexpect(!(cond), #cond " is non-zero", ##__VA_ARGS__)
625#define zexpect_not_ok(cond, ...) zexpect(!!(cond), #cond " is zero", ##__VA_ARGS__)
633#define zexpect_is_null(ptr, ...) zexpect((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
641#define zexpect_not_null(ptr, ...) zexpect((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
650#define zexpect_equal(a, b, ...) zexpect((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
662#define zexpect_not_equal(a, b, ...) zexpect((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
673#define zexpect_equal_ptr(a, b, ...) \
674 zexpect((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
685#define zexpect_within(a, b, delta, ...) \
686 zexpect(((a) >= ((b) - (delta))) && ((a) <= ((b) + (delta))), \
687 #a " not within " #b " +/- " #delta, ##__VA_ARGS__)
698#define zexpect_between_inclusive(a, lower, upper, ...) \
699 zexpect(((a) >= (lower)) && ((a) <= (upper)), \
700 #a " not between " #lower " and " #upper " inclusive", ##__VA_ARGS__)
711#define zexpect_mem_equal(buf, exp, size, ...) \
712 zexpect(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
722#define zexpect_str_equal(s1, s2, ...) \
723 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 PRINT
Definition: ztest.h:38
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)