diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-06-04 10:46:58 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-06-09 12:20:05 +0200 |
commit | 7457c3d1d457922772e8bb7e07e3e9fe7dd0e09d (patch) | |
tree | a18ab27a128c0e99c153c16b64e19ded98557ca5 /test | |
parent | ff10a9966637f65efe2c82f65ad2b76e34f3774c (diff) | |
download | barebox-7457c3d1d457922772e8bb7e07e3e9fe7dd0e09d.tar.gz barebox-7457c3d1d457922772e8bb7e07e3e9fe7dd0e09d.tar.xz |
test: add basic barebox self-test infrastructure
Self tests is code written to run within barebox to exercise
functionality. They offer flexibility to test specific units of barebox
instead of the program as a whole. Add a very simple infrastructure
for registering and executing self-tests. This is based on the Linux
kselftest modules. We don't utilize modules for this, however, because
we only have module support on ARM, but we need a generic solution.
Selftests can be enabled individually and even tested without shell
support to allow tests to happen for size-restricted barebox images
as well.
Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20210604084704.17410-8-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/Kconfig | 8 | ||||
-rw-r--r-- | test/Makefile | 1 | ||||
-rw-r--r-- | test/self/Kconfig | 33 | ||||
-rw-r--r-- | test/self/Makefile | 3 | ||||
-rw-r--r-- | test/self/core.c | 22 |
5 files changed, 67 insertions, 0 deletions
diff --git a/test/Kconfig b/test/Kconfig new file mode 100644 index 0000000000..eece702e68 --- /dev/null +++ b/test/Kconfig @@ -0,0 +1,8 @@ +menuconfig TEST + bool "Testing" + +if TEST + +source "test/self/Kconfig" + +endif diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000000..1b9eb2171a --- /dev/null +++ b/test/Makefile @@ -0,0 +1 @@ +obj-y += self/ diff --git a/test/self/Kconfig b/test/self/Kconfig new file mode 100644 index 0000000000..720abeffc5 --- /dev/null +++ b/test/self/Kconfig @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0 + +config SELFTEST + bool "Self-tests" + help + Configures support for in-barebox testing + +if SELFTEST + +config CMD_SELFTEST + bool "selftest command" + depends on COMMAND_SUPPORT + help + Command to run enabled barebox self-tests. + If run without arguments, all tests are run + + Usage: selftest [-l] [tests...] + + Options: + -l list available tests + +config SELFTEST_AUTORUN + bool "Run self-tests on startup" + help + Self tests are run automatically after initcalls are done, + but before barebox_main (shell or board-specific startup). + +config SELFTEST_ENABLE_ALL + bool "Enable all self-tests" + help + Selects all self-tests compatible with current configuration + +endif diff --git a/test/self/Makefile b/test/self/Makefile new file mode 100644 index 0000000000..78f738c8e2 --- /dev/null +++ b/test/self/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_SELFTEST) += core.o diff --git a/test/self/core.c b/test/self/core.c new file mode 100644 index 0000000000..caa4c27f6d --- /dev/null +++ b/test/self/core.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#define pr_fmt(fmt) "bselftest: " fmt + +#include <common.h> +#include <bselftest.h> + +LIST_HEAD(selftests); + +void selftests_run(void) +{ + struct selftest *test; + int err = 0; + + pr_notice("Configured tests will run now\n"); + + list_for_each_entry(test, &selftests, list) + err |= test->func(); + + if (err) + pr_err("Some selftests failed\n"); +} |