Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Ztest testing macros

Data Structures

struct  ztest_test_rule
 

Macros

#define ZTEST(suite, fn)   Z_ZTEST(suite, fn, 0)
 Create and register a new unit test. More...
 
#define ZTEST_USER(suite, fn)   Z_ZTEST(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
 Define a test function that should run as a user thread. More...
 
#define ZTEST_F(suite, fn)   Z_ZTEST_F(suite, fn, 0)
 Define a test function. More...
 
#define ZTEST_USER_F(suite, fn)   Z_ZTEST_F(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
 Define a test function that should run as a user thread. More...
 
#define ZTEST_RULE(name, before_each_fn, after_each_fn)
 Define a test rule that will run before/after each unit test. 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_run_test_suite(suite)   z_ztest_run_test_suite(STRINGIFY(suite))
 Run the specified test suite. More...
 

Typedefs

typedef void(* ztest_rule_cb) (const struct ztest_unit_test *test, void *data)
 Test rule callback function signature. 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...
 
void ztest_simple_1cpu_before (void *data)
 A 'before' function to use in test suites that just need to start 1cpu. More...
 
void ztest_simple_1cpu_after (void *data)
 A 'after' function to use in test suites that just need to stop 1cpu. 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

#define ZTEST (   suite,
  fn 
)    Z_ZTEST(suite, fn, 0)

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

Create and register a new unit test.

Calling this macro will create a new unit test and attach it to the declared suite. The suite does not need to be defined in the same compilational unit.

Parameters
suiteThe name of the test suite to attach this test
fnThe test function to call.

◆ ZTEST_BMEM

◆ ZTEST_DMEM

◆ ZTEST_F

#define ZTEST_F (   suite,
  fn 
)    Z_ZTEST_F(suite, fn, 0)

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

Define a test function.

This macro behaves exactly the same as ZTEST(), but the function takes an argument for the fixture of type struct suite##_fixture* named this.

Parameters
suiteThe name of the test suite to attach this test
fnThe test function to call.

◆ ZTEST_RULE

#define ZTEST_RULE (   name,
  before_each_fn,
  after_each_fn 
)

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

Value:
static STRUCT_SECTION_ITERABLE(ztest_test_rule, z_ztest_test_rule_##name) = { \
.before_each = (before_each_fn), \
.after_each = (after_each_fn), \
}
#define STRUCT_SECTION_ITERABLE(struct_type, name)
Defines a new iterable section.
Definition: common.h:210
Definition: ztest_test_new.h:268

Define a test rule that will run before/after each unit test.

Functions defined here will run before/after each unit test for every test suite. Along with the callback, the test functions are provided a pointer to the test being run, and the data. This provides a mechanism for tests to perform custom operations depending on the specific test or the data (for example logging may use the test's name).

Parameters
nameThe name for the test rule (must be unique within the compilational unit)
before_each_fnThe callback function to call before each test (may be NULL)
after_each_fnThe callback function to call after each test (may be NULL)

◆ ztest_run_test_suite

#define ztest_run_test_suite (   suite)    z_ztest_run_test_suite(STRINGIFY(suite))

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

Run the specified test suite.

Parameters
suiteTest suite to run.

◆ ZTEST_SECTION

◆ ZTEST_USER

#define ZTEST_USER (   suite,
  fn 
)    Z_ZTEST(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))

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

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

This macro behaves exactly the same as ZTEST, but calls the test function in user space if CONFIG_USERSPACE was enabled.

Parameters
suiteThe name of the test suite to attach this test
fnThe test function to call.

◆ ZTEST_USER_F

#define ZTEST_USER_F (   suite,
  fn 
)    Z_ZTEST_F(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))

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

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

If CONFIG_USERSPACE is not enabled, this is functionally identical to ZTEST_F(). The test function takes a single fixture argument of type struct suite##_fixture* named this.

Parameters
suiteThe name of the test suite to attach this test
fnThe test function to call.

Typedef Documentation

◆ ztest_rule_cb

typedef void(* ztest_rule_cb) (const struct ztest_unit_test *test, void *data)

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

Test rule callback function signature.

The function signature that can be used to register a test rule's before/after callback. This provides access to the test and the fixture data (if provided).

Parameters
testPointer to the unit test in context
dataPointer to the test's fixture data (may be NULL)

Function Documentation

◆ unit_test_noop()

static void unit_test_noop ( void  )
inlinestatic

#include <subsys/testsuite/ztest/include/ztest_test_new.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_simple_1cpu_after()

void ztest_simple_1cpu_after ( void *  data)

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

A 'after' function to use in test suites that just need to stop 1cpu.

Ignores data, and calls z_test_1cpu_stop()

Parameters
dataThe test suite's data

◆ ztest_simple_1cpu_before()

void ztest_simple_1cpu_before ( void *  data)

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

A 'before' function to use in test suites that just need to start 1cpu.

Ignores data, and calls z_test_1cpu_start()

Parameters
dataThe test suite's data

◆ ztest_test_fail()

void ztest_test_fail ( void  )

#include <subsys/testsuite/ztest/include/ztest_test_new.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_new.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_new.h>

Skip the current test.

Variable Documentation

◆ ztest_mem_partition

struct k_mem_partition ztest_mem_partition
extern