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

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

Macros

#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.
 

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:225

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,
  ... 
)    zassume((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)

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

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,
  ... 
)     zassume((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)

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

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,
  ... 
)    zassume(!(cond), #cond " is true", ##__VA_ARGS__)

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

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,
  ... 
)    zassume((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)

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

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 (   ...)    zassume_mem_equal__(__VA_ARGS__)

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

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,
  ... 
)     zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)

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

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,
  ... 
)    zassume((a) != (b), #a " equal to " #b, ##__VA_ARGS__)

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

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,
  ... 
)    zassume((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)

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

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,
  ... 
)    zassume(!!(cond), #cond " is zero", ##__VA_ARGS__)

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

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,
  ... 
)    zassume(!(cond), #cond " is non-zero", ##__VA_ARGS__)

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

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_true

#define zassume_true (   cond,
  ... 
)    zassume(cond, #cond " is false", ##__VA_ARGS__)

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

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