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

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

Macros

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

Detailed Description

This module provides expectations when using Ztest.

Macro Definition Documentation

◆ zexpect_between_inclusive

#define zexpect_between_inclusive (   a,
  lower,
  upper,
  ... 
)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zexpect(((a) >= (lower)) && ((a) <= (upper)), \
#a " not between " #lower " and " #upper " inclusive", ##__VA_ARGS__)
#define zexpect(cond, default_msg,...)
Definition: ztest_assert.h:255

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.

Parameters
aValue to compare
lowerLower limit
upperUpper limit
...Optional message and variables to print if the expectation fails

◆ zexpect_equal

#define zexpect_equal (   a,
  b,
  ... 
)    zexpect((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that a equals b, otherwise mark test as failed but continue its execution.

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

◆ zexpect_equal_ptr

#define zexpect_equal_ptr (   a,
  b,
  ... 
)     zexpect((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that a equals b, otherwise mark test as failed but continue its execution.

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 expectation fails

◆ zexpect_false

#define zexpect_false (   cond,
  ... 
)    zexpect(!(cond), #cond " is true", ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that cond is false, otherwise mark test as failed but continue its execution.

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

◆ zexpect_is_null

#define zexpect_is_null (   ptr,
  ... 
)    zexpect((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that ptr is NULL, otherwise mark test as failed but continue its execution.

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

◆ zexpect_mem_equal

#define zexpect_mem_equal (   buf,
  exp,
  size,
  ... 
)     zexpect(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that 2 memory buffers have the same contents, otherwise mark test as failed but continue its execution.

Parameters
bufBuffer to compare
expBuffer with expected contents
sizeSize of buffers
...Optional message and variables to print if the expectation fails

◆ zexpect_not_equal

#define zexpect_not_equal (   a,
  b,
  ... 
)    zexpect((a) != (b), #a " equal to " #b, ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that a does not equal b, otherwise mark test as failed but continue its execution.

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 expectation fails

◆ zexpect_not_null

#define zexpect_not_null (   ptr,
  ... 
)    zexpect((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that ptr is not NULL, otherwise mark test as failed but continue its execution.

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

◆ zexpect_not_ok

#define zexpect_not_ok (   cond,
  ... 
)    zexpect(!!(cond), #cond " is zero", ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that cond is not 0 (failure), otherwise mark test as failed but continue its execution.

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

◆ zexpect_ok

#define zexpect_ok (   cond,
  ... 
)    zexpect(!(cond), #cond " is non-zero", ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that cond is 0 (success), otherwise mark test as failed but continue its execution.

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

◆ zexpect_true

#define zexpect_true (   cond,
  ... 
)    zexpect(cond, #cond " is false", ##__VA_ARGS__)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Expect that cond is true, otherwise mark test as failed but continue its execution.

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

◆ zexpect_within

#define zexpect_within (   a,
  b,
  delta,
  ... 
)

#include </home/runner/work/sdk-nrf/sdk-nrf/ncs/zephyr/subsys/testsuite/ztest/include/zephyr/ztest_assert.h>

Value:
zexpect(((a) >= ((b) - (delta))) && ((a) <= ((b) + (delta))), \
#a " not within " #b " +/- " #delta, ##__VA_ARGS__)

Expect that a is within b with delta d, otherwise mark test as failed but continue its execution.

Parameters
aValue to compare
bValue to compare
deltaDifference between a and b
...Optional message and variables to print if the expectation fails