@@ -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+ */
256265typedef void (* ztest_rule_cb )(const struct ztest_unit_test * test , void * data );
257266
258267struct 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