Set global current_test_metadata for each test run so other test frameworks can choose to access fields for the current test.
This avoids having to pass _metadata down through functions so that code defined other functions can still use fields in _metadata. Test functions t->fn() are executed in series, so during the runtime of the test function, the function can count on current_test_metadata accurately being the metadata for the running test. Signed-off-by: Ackerley Tng <[email protected]> --- tools/testing/selftests/kselftest_harness.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 68cde1556ac41..85d9b4527fca6 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -1151,6 +1151,8 @@ static bool test_enabled(int argc, char **argv, return !has_positive; } +struct __test_metadata *current_test_metadata; + static void __run_test(struct __fixture_metadata *f, struct __fixture_variant_metadata *variant, struct __test_metadata *t) @@ -1182,7 +1184,9 @@ static void __run_test(struct __fixture_metadata *f, t->exit_code = KSFT_FAIL; } else if (child == 0) { setpgrp(); + current_test_metadata = t; t->fn(t, variant); + current_test_metadata = NULL; _exit(t->exit_code); } else { t->pid = child; -- 2.54.0.rc0.605.g598a273b03-goog

