Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Ztest testing macros

Macros

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

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

This module eases the testing process by providing helpful macros and other testing structures.

Macro Definition Documentation

◆ ztest_1cpu_unit_test

#define ztest_1cpu_unit_test (   fn)     ztest_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Define a SMP-unsafe test function.

As ztest_unit_test(), but ensures all test code runs on only one CPU when in SMP.

Parameters
fnTest function

◆ ztest_1cpu_user_unit_test

#define ztest_1cpu_user_unit_test (   fn)     ztest_user_unit_test_setup_teardown(fn, z_test_1cpu_start, z_test_1cpu_stop)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Define a SMP-unsafe test function that should run as a user thread.

As ztest_user_unit_test(), but ensures all test code runs on only one CPU when in SMP.

Parameters
fnTest function

◆ ZTEST_BMEM

◆ ZTEST_DMEM

◆ ztest_run_test_suite

#define ztest_run_test_suite (   suite)     z_ztest_run_test_suite(#suite, _##suite)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Run the specified test suite.

Parameters
suiteTest suite to run.

◆ ZTEST_SECTION

◆ ztest_test_suite

#define ztest_test_suite (   suite,
  ... 
)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Value:
static ZTEST_DMEM struct unit_test _##suite[] = { \
__VA_ARGS__, { 0 } \
}
#define ZTEST_DMEM
Definition: ztest_test.h:168
Definition: ztest_test.h:22

Define a test suite.

This function should be called in the following fashion:

ztest_test_suite(test_suite_name,
ztest_unit_test(test_function),
ztest_unit_test(test_other_function)
);
ztest_run_test_suite(test_suite_name);
#define ztest_test_suite(suite,...)
Define a test suite.
Definition: ztest_test.h:193
#define ztest_run_test_suite(suite)
Run the specified test suite.
Definition: ztest_test.h:202
#define ztest_unit_test(fn)
Define a test function.
Definition: ztest_test.h:117
Parameters
suiteName of the testing suite

◆ ztest_unit_test

#define ztest_unit_test (   fn)     ztest_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Define a test function.

This should be called as an argument to ztest_test_suite.

Parameters
fnTest function

◆ ztest_unit_test_setup_teardown

#define ztest_unit_test_setup_teardown (   fn,
  setup,
  teardown 
)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Value:
{ \
STRINGIFY(fn), fn, setup, teardown, 0 \
}

Define a test with setup and teardown functions.

This should be called as an argument to ztest_test_suite. The test will be run in the following order: setup, fn, teardown.

Parameters
fnMain test function
setupSetup function
teardownTeardown function

◆ ztest_user_unit_test

#define ztest_user_unit_test (   fn)     ztest_user_unit_test_setup_teardown(fn, unit_test_noop, unit_test_noop)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Define a test function that should run as a user thread.

This should be called as an argument to ztest_test_suite. If CONFIG_USERSPACE is not enabled, this is functionally identical to ztest_unit_test().

Parameters
fnTest function

◆ ztest_user_unit_test_setup_teardown

#define ztest_user_unit_test_setup_teardown (   fn,
  setup,
  teardown 
)

#include <subsys/testsuite/ztest/include/ztest_test.h>

Value:
{ \
STRINGIFY(fn), fn, setup, teardown, K_USER \
}
#define K_USER
user mode thread
Definition: kernel.h:191

Define a user mode test with setup and teardown functions.

This should be called as an argument to ztest_test_suite. The test will be run in the following order: setup, fn, teardown. ALL test functions will be run in user mode, and only if CONFIG_USERSPACE is enabled, otherwise this is the same as ztest_unit_test_setup_teardown().

Parameters
fnMain test function
setupSetup function
teardownTeardown function

Function Documentation

◆ unit_test_noop()

static void unit_test_noop ( void  )
inlinestatic

#include <subsys/testsuite/ztest/include/ztest_test.h>

Do nothing, successfully.

Unit test / setup function / teardown function that does nothing, successfully. Can be used as a parameter to ztest_unit_test_setup_teardown().

◆ ztest_test_fail()

void ztest_test_fail ( void  )

#include <subsys/testsuite/ztest/include/ztest_test.h>

Fail the currently running test.

This is the function called from failed assertions and the like. You probably don't need to call it yourself.

◆ ztest_test_pass()

void ztest_test_pass ( void  )

#include <subsys/testsuite/ztest/include/ztest_test.h>

Pass the currently running test.

Normally a test passes just by returning without an assertion failure. However, if the success case for your test involves a fatal fault, you can call this function from k_sys_fatal_error_handler to indicate that the test passed before aborting the thread.

◆ ztest_test_skip()

void ztest_test_skip ( void  )

#include <subsys/testsuite/ztest/include/ztest_test.h>

Skip the current test.

Variable Documentation

◆ ztest_mem_partition

struct k_mem_partition ztest_mem_partition
extern