Skip to contentSkip to conversation

Kselftest-kunit update for Linux 5.7-rc1

GIT PULL Merged Shuah Khan 2 participants 2 messages Apr 1, 2020

Subsystems (5)
lore
Share & tools
lore

Shuah Khan

author maintainer
#0 lore raw

Hi Linus,

Please pull the following Kselftest Kunit update for Linux 5.7-rc1.

This kunit update for Linux-5.7-rc1 consists of:

- debugfs support for displaying kunit test suite results; this is especially useful for module-loaded tests to allow disentangling of test result display from other dmesg events. CONFIG_KUNIT_DEBUGFS enables/disables the debugfs support.

- Several fixes and improvements to kunit framework and tool.

diff is attached.

thanks,
-- Shuah

----------------------------------------------------------------
The following changes since commit 2c523b344dfa65a3738e7039832044aa133c75fb:

Linux 5.6-rc5 (2020-03-08 17:44:44 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
tags/linux-kselftest-kunit-5.7-rc1

for you to fetch changes up to e23349af9ee25a5760112a2f8476b94a4ec86f1c:

kunit: tool: add missing test data file content (2020-03-26 14:11:12
-0600)

----------------------------------------------------------------
linux-kselftest-kunit-5.7-rc1

This kunit update for Linux-5.7-rc1 consists of:

- debugfs support for displaying kunit test suite results; this is especially useful for module-loaded tests to allow disentangling of test result display from other dmesg events. CONFIG_KUNIT_DEBUGFS enables/disables the debugfs support.

- Several fixes and improvements to kunit framework and tool.

----------------------------------------------------------------
Alan Maguire (4):
kunit: add debugfs /sys/kernel/debug/kunit/<suite>/results display
kunit: add log test
kunit: subtests should be indented 4 spaces according to TAP
kunit: update documentation to describe debugfs representation

Brendan Higgins (1):
kunit: tool: add missing test data file content

David Gow (4):
kunit: Always print actual pointer values in asserts
kunit: kunit_tool: Allow .kunitconfig to disable config items Fix linked-list KUnit test when run multiple times
Documentation: kunit: Make the KUnit documentation less UML-specific

Greg Thelen (1):

      kunit: add --make_options

Heidi Fahim (2):
kunit: kunit_parser: make parser more robust
kunit: Run all KUnit tests through allyesconfig

 Documentation/dev-tools/kunit/index.rst            |  40 +++---
 Documentation/dev-tools/kunit/kunit-tool.rst       |   7 +
 Documentation/dev-tools/kunit/start.rst            |  80 +++++++++--
 Documentation/dev-tools/kunit/usage.rst            |  14 ++
 include/kunit/test.h                               |  63 +++++++--
 lib/kunit/Kconfig                                  |   8 ++
 lib/kunit/Makefile                                 |   4 +
 lib/kunit/assert.c                                 |  79 +++++------
 lib/kunit/debugfs.c                                | 116 ++++++++++++++++
 lib/kunit/debugfs.h                                |  30 +++++
 lib/kunit/kunit-test.c                             |  44 +++++-
lib/kunit/test.c                                   | 148 ++++++++++++++++-----
 lib/list-test.c                                    |   4 +-
 tools/testing/kunit/.gitattributes                 |   1 +
 tools/testing/kunit/configs/broken_on_uml.config   |  41 ++++++
 tools/testing/kunit/kunit.py                       |  38 ++++--
 tools/testing/kunit/kunit_config.py                |  41 ++++--
 tools/testing/kunit/kunit_kernel.py                |  84 ++++++++----
 tools/testing/kunit/kunit_parser.py                |  51 +++----
 tools/testing/kunit/kunit_tool_test.py             | 108 ++++++++++++---
 .../kunit/test_data/test_config_printk_time.log    | Bin 0 -> 1584 bytes
 .../test_data/test_interrupted_tap_output.log      | Bin 0 -> 1982 bytes
 .../test_data/test_kernel_panic_interrupt.log      | Bin 0 -> 1321 bytes
 .../kunit/test_data/test_multiple_prefixes.log     | Bin 0 -> 1832 bytes
 .../test_output_with_prefix_isolated_correctly.log | Bin 0 -> 1655 bytes
 .../kunit/test_data/test_pound_no_prefix.log       | Bin 0 -> 1193 bytes
 tools/testing/kunit/test_data/test_pound_sign.log  | Bin 0 -> 1656 bytes
 27 files changed, 799 insertions(+), 202 deletions(-)
 create mode 100644 lib/kunit/debugfs.c
 create mode 100644 lib/kunit/debugfs.h
 create mode 100644 tools/testing/kunit/.gitattributes
 create mode 100644 tools/testing/kunit/configs/broken_on_uml.config
 create mode 100644 
tools/testing/kunit/test_data/test_config_printk_time.log
 create mode 100644 
tools/testing/kunit/test_data/test_interrupted_tap_output.log
 create mode 100644 
tools/testing/kunit/test_data/test_kernel_panic_interrupt.log
 create mode 100644 
tools/testing/kunit/test_data/test_multiple_prefixes.log
 create mode 100644 
tools/testing/kunit/test_data/test_output_with_prefix_isolated_correctly.log
 create mode 100644 tools/testing/kunit/test_data/test_pound_no_prefix.log
 create mode 100644 tools/testing/kunit/test_data/test_pound_sign.log

----------------------------------------------------------------

Documentation/dev-tools/kunit/index.rst +25 -15
index d16a4d2c3a41..e93606ecfb01 100644
@@ -17,14 +17,23 @@ What is KUnit?
 ==============
 
 KUnit is a lightweight unit testing and mocking framework for the Linux kernel.
-These tests are able to be run locally on a developer's workstation without a VM
-or special hardware.
 
 KUnit is heavily inspired by JUnit, Python's unittest.mock, and
 Googletest/Googlemock for C++. KUnit provides facilities for defining unit test
 cases, grouping related test cases into test suites, providing common
 infrastructure for running tests, and much more.
 
+KUnit consists of a kernel component, which provides a set of macros for easily
+writing unit tests. Tests written against KUnit will run on kernel boot if
+built-in, or when loaded if built as a module. These tests write out results to
+the kernel log in `TAP <https://testanything.org/>`_ format.
+
+To make running these tests (and reading the results) easier, KUnit offers
+:doc:`kunit_tool <kunit-tool>`, which builds a `User Mode Linux
+<http://user-mode-linux.sourceforge.net>`_ kernel, runs it, and parses the test
+results. This provides a quick way of running KUnit tests during development,
+without requiring a virtual machine or separate hardware.
+
 Get started now: :doc:`start`
 
 Why KUnit?
@@ -36,21 +45,20 @@ allow all possible code paths to be tested in the code under test; this is only
 possible if the code under test is very small and does not have any external
 dependencies outside of the test's control like hardware.
 
-Outside of KUnit, there are no testing frameworks currently
-available for the kernel that do not require installing the kernel on a test
-machine or in a VM and all require tests to be written in userspace running on
-the kernel; this is true for Autotest, and kselftest, disqualifying
-any of them from being considered unit testing frameworks.
+KUnit provides a common framework for unit tests within the kernel.
+
+KUnit tests can be run on most architectures, and most tests are architecture
+independent. All built-in KUnit tests run on kernel startup.  Alternatively,
+KUnit and KUnit tests can be built as modules and tests will run when the test
+module is loaded.
 
-KUnit addresses the problem of being able to run tests without needing a virtual
-machine or actual hardware with User Mode Linux. User Mode Linux is a Linux
-architecture, like ARM or x86; however, unlike other architectures it compiles
-to a standalone program that can be run like any other program directly inside
-of a host operating system; to be clear, it does not require any virtualization
-support; it is just a regular program.
+.. note::
 
-Alternatively, kunit and kunit tests can be built as modules and tests will
-run when the test module is loaded.
+        KUnit can also run tests without needing a virtual machine or actual
+        hardware under User Mode Linux. User Mode Linux is a Linux architecture,
+        like ARM or x86, which compiles the kernel as a Linux executable. KUnit
+        can be used with UML either by building with ``ARCH=um`` (like any other
+        architecture), or by using :doc:`kunit_tool <kunit-tool>`.
 
 KUnit is fast. Excluding build time, from invocation to completion KUnit can run
 several dozen tests in only 10 to 20 seconds; this might not sound like a big
@@ -81,3 +89,5 @@ How do I use it?
 *   :doc:`start` - for new users of KUnit
 *   :doc:`usage` - for a more detailed explanation of KUnit features
 *   :doc:`api/index` - for the list of KUnit APIs used for testing
+*   :doc:`kunit-tool` - for more information on the kunit_tool helper script
+*   :doc:`faq` - for answers to some common questions about KUnit
Documentation/dev-tools/kunit/kunit-tool.rst +7 -0
index 50d46394e97e..949af2da81e5 100644
@@ -12,6 +12,13 @@ the Linux kernel as UML (`User Mode Linux
 <http://user-mode-linux.sourceforge.net/>`_), running KUnit tests, parsing
 the test results and displaying them in a user friendly manner.
 
+kunit_tool addresses the problem of being able to run tests without needing a
+virtual machine or actual hardware with User Mode Linux. User Mode Linux is a
+Linux architecture, like ARM or x86; however, unlike other architectures it
+compiles the kernel as a standalone Linux executable that can be run like any
+other program directly inside of a host operating system. To be clear, it does
+not require any virtualization support: it is just a regular program.
+
 What is a kunitconfig?
 ======================
 
Documentation/dev-tools/kunit/start.rst +67 -13

106 lines not on this page · raw message

Documentation/dev-tools/kunit/usage.rst +14 -0
index 607758a66a99..473a2361ec37 100644
@@ -591,3 +591,17 @@ able to run one test case per invocation.
 
 .. TODO([email protected]): Add an actual example of an architecture
    dependent KUnit test.
+
+KUnit debugfs representation
+============================
+When kunit test suites are initialized, they create an associated directory
+in /sys/kernel/debug/kunit/<test-suite>.  The directory contains one file
+
+- results: "cat results" displays results of each test case and the results
+  of the entire suite for the last test run.
+
+The debugfs representation is primarily of use when kunit test suites are
+run in a native environment, either as modules or builtin.  Having a way
+to display results like this is valuable as otherwise results can be
+intermixed with other events in dmesg output.  The maximum size of each
+results file is KUNIT_LOG_SIZE bytes (defined in include/kunit/test.h).
include/kunit/test.h +55 -8

119 lines not on this page · raw message

lib/kunit/Kconfig +8 -0
index 065aa16f448b..95d12e3d6d95 100644
@@ -14,6 +14,14 @@ menuconfig KUNIT
 
 if KUNIT
 
+config KUNIT_DEBUGFS
+	bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation"
+	help
+	  Enable debugfs representation for kunit.  Currently this consists
+	  of /sys/kernel/debug/kunit/<test_suite>/results files for each
+	  test suite, which allow users to see results of the last test suite
+	  run that occurred.
+
 config KUNIT_TEST
 	tristate "KUnit test for KUnit"
 	help
lib/kunit/Makefile +4 -0
index fab55649b69a..724b94311ca3 100644
@@ -5,6 +5,10 @@ kunit-objs +=				test.o \
 					assert.o \
 					try-catch.o
 
+ifeq ($(CONFIG_KUNIT_DEBUGFS),y)
+kunit-objs +=				debugfs.o
+endif
+
 obj-$(CONFIG_KUNIT_TEST) +=		kunit-test.o
 
 # string-stream-test compiles built-in only.
lib/kunit/assert.c +40 -39

119 lines not on this page · raw message

lib/kunit/debugfs.c new file +116 -0

116 lines not on this page · raw message

lib/kunit/debugfs.h new file +30 -0
new file mode 100644
index 000000000000..dcc7d7556107
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020, Oracle and/or its affiliates.
+ */
+
+#ifndef _KUNIT_DEBUGFS_H
+#define _KUNIT_DEBUGFS_H
+
+#include <kunit/test.h>
+
+#ifdef CONFIG_KUNIT_DEBUGFS
+
+void kunit_debugfs_create_suite(struct kunit_suite *suite);
+void kunit_debugfs_destroy_suite(struct kunit_suite *suite);
+void kunit_debugfs_init(void);
+void kunit_debugfs_cleanup(void);
+
+#else
+
+static inline void kunit_debugfs_create_suite(struct kunit_suite *suite) { }
+
+static inline void kunit_debugfs_destroy_suite(struct kunit_suite *suite) { }
+
+static inline void kunit_debugfs_init(void) { }
+
+static inline void kunit_debugfs_cleanup(void) { }
+
+#endif /* CONFIG_KUNIT_DEBUGFS */
+
+#endif /* _KUNIT_DEBUGFS_H */
lib/kunit/kunit-test.c +41 -3

61 lines not on this page · raw message

lib/kunit/test.c +117 -31

257 lines not on this page · raw message

lib/list-test.c +2 -2
index 76babb1df889..ee09505df16f 100644
@@ -659,7 +659,7 @@ static void list_test_list_for_each_prev_safe(struct kunit *test)
 static void list_test_list_for_each_entry(struct kunit *test)
 {
 	struct list_test_struct entries[5], *cur;
-	static LIST_HEAD(list);
+	LIST_HEAD(list);
 	int i = 0;
 
 	for (i = 0; i < 5; ++i) {
@@ -680,7 +680,7 @@ static void list_test_list_for_each_entry(struct kunit *test)
 static void list_test_list_for_each_entry_reverse(struct kunit *test)
 {
 	struct list_test_struct entries[5], *cur;
-	static LIST_HEAD(list);
+	LIST_HEAD(list);
 	int i = 0;
 
 	for (i = 0; i < 5; ++i) {
tools/testing/kunit/.gitattributes new file +1 -0
new file mode 100644
index 000000000000..5b7da1fc3b8f
@@ -0,0 +1 @@
+test_data/* binary
tools/testing/kunit/configs/broken_on_uml.config new file +41 -0

41 lines not on this page · raw message

tools/testing/kunit/kunit.py +25 -13
index 180ad1e1b04f..7dca74774dd2 100755
@@ -22,7 +22,9 @@ import kunit_parser
 
 KunitResult = namedtuple('KunitResult', ['status','result'])
 
-KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs', 'build_dir', 'defconfig'])
+KunitRequest = namedtuple('KunitRequest', ['raw_output','timeout', 'jobs',
+					   'build_dir', 'defconfig',
+					   'alltests', 'make_options'])
 
 KernelDirectoryPath = sys.argv[0].split('tools/testing/kunit/')[0]
 
@@ -47,7 +49,7 @@ def get_kernel_root_path():
 def run_tests(linux: kunit_kernel.LinuxSourceTree,
 	      request: KunitRequest) -> KunitResult:
 	config_start = time.time()
-	success = linux.build_reconfig(request.build_dir)
+	success = linux.build_reconfig(request.build_dir, request.make_options)
 	config_end = time.time()
 	if not success:
 		return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel')
@@ -55,24 +57,24 @@ def run_tests(linux: kunit_kernel.LinuxSourceTree,
 	kunit_parser.print_with_timestamp('Building KUnit Kernel ...')
 
 	build_start = time.time()
-	success = linux.build_um_kernel(request.jobs, request.build_dir)
+	success = linux.build_um_kernel(request.alltests,
+					request.jobs,
+					request.build_dir,
+					request.make_options)
 	build_end = time.time()
 	if not success:
 		return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel')
 
 	kunit_parser.print_with_timestamp('Starting KUnit Kernel ...')
 	test_start = time.time()
-
-	test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS,
-					      [],
-					      'Tests not Parsed.')
+	kunit_output = linux.run_kernel(
+		timeout=None if request.alltests else request.timeout,
+		build_dir=request.build_dir)
 	if request.raw_output:
-		kunit_parser.raw_output(
-			linux.run_kernel(timeout=request.timeout,
-					 build_dir=request.build_dir))
+		raw_output = kunit_parser.raw_output(kunit_output)
+		isolated = list(kunit_parser.isolate_kunit_output(raw_output))
+		test_result = kunit_parser.parse_test_result(isolated)
 	else:
-		kunit_output = linux.run_kernel(timeout=request.timeout,
-						build_dir=request.build_dir)
 		test_result = kunit_parser.parse_run_tests(kunit_output)
 	test_end = time.time()
 
@@ -120,6 +122,14 @@ def main(argv, linux=None):
 				help='Uses a default .kunitconfig.',
 				action='store_true')
 
+	run_parser.add_argument('--alltests',
+				help='Run all KUnit tests through allyesconfig',
+				action='store_true')
+
+	run_parser.add_argument('--make_options',
+				help='X=Y make option, can be repeated.',
+				action='append')
+
 	cli_args = parser.parse_args(argv)
 
 	if cli_args.subcommand == 'run':
@@ -143,7 +153,9 @@ def main(argv, linux=None):
 				       cli_args.timeout,
 				       cli_args.jobs,
 				       cli_args.build_dir,
-				       cli_args.defconfig)
+				       cli_args.defconfig,
+				       cli_args.alltests,
+				       cli_args.make_options)
 		result = run_tests(linux, request)
 		if result.status != KunitStatus.SUCCESS:
 			sys.exit(1)
tools/testing/kunit/kunit_config.py +32 -9

64 lines not on this page · raw message

tools/testing/kunit/kunit_kernel.py +58 -26

157 lines not on this page · raw message

tools/testing/kunit/kunit_parser.py +26 -25

120 lines not on this page · raw message

tools/testing/kunit/kunit_tool_test.py +90 -18

171 lines not on this page · raw message

tools/testing/kunit/test_data/test_config_printk_time.log new file binary +0 -0
new file mode 100644
index 000000000000..c02ca773946d
Binary files /dev/null and b/tools/testing/kunit/test_data/test_config_printk_time.log differ
tools/testing/kunit/test_data/test_interrupted_tap_output.log new file binary +0 -0
new file mode 100644
index 000000000000..5c73fb3a1c6f
Binary files /dev/null and b/tools/testing/kunit/test_data/test_interrupted_tap_output.log differ
tools/testing/kunit/test_data/test_kernel_panic_interrupt.log new file binary +0 -0
new file mode 100644
index 000000000000..c045eee75f27
Binary files /dev/null and b/tools/testing/kunit/test_data/test_kernel_panic_interrupt.log differ
tools/testing/kunit/test_data/test_multiple_prefixes.log new file binary +0 -0
new file mode 100644
index 000000000000..bc48407dcc36
Binary files /dev/null and b/tools/testing/kunit/test_data/test_multiple_prefixes.log differ
tools/testing/kunit/test_data/test_output_with_prefix_isolated_correctly.log new file binary +0 -0
new file mode 100644
index 000000000000..0f87cdabebb0
Binary files /dev/null and b/tools/testing/kunit/test_data/test_output_with_prefix_isolated_correctly.log differ
tools/testing/kunit/test_data/test_pound_no_prefix.log new file binary +0 -0
new file mode 100644
index 000000000000..2ceb360be7d5
Binary files /dev/null and b/tools/testing/kunit/test_data/test_pound_no_prefix.log differ
tools/testing/kunit/test_data/test_pound_sign.log new file binary +0 -0
new file mode 100644
index 000000000000..28ffa5ba03bf
Binary files /dev/null and b/tools/testing/kunit/test_data/test_pound_sign.log differ
merge bot Merged
#1 lore raw
The pull request you sent on Wed, 1 Apr 2020 11:54:36 -0600:

The pull request you sent on Wed, 1 Apr 2020 11:54:36 -0600:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux-kselftest-kunit-5.7-rc1

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/668f1e9267415153e30bea03828c0530874e92e4

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker