kunit: Add 'kunit_shutdown' option

This adds a new kernel command-line option, 'kunit_shutdown', which
shuts the kernel down (halts the machine) after tests are complete.

It also updates kunit_tool to use this option, and recognise the kernel
shutting down as the end of the test.

Change-Id: I5b2b25d767f7af4d80c0bc4ae2967bfaf18c73b0
Signed-off-by: David Gow <davidgow@google.com>
diff --git a/test/test-executor.c b/test/test-executor.c
index d117e96..2cb8bb3 100644
--- a/test/test-executor.c
+++ b/test/test-executor.c
@@ -1,10 +1,15 @@
 #include <linux/init.h>
+#include <linux/moduleparam.h>
 #include <linux/printk.h>
+#include <linux/reboot.h>
 #include <test/test.h>
 
 extern char __test_modules_start;
 extern char __test_modules_end;
 
+static int kunit_shutdown;
+core_param(kunit_shutdown, kunit_shutdown, int, 0644);
+
 static bool test_run_all_tests(void)
 {
 	struct test_module **module;
@@ -19,6 +24,9 @@
 			has_test_failed = true;
 	}
 
+	if (kunit_shutdown)
+		kernel_halt();
+
 	return !has_test_failed;
 }
 
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 76420d2..ff0968b 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -155,7 +155,7 @@
 		return BuildResult(BuildStatus.SUCCESS, 'Built kernel!')
 
 	def run_kernel(self, args=[], timeout=None):
-		args.extend(['mem=256M'])
+		args.extend(['mem=256M kunit_shutdown=1'])
 		raw_log = self._ops.linux_bin(args, timeout)
 		with open('test.log', 'w') as f:
 			for line in raw_log.split('\n'):
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 4d65e0a..bc63ada 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -29,7 +29,7 @@
 TestCase = namedtuple('TestCase', ['status','name','log'])
 
 kunit_start_re = re.compile('console .* enabled')
-kunit_end_re = re.compile('List of all partitions:')
+kunit_end_re = re.compile('reboot: System halted')
 
 TIMED_OUT_LOG_ENTRY = 'Timeout Reached - Process Terminated'
 
diff --git a/tools/testing/kunit/kunit_test.py b/tools/testing/kunit/kunit_test.py
index 6471a93..7e3be7a 100755
--- a/tools/testing/kunit/kunit_test.py
+++ b/tools/testing/kunit/kunit_test.py
@@ -180,7 +180,7 @@
 							kunit_kernel.BuildStatus.SUCCESS, ''))
 		self.linux_source_mock.run_kernel = mock.Mock(return_value=[
 				'console 0 enabled',
-				'List of all partitions:'])
+				'reboot: System halted'])
 
 	def tearDown(self):
 		self.print_patch.stop()
diff --git a/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log b/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log
index c553ca5..d0900d1 100644
--- a/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log
+++ b/tools/testing/kunit/test_data/test_is_test_passed-no_tests_run.log
@@ -69,7 +69,4 @@
 Console initialized on /dev/tty0
 console [tty0] enabled
 console [mc-1] enabled
-List of all partitions:
-No filesystem could mount root, tried: 
-
-Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0)
+reboot: System halted
diff --git a/tools/testing/kunit/test_data/test_output_isolated_correctly.log b/tools/testing/kunit/test_data/test_output_isolated_correctly.log
index c1ec856..3c63bea 100644
--- a/tools/testing/kunit/test_data/test_output_isolated_correctly.log
+++ b/tools/testing/kunit/test_data/test_output_isolated_correctly.log
@@ -61,4 +61,4 @@
 kunit example: initializing
 kunit example: example_mock_test passed
 kunit example: all tests passed
-List of all partitions:
+reboot: System halted