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

Macros

#define zassume_true(cond, ...)
 Assume that cond is true.
 
#define zassume_false(cond, ...)
 Assume that cond is false.
 
#define zassume_ok(cond, ...)
 Assume that cond is 0 (success)
 
#define zassume_not_ok(cond, ...)
 Assume that cond is not 0 (failure)
 
#define zassume_is_null(ptr, ...)
 Assume that ptr is NULL.
 
#define zassume_not_null(ptr, ...)
 Assume that ptr is not NULL.
 
#define zassume_equal(a, b, ...)
 Assume that a equals b.
 
#define zassume_not_equal(a, b, ...)
 Assume that a does not equal b.
 
#define zassume_equal_ptr(a, b, ...)
 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(...)
 Assume that 2 memory buffers have the same contents.
 
#define zassume_mem_equal__(buf, exp, size, ...)
 Internal assume that 2 memory buffers have the same contents.
 
#define zassume_str_equal(s1, s2, ...)
 Assumes that 2 strings have the same contents.
 

Detailed Description

This module provides assumptions when using Ztest.

Macro Definition Documentation

◆ zassume_between_inclusive

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

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

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

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

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_equal

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

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

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

Assume that a equals b.

a and b won't be converted and will be compared directly. If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_equal_ptr

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

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

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

Assume that a equals b.

a and b will be converted to void * before comparing. If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_false

#define zassume_false ( cond,
... )

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

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

Assume that cond is false.

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_is_null

#define zassume_is_null ( ptr,
... )

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

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

Assume that ptr is NULL.

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_mem_equal

#define zassume_mem_equal ( ...)

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

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

Assume that 2 memory buffers have the same contents.

This macro calls the final memory comparison assumption 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 zassume_mem_equal__ for real arguments accepted.

◆ zassume_mem_equal__

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

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

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

Internal assume that 2 memory buffers have the same contents.

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_not_equal

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

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

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

Assume that a does not equal b.

a and b won't be converted and will be compared directly. If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_not_null

#define zassume_not_null ( ptr,
... )

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

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

Assume that ptr is not NULL.

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_not_ok

#define zassume_not_ok ( cond,
... )

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

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

Assume that cond is not 0 (failure)

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_ok

#define zassume_ok ( cond,
... )

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

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

Assume that cond is 0 (success)

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_str_equal

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

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

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

Assumes that 2 strings have the same contents.

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

◆ zassume_true

#define zassume_true ( cond,
... )

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

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

Assume that cond is true.

If the assumption fails, the test will be marked as "skipped".

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

◆ zassume_within

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

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

Value:
zassume(((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

Assume that a is within b with delta d.

If the assumption fails, the test will be marked as "skipped".

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