* [PATCH] test: self: provide selftest_is_running()
@ 2022-09-05 7:01 Ahmad Fatoum
2022-09-13 8:14 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-09-05 7:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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@pengutronix.de>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] test: self: provide selftest_is_running()
2022-09-05 7:01 [PATCH] test: self: provide selftest_is_running() Ahmad Fatoum
@ 2022-09-13 8:14 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-09-13 8:14 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Sep 05, 2022 at 09:01:25AM +0200, Ahmad Fatoum wrote:
> 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@pengutronix.de>
> ---
> commands/selftest.c | 2 +-
> include/bselftest.h | 5 +++++
> test/self/core.c | 26 +++++++++++++++++++++++++-
> 3 files changed, 31 insertions(+), 2 deletions(-)
Applied, thanks
Sascha
>
> 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
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-13 8:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 7:01 [PATCH] test: self: provide selftest_is_running() Ahmad Fatoum
2022-09-13 8:14 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox