Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Ztest assertion macros

This module provides assertions when using Ztest. More...

Macros

#define zassert(cond, default_msg, ...)
 
#define zassume(cond, default_msg, ...)
 
#define zexpect(cond, default_msg, ...)
 
#define zassert_unreachable(...)
 Assert that this function call won't be reached.
 
#define zassert_true(cond, ...)
 Assert that cond is true.
 
#define zassert_false(cond, ...)
 Assert that cond is false.
 
#define zassert_ok(cond, ...)
 Assert that cond is 0 (success)
 
#define zassert_not_ok(cond, ...)
 Assert that cond is not 0 (failure)
 
#define zassert_is_null(ptr, ...)
 Assert that ptr is NULL.
 
#define zassert_not_null(ptr, ...)
 Assert that ptr is not NULL.
 
#define zassert_equal(a, b, ...)
 Assert that a equals b.
 
#define zassert_not_equal(a, b, ...)
 Assert that a does not equal b.
 
#define zassert_equal_ptr(a, b, ...)
 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(...)
 Assert that 2 memory buffers have the same contents.
 
#define zassert_mem_equal__(buf, exp, size, ...)
 Internal assert that 2 memory buffers have the same contents.
 
#define zassert_str_equal(s1, s2, ...)
 Assert that 2 strings have the same contents.
 

Detailed Description

This module provides assertions when using Ztest.

Macro Definition Documentation

◆ zassert

#define zassert ( cond,
default_msg,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
_zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195

◆ zassert_between_inclusive

#define zassert_between_inclusive ( a,
l,
u,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
##__VA_ARGS__)
#define zassert(cond, default_msg,...)
Definition ztest_assert.h:193

Assert that a is greater than or equal to l and less than or equal to u.

Parameters
aValue to compare
lLower limit
uUpper limit
...Optional message and variables to print if the assertion fails

◆ zassert_equal

#define zassert_equal ( a,
b,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)

Assert that a equals b.

a and b won't be converted and will be compared directly.

Parameters
aValue to compare
bValue to compare
...Optional message and variables to print if the assertion fails

◆ zassert_equal_ptr

#define zassert_equal_ptr ( a,
b,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)

Assert that a equals b.

a and b will be converted to void * before comparing.

Parameters
aValue to compare
bValue to compare
...Optional message and variables to print if the assertion fails

◆ zassert_false

#define zassert_false ( cond,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(!(cond), #cond " is true", ##__VA_ARGS__)

Assert that cond is false.

Parameters
condCondition to check
...Optional message and variables to print if the assertion fails

◆ zassert_is_null

#define zassert_is_null ( ptr,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)

Assert that ptr is NULL.

Parameters
ptrPointer to compare
...Optional message and variables to print if the assertion fails

◆ zassert_mem_equal

#define zassert_mem_equal ( ...)

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert_mem_equal__(__VA_ARGS__)
#define zassert_mem_equal__(buf, exp, size,...)
Internal assert that 2 memory buffers have the same contents.
Definition ztest_assert.h:395

Assert that 2 memory buffers have the same contents.

This macro calls the final memory comparison assertion macro. Using double expansion allows providing some arguments by macros that would expand to more than one values (ANSI-C99 defines that all the macro arguments have to be expanded before macro call).

Parameters
...Arguments, see zassert_mem_equal__ for real arguments accepted.

◆ zassert_mem_equal__

#define zassert_mem_equal__ ( buf,
exp,
size,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
int memcmp(const void *m1, const void *m2, size_t n)

Internal assert that 2 memory buffers have the same contents.

Note
This is internal macro, to be used as a second expansion. See zassert_mem_equal.
Parameters
bufBuffer to compare
expBuffer with expected contents
sizeSize of buffers
...Optional message and variables to print if the assertion fails

◆ zassert_not_equal

#define zassert_not_equal ( a,
b,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert((a) != (b), #a " equal to " #b, ##__VA_ARGS__)

Assert that a does not equal b.

a and b won't be converted and will be compared directly.

Parameters
aValue to compare
bValue to compare
...Optional message and variables to print if the assertion fails

◆ zassert_not_null

#define zassert_not_null ( ptr,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)

Assert that ptr is not NULL.

Parameters
ptrPointer to compare
...Optional message and variables to print if the assertion fails

◆ zassert_not_ok

#define zassert_not_ok ( cond,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(!!(cond), #cond " is zero", ##__VA_ARGS__)

Assert that cond is not 0 (failure)

Parameters
condCondition to check
...Optional message and variables to print if the assertion fails

◆ zassert_ok

#define zassert_ok ( cond,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(!(cond), #cond " is non-zero", ##__VA_ARGS__)

Assert that cond is 0 (success)

Parameters
condCondition to check
...Optional message and variables to print if the assertion fails

◆ zassert_str_equal

#define zassert_str_equal ( s1,
s2,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(strcmp(s1, s2) == 0, #s1 " not equal to " #s2, ##__VA_ARGS__)
int strcmp(const char *s1, const char *s2)

Assert that 2 strings have the same contents.

Parameters
s1The first string
s2The second string
...Optional message and variables to print if the expectation fails

◆ zassert_true

#define zassert_true ( cond,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(cond, #cond " is false", ##__VA_ARGS__)

Assert that cond is true.

Parameters
condCondition to check
...Optional message and variables to print if the assertion fails

◆ zassert_unreachable

#define zassert_unreachable ( ...)

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(0, "Reached unreachable code", ##__VA_ARGS__)

Assert that this function call won't be reached.

Parameters
...Optional message and variables to print if the assertion fails

◆ zassert_within

#define zassert_within ( a,
b,
d,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
##__VA_ARGS__)
irp nz macro MOVR cc d
Definition asm-macro-32-bit-gnu.h:11

Assert that a is within b with delta d.

Parameters
aValue to compare
bValue to compare
dDelta
...Optional message and variables to print if the assertion fails

◆ zassume

#define zassume ( cond,
default_msg,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
_zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))

◆ zexpect

#define zexpect ( cond,
default_msg,
... )

#include </home/runner/work/zephyr/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
_zexpect_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))