test: Support an init/uninit functions for test suites

Some suites need things to be set up before they can run. Add a way to
declare an init function using the UNIT_TEST_INIT() macro. The init
function is just like any other test, but is always placed first so that
it runs before all the other test functions in the suite.

Add an uninit function as well, to clean up after the test.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-02-07 11:30:38 -07:00
committed by Tom Rini
parent 63adc40d4c
commit c908ecb7b5
2 changed files with 22 additions and 1 deletions

View File

@@ -620,7 +620,8 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
const char *test_name = test->name;
int ret, i, old_fail_count;
if (!test_matches(prefix, test_name, select_name))
if (!(test->flags & (UTF_INIT | UTF_UNINIT)) &&
!test_matches(prefix, test_name, select_name))
continue;
if (test->flags & UTF_MANUAL) {