Zephyr Project API  3.3.0
A Scalable Open Source RTOS
ztest_test_deprecated.h File Reference

Zephyr testing framework _test_deprecated. More...

Go to the source code of this file.

Data Structures

struct  unit_test
 
struct  ztest_suite_stats
 
struct  ztest_suite_node
 

Macros

#define ztest_register_test_suite(SUITE_NAME, PREDICATE, args...)
 
#define ztest_unit_test_setup_teardown(fn, setup, teardown)
 Define a test with setup and teardown functions. More...
 
#define ztest_user_unit_test_setup_teardown(fn, setup, teardown)
 Define a user mode test with setup and teardown functions. More...
 
#define ztest_unit_test(fn)    ztest_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop)
 Define a test function. More...
 
#define ztest_user_unit_test(fn)    ztest_user_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop)
 Define a test function that should run as a user thread. More...
 
#define ztest_1cpu_unit_test(fn)    ztest_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop)
 Define a SMP-unsafe test function. More...
 
#define ztest_1cpu_user_unit_test(fn)    ztest_user_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop)
 Define a SMP-unsafe test function that should run as a user thread. More...
 
#define ZTEST_DMEM   K_APP_DMEM(ztest_mem_partition)
 
#define ZTEST_BMEM   K_APP_BMEM(ztest_mem_partition)
 
#define ZTEST_SECTION   K_APP_DMEM_SECTION(ztest_mem_partition)
 
#define ztest_test_suite(suite, ...)    static ZTEST_DMEM struct unit_test _##suite[] = { __VA_ARGS__, { 0 } }
 Define a test suite. More...
 
#define ztest_run_test_suite(suite)    z_ztest_run_test_suite(#suite, _##suite)
 Run the specified test suite. More...
 

Functions

int ztest_run_registered_test_suites (const void *state)
 
void ztest_verify_all_registered_test_suites_ran (void)
 Fails the test if any of the registered tests did not run. More...
 
void ztest_test_fail (void)
 Fail the currently running test. More...
 
void ztest_test_pass (void)
 Pass the currently running test. More...
 
void ztest_test_skip (void)
 Skip the current test. More...
 
static void unit_test_noop (void)
 Do nothing, successfully. More...
 

Variables

struct k_mem_partition ztest_mem_partition
 

Detailed Description

Zephyr testing framework _test_deprecated.

Macro Definition Documentation

◆ ztest_register_test_suite

#define ztest_register_test_suite (   SUITE_NAME,
  PREDICATE,
  args... 
)
Value:
ztest_test_suite(SUITE_NAME, ##args); \
struct ztest_suite_stats UTIL_CAT(z_ztest_test_node_stats_, SUITE_NAME); \
static STRUCT_SECTION_ITERABLE(ztest_suite_node, z_ztest_test_node_##SUITE_NAME) = { \
.name = #SUITE_NAME, \
.suite = _##SUITE_NAME, \
.predicate = PREDICATE, \
.stats = &UTIL_CAT(z_ztest_test_node_stats_, SUITE_NAME), \
};
#define STRUCT_SECTION_ITERABLE(struct_type, name)
Defines a new element for an iterable section.
Definition: common.h:216
#define ztest_test_suite(suite,...)
Define a test suite.
Definition: ztest_test_deprecated.h:275
Definition: ztest_test_deprecated.h:48
Definition: ztest_test_deprecated.h:35
#define UTIL_CAT(a,...)
Definition: util_internal.h:104

Create and register a ztest suite. Using this macro creates a new test suite (using ztest_test_suite). It then creates a struct ztest_suite_node in a specific linker section.

Tests can then be run by calling ztest_run_registered_test_suites(const void *state) by passing in the current state. See the documentation for ztest_run_registered_test_suites for more info.

Parameters
SUITE_NAMEThe name of the suite (see ztest_test_suite for more info)
PREDICATEA function to test against the state and determine if the test should run.
argsVarargs placeholder for the remaining arguments passed for the unit tests.

Function Documentation

◆ ztest_run_registered_test_suites()

int ztest_run_registered_test_suites ( const void *  state)

Run the registered unit tests which return true from their pragma function.

Parameters
stateThe current state of the machine as it relates to the test executable.
Returns
The number of tests that ran.

◆ ztest_verify_all_registered_test_suites_ran()

void ztest_verify_all_registered_test_suites_ran ( void  )

Fails the test if any of the registered tests did not run.

When registering test suites, a pragma function can be provided to determine WHEN the test should run. It is possible that a test suite could be registered but the pragma always prevents it from running. In cases where a test should make sure that ALL suites ran at least once, this function may be called at the end of test_main(). It will cause the test to fail if any suite was registered but never ran.