Skip to content

Commit

Permalink
kunit: Add 'kunit_shutdown' option
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Gow authored and Shuah Khan committed Jun 11, 2021
1 parent 384426b commit b6d5799
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/kunit/executor.c
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +130,8 @@ int kunit_run_all_tests(void)
kfree(suite_set.start);
}

kunit_handle_shutdown();

return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/kunit/kunit_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def build_um_kernel(self, alltests, jobs, build_dir, make_options) -> bool:
def run_kernel(self, args=None, build_dir='', filter_glob='', timeout=None) -> Iterator[str]:
if not args:
args = []
args.extend(['mem=1G', 'console=tty'])
args.extend(['mem=1G', 'console=tty', 'kunit_shutdown=halt'])
if filter_glob:
args.append('kunit.filter_glob='+filter_glob)
self._ops.linux_bin(args, timeout, build_dir)
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/kunit/kunit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestStatus(Enum):

kunit_start_re = re.compile(r'TAP version [0-9]+$')
kunit_end_re = re.compile('(List of all partitions:|'
'Kernel panic - not syncing: VFS:)')
'Kernel panic - not syncing: VFS:|reboot: System halted)')

def isolate_kunit_output(kernel_output) -> Iterator[str]:
started = False
Expand Down

0 comments on commit b6d5799

Please sign in to comment.