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

Macros

#define zexpect_true(cond, ...)
 Expect that cond is true, otherwise mark test as failed but continue its execution.
 
#define zexpect_false(cond, ...)
 Expect that cond is false, otherwise mark test as failed but continue its execution.
 
#define zexpect_ok(cond, ...)
 Expect that cond is 0 (success), otherwise mark test as failed but continue its execution.
 
#define zexpect_not_ok(cond, ...)
 Expect that cond is not 0 (failure), otherwise mark test as failed but continue its execution.
 
#define zexpect_is_null(ptr, ...)
 Expect that ptr is NULL, otherwise mark test as failed but continue its execution.
 
#define zexpect_not_null(ptr, ...)
 Expect that ptr is not NULL, otherwise mark test as failed but continue its execution.
 
#define zexpect_equal(a, b, ...)
 Expect that a equals b, otherwise mark test as failed but continue its execution.
 
#define zexpect_not_equal(a, b, ...)
 Expect that a does not equal b, otherwise mark test as failed but continue its execution.
 
#define zexpect_equal_ptr(a, b, ...)
 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, ...)
 Expect that 2 memory buffers have the same contents, otherwise mark test as failed but continue its execution.
 
#define zexpect_str_equal(s1, s2, ...)
 Expect that 2 strings 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/zephyr/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:261

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,
... )

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

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

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,
... )

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

Value:
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.

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,
... )

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

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

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,
... )

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

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

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,
... )

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

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

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,
... )

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

Value:
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.

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,
... )

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

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

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,
... )

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

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

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,
... )

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

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

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_str_equal

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

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

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

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

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

◆ zexpect_true

#define zexpect_true ( cond,
... )

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

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

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/zephyr/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