summaryrefslogtreecommitdiff
path: root/lib/kunit
diff options
context:
space:
mode:
authorDavid Gow <davidgow@google.com>2021-05-27 00:24:04 +0300
committerShuah Khan <skhan@linuxfoundation.org>2021-06-12 01:04:57 +0300
commitb6d5799b0b5866dc63be7f032473dc536f865b4d (patch)
tree11bdd407b115e0cf4d970236020b739241d339ce /lib/kunit
parent384426bd101cb3cd580b18de19d4891ec5ca5bf9 (diff)
downloadlinux-b6d5799b0b5866dc63be7f032473dc536f865b4d.tar.xz
kunit: Add 'kunit_shutdown' option
Add a new kernel command-line option, 'kunit_shutdown', which allows the user to specify that the kernel poweroff, halt, or reboot after completing all KUnit tests; this is very handy for running KUnit tests on UML or a VM so that the UML/VM process exits cleanly immediately after running all tests without needing a special initramfs. Signed-off-by: David Gow <davidgow@google.com> Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Stephen Boyd <sboyd@kernel.org> Tested-By: Daniel Latypov <dlatypov@google.com> Reviewed-by: Daniel Latypov <dlatypov@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/kunit')
-rw-r--r--lib/kunit/executor.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 15832ed44668..7db619624437 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
+#include <linux/reboot.h>
#include <kunit/test.h>
#include <linux/glob.h>
#include <linux/moduleparam.h>
@@ -18,6 +19,9 @@ module_param(filter_glob, charp, 0);
MODULE_PARM_DESC(filter_glob,
"Filter which KUnit test suites run at boot-time, e.g. list*");
+static char *kunit_shutdown;
+core_param(kunit_shutdown, kunit_shutdown, charp, 0644);
+
static struct kunit_suite * const *
kunit_filter_subsuite(struct kunit_suite * const * const subsuite)
{
@@ -82,6 +86,20 @@ static struct suite_set kunit_filter_suites(void)
return filtered;
}
+static void kunit_handle_shutdown(void)
+{
+ if (!kunit_shutdown)
+ return;
+
+ if (!strcmp(kunit_shutdown, "poweroff"))
+ kernel_power_off();
+ else if (!strcmp(kunit_shutdown, "halt"))
+ kernel_halt();
+ else if (!strcmp(kunit_shutdown, "reboot"))
+ kernel_restart(NULL);
+
+}
+
static void kunit_print_tap_header(struct suite_set *suite_set)
{
struct kunit_suite * const * const *suites, * const *subsuite;
@@ -112,6 +130,8 @@ int kunit_run_all_tests(void)
kfree(suite_set.start);
}
+ kunit_handle_shutdown();
+
return 0;
}