Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ztest_assert.h File Reference

Zephyr testing framework assertion macros. More...

#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <zephyr/ztest.h>

Go to the source code of this file.

Macros

#define zassert(cond, default_msg, ...)    _zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
 
#define zassume(cond, default_msg, ...)    _zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
 
#define zexpect(cond, default_msg, ...)    _zexpect_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
 
#define zassert_unreachable(...)   zassert(0, "Reached unreachable code", ##__VA_ARGS__)
 Assert that this function call won't be reached.
 
#define zassert_true(cond, ...)   zassert(cond, #cond " is false", ##__VA_ARGS__)
 Assert that cond is true.
 
#define zassert_false(cond, ...)   zassert(!(cond), #cond " is true", ##__VA_ARGS__)
 Assert that cond is false.
 
#define zassert_ok(cond, ...)   zassert(!(cond), #cond " is non-zero", ##__VA_ARGS__)
 Assert that cond is 0 (success)
 
#define zassert_not_ok(cond, ...)   zassert(!!(cond), #cond " is zero", ##__VA_ARGS__)
 Assert that cond is not 0 (failure)
 
#define zassert_is_null(ptr, ...)   zassert((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
 Assert that ptr is NULL.
 
#define zassert_not_null(ptr, ...)   zassert((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
 Assert that ptr is not NULL.
 
#define zassert_equal(a, b, ...)   zassert((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
 Assert that a equals b.
 
#define zassert_not_equal(a, b, ...)   zassert((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
 Assert that a does not equal b.
 
#define zassert_equal_ptr(a, b, ...)    zassert((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
 Assert that a equals b.
 
#define zassert_within(a, b, d, ...)
 Assert that a is within b with delta d.
 
#define zassert_between_inclusive(a, l, u, ...)
 Assert that a is greater than or equal to l and less than or equal to u.
 
#define zassert_mem_equal(...)   zassert_mem_equal__(__VA_ARGS__)
 Assert that 2 memory buffers have the same contents.
 
#define zassert_mem_equal__(buf, exp, size, ...)    zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
 Internal assert that 2 memory buffers have the same contents.
 
#define zassert_str_equal(s1, s2, ...)    zassert(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
 Assert that 2 strings have the same contents.
 
#define zassume_true(cond, ...)   zassume(cond, #cond " is false", ##__VA_ARGS__)
 Assume that cond is true.
 
#define zassume_false(cond, ...)   zassume(!(cond), #cond " is true", ##__VA_ARGS__)
 Assume that cond is false.
 
#define zassume_ok(cond, ...)   zassume(!(cond), #cond " is non-zero", ##__VA_ARGS__)
 Assume that cond is 0 (success)
 
#define zassume_not_ok(cond, ...)   zassume(!!(cond), #cond " is zero", ##__VA_ARGS__)
 Assume that cond is not 0 (failure)
 
#define zassume_is_null(ptr, ...)   zassume((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
 Assume that ptr is NULL.
 
#define zassume_not_null(ptr, ...)   zassume((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
 Assume that ptr is not NULL.
 
#define zassume_equal(a, b, ...)   zassume((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
 Assume that a equals b.
 
#define zassume_not_equal(a, b, ...)   zassume((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
 Assume that a does not equal b.
 
#define zassume_equal_ptr(a, b, ...)    zassume((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
 Assume that a equals b.
 
#define zassume_within(a, b, d, ...)
 Assume that a is within b with delta d.
 
#define zassume_between_inclusive(a, l, u, ...)
 Assume that a is greater than or equal to l and less than or equal to u.
 
#define zassume_mem_equal(...)   zassume_mem_equal__(__VA_ARGS__)
 Assume that 2 memory buffers have the same contents.
 
#define zassume_mem_equal__(buf, exp, size, ...)    zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
 Internal assume that 2 memory buffers have the same contents.
 
#define zassume_str_equal(s1, s2, ...)    zassume(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
 Assumes that 2 strings have the same contents.
 
#define zexpect_true(cond, ...)   zexpect(cond, #cond " is false", ##__VA_ARGS__)
 Expect that cond is true, otherwise mark test as failed but continue its execution.
 
#define zexpect_false(cond, ...)   zexpect(!(cond), #cond " is true", ##__VA_ARGS__)
 Expect that cond is false, otherwise mark test as failed but continue its execution.
 
#define zexpect_ok(cond, ...)   zexpect(!(cond), #cond " is non-zero", ##__VA_ARGS__)
 Expect that cond is 0 (success), otherwise mark test as failed but continue its execution.
 
#define zexpect_not_ok(cond, ...)   zexpect(!!(cond), #cond " is zero", ##__VA_ARGS__)
 Expect that cond is not 0 (failure), otherwise mark test as failed but continue its execution.
 
#define zexpect_is_null(ptr, ...)   zexpect((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
 Expect that ptr is NULL, otherwise mark test as failed but continue its execution.
 
#define zexpect_not_null(ptr, ...)   zexpect((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
 Expect that ptr is not NULL, otherwise mark test as failed but continue its execution.
 
#define zexpect_equal(a, b, ...)   zexpect((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
 Expect that a equals b, otherwise mark test as failed but continue its execution.
 
#define zexpect_not_equal(a, b, ...)   zexpect((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
 Expect that a does not equal b, otherwise mark test as failed but continue its execution.
 
#define zexpect_equal_ptr(a, b, ...)    zexpect((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
 Expect that a equals b, otherwise mark test as failed but continue its execution.
 
#define zexpect_within(a, b, delta, ...)
 Expect that a is within b with delta d, otherwise mark test as failed but continue its execution.
 
#define zexpect_between_inclusive(a, lower, upper, ...)
 Expect that a is greater than or equal to l and less than or equal to u, otherwise mark test as failed but continue its execution.
 
#define zexpect_mem_equal(buf, exp, size, ...)    zexpect(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
 Expect that 2 memory buffers have the same contents, otherwise mark test as failed but continue its execution.
 
#define zexpect_str_equal(s1, s2, ...)    zexpect(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
 Expect that 2 strings have the same contents, otherwise mark test as failed but continue its execution.
 

Functions

const char * ztest_relative_filename (const char *file)
 
void ztest_test_fail (void)
 
void ztest_test_skip (void)
 
void ztest_test_expect_fail (void)
 
void ztest_skip_failed_assumption (void)
 

Detailed Description

Zephyr testing framework assertion macros.

Function Documentation

◆ ztest_relative_filename()

const char * ztest_relative_filename ( const char *  file)

◆ ztest_skip_failed_assumption()

void ztest_skip_failed_assumption ( void  )

◆ ztest_test_expect_fail()

void ztest_test_expect_fail ( void  )

◆ ztest_test_fail()

void ztest_test_fail ( void  )

◆ ztest_test_skip()

void ztest_test_skip ( void  )