Skip to content

Commit 236fe51

Browse files
author
Yuval Peress
committed
ztest: document test rules
Add documentation to test rules. Signed-off-by: Yuval Peress <[email protected]>
1 parent 140837c commit 236fe51

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

subsys/testsuite/ztest/include/ztest_test_new.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,34 @@ static inline void unit_test_noop(void)
253253
*/
254254
#define ZTEST_USER_F(suite, fn) Z_ZTEST_F(suite, fn, COND_CODE_1(CONFIG_USERSPACE, (K_USER), (0)))
255255

256+
/**
257+
* @brief Test rule callback function signature
258+
*
259+
* The function signature that can be used to register a test rule's before/after callback. This
260+
* provides access to the test and the fixture data (if provided).
261+
*
262+
* @param test Pointer to the unit test in context
263+
* @param data Pointer to the test's fixture data (may be NULL)
264+
*/
256265
typedef void (*ztest_rule_cb)(const struct ztest_unit_test *test, void *data);
257266

258267
struct ztest_test_rule {
259268
ztest_rule_cb before_each;
260269
ztest_rule_cb after_each;
261270
};
262271

272+
/**
273+
* @brief Define a test rule that will run before/after each unit test.
274+
*
275+
* Functions defined here will run before/after each unit test for every test suite. Along with the
276+
* callback, the test functions are provided a pointer to the test being run, and the data. This
277+
* provides a mechanism for tests to perform custom operations depending on the specific test or
278+
* the data (for example logging may use the test's name).
279+
*
280+
* @param name The name for the test rule (must be unique within the compilational unit)
281+
* @param before_each_fn The callback function to call before each test (may be NULL)
282+
* @param after_each_fn The callback function to call after each test (may be NULL)
283+
*/
263284
#define ZTEST_RULE(name, before_each_fn, after_each_fn) \
264285
static STRUCT_SECTION_ITERABLE(ztest_test_rule, z_ztest_test_rule_##name) = { \
265286
.before_each = (before_each_fn), \

0 commit comments

Comments
 (0)