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 bool z_zassert(
bool cond, 
const char *default_msg, 
const char *file, 
int line,
 
   80                             const char *func, 
const char *msg, ...)
 
   86                PRINT_DATA(
"\n    Assertion failed at %s:%d: %s: %s\n",
 
   94#if CONFIG_ZTEST_ASSERT_VERBOSE == 2 
   96                PRINT_DATA(
"\n   Assertion succeeded at %s:%d (%s)\n",
 
  103static inline bool z_zassume(
bool cond, 
const char *default_msg, 
const char *file, 
int line,
 
  104                             const char *func, 
const char *msg, ...)
 
  109                va_start(vargs, msg);
 
  110                PRINT_DATA(
"\n    Assumption failed at %s:%d: %s: %s\n",
 
  118#if CONFIG_ZTEST_ASSERT_VERBOSE == 2 
  120                PRINT_DATA(
"\n   Assumption succeeded at %s:%d (%s)\n",
 
  127static inline bool z_zexpect(
bool cond, 
const char *default_msg, 
const char *file, 
int line,
 
  128                             const char *func, 
const char *msg, ...)
 
  133                va_start(vargs, msg);
 
  134                PRINT_DATA(
"\n    Expectation failed at %s:%d: %s: %s\n",
 
  142#if CONFIG_ZTEST_ASSERT_VERBOSE == 2 
  144                PRINT_DATA(
"\n   Expectation succeeded at %s:%d (%s)\n",
 
  176#define _zassert_base(cond, default_msg, msg, ...)                                                 \ 
  178                bool _msg = (msg != NULL);                                                         \ 
  180                        z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,    \ 
  181                                  __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__);             \ 
  185                        COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))),   \ 
  190#define _zassert_va(cond, default_msg, msg, ...)                                                   \ 
  191        _zassert_base(cond, default_msg, msg, ##__VA_ARGS__) 
  193#define zassert(cond, default_msg, ...)                                                            \ 
  194        _zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL))) 
 
  214#define _zassume_base(cond, default_msg, msg, ...)                                                 \ 
  216                bool _msg = (msg != NULL);                                                         \ 
  218                        z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,    \ 
  219                                  __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__);             \ 
  223                        COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))),   \ 
  228#define _zassume_va(cond, default_msg, msg, ...)                                                   \ 
  229        _zassume_base(cond, default_msg, msg, ##__VA_ARGS__) 
  231#define zassume(cond, default_msg, ...)                                                            \ 
  232        _zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL))) 
 
  244#define _zexpect_base(cond, default_msg, msg, ...)                                                 \ 
  246                bool _msg = (msg != NULL);                                                         \ 
  248                        z_zexpect(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,    \ 
  249                                  __LINE__, __func__, _msg ? msg : "", ##__VA_ARGS__);             \ 
  253                        COND_CODE_1(KERNEL, (COND_CODE_1(CONFIG_MULTITHREADING, (), (return;))),   \ 
  258#define _zexpect_va(cond, default_msg, msg, ...)                                                   \ 
  259        _zexpect_base(cond, default_msg, msg, ##__VA_ARGS__) 
  261#define zexpect(cond, default_msg, ...)                                                            \ 
  262        _zexpect_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL))) 
 
  268#define zassert_unreachable(...) zassert(0, "Reached unreachable code", ##__VA_ARGS__) 
  275#define zassert_true(cond, ...) zassert(cond, #cond " is false", ##__VA_ARGS__) 
  282#define zassert_false(cond, ...) zassert(!(cond), #cond " is true", ##__VA_ARGS__) 
  289#define zassert_ok(cond, ...) zassert(!(cond), #cond " is non-zero", ##__VA_ARGS__) 
  296#define zassert_not_ok(cond, ...) zassert(!!(cond), #cond " is zero", ##__VA_ARGS__) 
  303#define zassert_is_null(ptr, ...) zassert((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__) 
  310#define zassert_not_null(ptr, ...) zassert((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__) 
  321#define zassert_equal(a, b, ...) zassert((a) == (b), #a " not equal to " #b, ##__VA_ARGS__) 
  332#define zassert_not_equal(a, b, ...) zassert((a) != (b), #a " equal to " #b, ##__VA_ARGS__) 
  343#define zassert_equal_ptr(a, b, ...)                                                               \ 
  344        zassert((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__) 
 
  354#define zassert_within(a, b, d, ...)                                                               \ 
  355        zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d,     \ 
 
  367#define zassert_between_inclusive(a, l, u, ...)                                                    \ 
  368        zassert(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive",       \ 
 
  382#define zassert_mem_equal(...) zassert_mem_equal__(__VA_ARGS__) 
  395#define zassert_mem_equal__(buf, exp, size, ...)                                                   \ 
  396        zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__) 
 
  405#define zassert_str_equal(s1, s2, ...)                                                             \ 
  406        zassert(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__) 
 
  429#define zassume_true(cond, ...) zassume(cond, #cond " is false", ##__VA_ARGS__) 
  439#define zassume_false(cond, ...) zassume(!(cond), #cond " is true", ##__VA_ARGS__) 
  449#define zassume_ok(cond, ...) zassume(!(cond), #cond " is non-zero", ##__VA_ARGS__) 
  459#define zassume_not_ok(cond, ...) zassume(!!(cond), #cond " is zero", ##__VA_ARGS__) 
  469#define zassume_is_null(ptr, ...) zassume((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__) 
  479#define zassume_not_null(ptr, ...) zassume((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__) 
  491#define zassume_equal(a, b, ...) zassume((a) == (b), #a " not equal to " #b, ##__VA_ARGS__) 
  503#define zassume_not_equal(a, b, ...) zassume((a) != (b), #a " equal to " #b, ##__VA_ARGS__) 
  515#define zassume_equal_ptr(a, b, ...)                                                               \ 
  516        zassume((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__) 
 
  528#define zassume_within(a, b, d, ...)                                                               \ 
  529        zassume(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d,     \ 
 
  543#define zassume_between_inclusive(a, l, u, ...)                                                    \ 
  544        zassume(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive",       \ 
 
  558#define zassume_mem_equal(...) zassume_mem_equal__(__VA_ARGS__) 
  573#define zassume_mem_equal__(buf, exp, size, ...)                                                   \ 
  574        zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__) 
 
  583#define zassume_str_equal(s1, s2, ...)                                                             \ 
  584        zassume(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__) 
 
  605#define zexpect_true(cond, ...) zexpect(cond, #cond " is false", ##__VA_ARGS__) 
  613#define zexpect_false(cond, ...) zexpect(!(cond), #cond " is true", ##__VA_ARGS__) 
  622#define zexpect_ok(cond, ...) zexpect(!(cond), #cond " is non-zero", ##__VA_ARGS__) 
  631#define zexpect_not_ok(cond, ...) zexpect(!!(cond), #cond " is zero", ##__VA_ARGS__) 
  639#define zexpect_is_null(ptr, ...) zexpect((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__) 
  647#define zexpect_not_null(ptr, ...) zexpect((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__) 
  656#define zexpect_equal(a, b, ...) zexpect((a) == (b), #a " not equal to " #b, ##__VA_ARGS__) 
  668#define zexpect_not_equal(a, b, ...) zexpect((a) != (b), #a " equal to " #b, ##__VA_ARGS__) 
  679#define zexpect_equal_ptr(a, b, ...)                                                               \ 
  680        zexpect((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__) 
 
  691#define zexpect_within(a, b, delta, ...)                                                           \ 
  692        zexpect(((a) >= ((b) - (delta))) && ((a) <= ((b) + (delta))),                              \ 
  693                #a " not within " #b " +/- " #delta, ##__VA_ARGS__) 
 
  704#define zexpect_between_inclusive(a, lower, upper, ...)                                            \ 
  705        zexpect(((a) >= (lower)) && ((a) <= (upper)),                                              \ 
  706                #a " not between " #lower " and " #upper " inclusive", ##__VA_ARGS__) 
 
  717#define zexpect_mem_equal(buf, exp, size, ...)                                                     \ 
  718        zexpect(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__) 
 
  728#define zexpect_str_equal(s1, s2, ...)                                                             \ 
  729        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_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)