For debugging during self-test run, it can be useful to enable select logging only when the selftest is running. Provide a selftest_is_running() function that can be used to determine whether a test is running. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- commands/selftest.c | 2 +- include/bselftest.h | 5 +++++ test/self/core.c | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/commands/selftest.c b/commands/selftest.c index a10f1467fece..bb62575aa7bb 100644 --- a/commands/selftest.c +++ b/commands/selftest.c @@ -24,7 +24,7 @@ static int run_selftest(const char *match, bool list) if (match && strcmp(test->name, match)) continue; - err |= test->func(); + err |= selftest_run(test); matches++; } diff --git a/include/bselftest.h b/include/bselftest.h index 21eeba0526ef..f03c803b6553 100644 --- a/include/bselftest.h +++ b/include/bselftest.h @@ -15,6 +15,7 @@ struct selftest { const char *name; int (*func)(void); struct list_head list; + bool running; }; static inline int selftest_report(unsigned int total_tests, unsigned int failed_tests, @@ -71,4 +72,8 @@ static inline void selftests_run(void) } \ __bselftest_initcall(_func##_bselftest_register); + +int selftest_run(struct selftest *test); +bool selftest_is_running(struct selftest *test); + #endif diff --git a/test/self/core.c b/test/self/core.c index caa4c27f6def..40f5ee842d16 100644 --- a/test/self/core.c +++ b/test/self/core.c @@ -7,6 +7,30 @@ LIST_HEAD(selftests); +int selftest_run(struct selftest *test) +{ + int err; + + test->running = true; + err = test->func(); + test->running = false; + + return err; +} + +bool selftest_is_running(struct selftest *test) +{ + if (test) + return test->running; + + list_for_each_entry(test, &selftests, list) { + if (selftest_is_running(test)) + return true; + } + + return false; +} + void selftests_run(void) { struct selftest *test; @@ -15,7 +39,7 @@ void selftests_run(void) pr_notice("Configured tests will run now\n"); list_for_each_entry(test, &selftests, list) - err |= test->func(); + err |= selftest_run(test); if (err) pr_err("Some selftests failed\n"); -- 2.30.2