This series adds basic self tests for HMM and are intended for Jason
Gunthorpe's rdma tree which has a number of HMM patches applied.
Changes v7 -> v8:
Rebased to Jason's rdma/hmm tree, plus Jason's 6 patch series
"Small hmm_range_fault() cleanups".
Applied a number of changes from Jason's comments.
Changes v6 -> v7:
Rebased to linux-5.6.0-rc6
Reverted back to just using mmu_interval_notifier_insert() and making
this series only introduce HMM self tests.
Changes v5 -> v6:
Rebased to linux-5.5.0-rc6
Refactored mmu interval notifier patches
Converted nouveau to use the new mmu interval notifier API
Changes v4 -> v5:
Added mmu interval notifier insert/remove/update callable from the
invalidate() callback
Updated HMM tests to use the new core interval notifier API
Changes v1 -> v4:
https://lore.kernel.org/linux-mm/20191104222141.5173-1-rcampbell@nvidia.com
Ralph Campbell (3):
mm/hmm/test: add selftest driver for HMM
mm/hmm/test: add selftests for HMM
MAINTAINERS: add HMM selftests
MAINTAINERS | 3 +
include/uapi/linux/test_hmm.h | 59 ++
lib/Kconfig.debug | 12 +
lib/Makefile | 1 +
lib/test_hmm.c | 1177 +++++++++++++++++++++
tools/testing/selftests/vm/.gitignore | 1 +
tools/testing/selftests/vm/Makefile | 3 +
tools/testing/selftests/vm/config | 2 +
tools/testing/selftests/vm/hmm-tests.c | 1353 ++++++++++++++++++++++++
tools/testing/selftests/vm/run_vmtests | 16 +
tools/testing/selftests/vm/test_hmm.sh | 97 ++
11 files changed, 2724 insertions(+)
create mode 100644 include/uapi/linux/test_hmm.h
create mode 100644 lib/test_hmm.c
create mode 100644 tools/testing/selftests/vm/hmm-tests.c
create mode 100755 tools/testing/selftests/vm/test_hmm.sh
--
2.20.1
When kunit tests are run on native (i.e. non-UML) environments, the results
of test execution are often intermixed with dmesg output. This patch
series attempts to solve this by providing a debugfs representation
of the results of the last test run, available as
/sys/kernel/debug/kunit/<testsuite>/results
Changes since v7:
- renamed KUNIT_INDENT[2] to KUNIT_SUBTEST_INDENT, KUNIT_SUBSUBTEST_INDENT
and added more description to their definitions to clarify why they
are defined as they are (Shuah)
- defined KUNIT_SUBSUBTEST_INDENT directly as 8 spaces to avoid
checkpatch error (Shuah)
Changes since v6:
- fixed regexp parsing in kunit_parser.py to ensure test results are read
successfully with 4-space indentation (Brendan, patch 3)
Changes since v5:
- replaced undefined behaviour use of snprintf(buf, ..., buf) in
kunit_log() with a function to append string to existing log
(Frank, patch 1)
- added clarification on log size limitations to documentation
(Frank, patch 4)
Changes since v4:
- added suite-level log expectations to kunit log test (Brendan, patch 2)
- added log expectations (of it being NULL) for case where
CONFIG_KUNIT_DEBUGFS=n to kunit log test (patch 2)
- added patch 3 which replaces subtest tab indentation with 4 space
indentation as per TAP 14 spec (Frank, patch 3)
Changes since v3:
- added CONFIG_KUNIT_DEBUGFS to support conditional compilation of debugfs
representation, including string logging (Frank, patch 1)
- removed unneeded NULL check for test_case in
kunit_suite_for_each_test_case() (Frank, patch 1)
- added kunit log test to verify logging multiple strings works
(Frank, patch 2)
- rephrased description of results file (Frank, patch 3)
Changes since v2:
- updated kunit_status2str() to kunit_status_to_string() and made it
static inline in include/kunit/test.h (Brendan)
- added log string to struct kunit_suite and kunit_case, with log
pointer in struct kunit pointing at the case log. This allows us
to collect kunit_[err|info|warning]() messages at the same time
as we printk() them. This solves for the most part the sharing
of log messages between test execution and debugfs since we
just print the suite log (which contains the test suite preamble)
and the individual test logs. The only exception is the suite-level
status, which we cannot store in the suite log as it would mean
we'd print the suite and its status prior to the suite's results.
(Brendan, patch 1)
- dropped debugfs-based kunit run patch for now so as not to cause
problems with tests currently under development (Brendan)
- fixed doc issues with code block (Brendan, patch 3)
Changes since v1:
- trimmed unneeded include files in lib/kunit/debugfs.c (Greg)
- renamed global debugfs functions to be prefixed with kunit_ (Greg)
- removed error checking for debugfs operations (Greg)
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
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 +++++++++++++++++++++++++-------
tools/testing/kunit/kunit_parser.py | 10 +--
10 files changed, 430 insertions(+), 86 deletions(-)
create mode 100644 lib/kunit/debugfs.c
create mode 100644 lib/kunit/debugfs.h
--
1.8.3.1
Hi!
Shuah please consider applying to the kselftest tree.
This set is an attempt to make running tests for different
sets of data easier. The direct motivation is the tls
test which we'd like to run for TLS 1.2 and TLS 1.3,
but currently there is no easy way to invoke the same
tests with different parameters.
Tested all users of kselftest_harness.h.
v2:
- don't run tests by fixture
- don't pass params as an explicit argument
v3:
- go back to the orginal implementation with an extra
parameter, and running by fixture (Kees);
- add LIST_APPEND helper (Kees);
- add a dot between fixture and param name (Kees);
- rename the params to variants (Tim);
v4:
- whitespace fixes.
v5 (Kees):
- move a comment;
- remove a temporary variable;
- reword the commit message on patch 4.
v1: https://lore.kernel.org/netdev/20200313031752.2332565-1-kuba@kernel.org/
v2: https://lore.kernel.org/netdev/20200314005501.2446494-1-kuba@kernel.org/
v3: https://lore.kernel.org/netdev/20200316225647.3129354-1-kuba@kernel.org/
v4: https://lore.kernel.org/netdev/20200317010419.3268916-1-kuba@kernel.org/
Jakub Kicinski (5):
kselftest: factor out list manipulation to a helper
kselftest: create fixture objects
kselftest: run tests by fixture
kselftest: add fixture variants
selftests: tls: run all tests for TLS 1.2 and TLS 1.3
Documentation/dev-tools/kselftest.rst | 3 +-
tools/testing/selftests/kselftest_harness.h | 234 +++++++++++++++-----
tools/testing/selftests/net/tls.c | 93 ++------
3 files changed, 202 insertions(+), 128 deletions(-)
--
2.25.1
> Traced event can trigger 'snapshot' operation(i.e. calls snapshot_trigger()
I suggest to improve the change description.
* Adjustment:
… operation (i. e. …
* Will the tag “Fixes” become relevant?
Regards,
Markus
Fix warnings at 'make htmldocs', and formatting issues in the resulting
documentation.
- test.h: Fix annotation in kernel-doc parameter description.
- Documentation/*.rst: Fixing formatting issues, and a duplicate label
issue due to usage of sphinx.ext.autosectionlabel and identical labels
within one document (sphinx warning)
NB: checkpatch.pl will complain about flow control statements (i.e. usage
of "return") within the macro kunit_test_suites(suites_list...).
v2: Several documentation fixes
v3: Do not touch API documentation index
v4: Replace macro argument in test.h by named variadic argument
Signed-off-by: Lothar Rubusch <l.rubusch(a)gmail.com>
---
Documentation/dev-tools/kunit/start.rst | 13 ++++++++-----
Documentation/dev-tools/kunit/usage.rst | 4 ++--
include/kunit/test.h | 12 ++++++------
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/Documentation/dev-tools/kunit/start.rst b/Documentation/dev-tools/kunit/start.rst
index e1c5ce80ce12..bb112cf70624 100644
--- a/Documentation/dev-tools/kunit/start.rst
+++ b/Documentation/dev-tools/kunit/start.rst
@@ -32,15 +32,17 @@ test targets as well. The ``.kunitconfig`` should also contain any other config
options required by the tests.
A good starting point for a ``.kunitconfig`` is the KUnit defconfig:
+
.. code-block:: bash
cd $PATH_TO_LINUX_REPO
cp arch/um/configs/kunit_defconfig .kunitconfig
You can then add any other Kconfig options you wish, e.g.:
+
.. code-block:: none
- CONFIG_LIST_KUNIT_TEST=y
+ CONFIG_LIST_KUNIT_TEST=y
:doc:`kunit_tool <kunit-tool>` will ensure that all config options set in
``.kunitconfig`` are set in the kernel ``.config`` before running the tests.
@@ -54,8 +56,8 @@ using.
other tools (such as make menuconfig) to adjust other config options.
-Running the tests
------------------
+Running the tests (KUnit Wrapper)
+---------------------------------
To make sure that everything is set up correctly, simply invoke the Python
wrapper from your kernel repo:
@@ -105,8 +107,9 @@ have config options ending in ``_KUNIT_TEST``.
KUnit and KUnit tests can be compiled as modules: in this case the tests in a
module will be run when the module is loaded.
-Running the tests
------------------
+
+Running the tests (w/o KUnit Wrapper)
+-------------------------------------
Build and run your kernel as usual. Test output will be written to the kernel
log in `TAP <https://testanything.org/>`_ format.
diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index 473a2361ec37..3c3fe8b5fecc 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -595,7 +595,7 @@ able to run one test case per invocation.
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
+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.
@@ -604,4 +604,4 @@ 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).
+results file is KUNIT_LOG_SIZE bytes (defined in ``include/kunit/test.h``).
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 9b0c46a6ca1f..47e61e1d5337 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -175,7 +175,7 @@ struct kunit_suite {
void (*exit)(struct kunit *test);
struct kunit_case *test_cases;
- /* private - internal use only */
+ /* private: internal use only */
struct dentry *debugfs;
char *log;
};
@@ -232,12 +232,12 @@ void __kunit_test_suites_exit(struct kunit_suite **suites);
* kunit_test_suites() - used to register one or more &struct kunit_suite
* with KUnit.
*
- * @suites: a statically allocated list of &struct kunit_suite.
+ * @suites_list...: a statically allocated list of &struct kunit_suite.
*
- * Registers @suites with the test framework. See &struct kunit_suite for
+ * Registers @suites_list with the test framework. See &struct kunit_suite for
* more information.
*
- * When builtin, KUnit tests are all run as late_initcalls; this means
+ * When builtin, KUnit tests are all run as late_initcalls; this means
* that they cannot test anything where tests must run at a different init
* phase. One significant restriction resulting from this is that KUnit
* cannot reliably test anything that is initialize in the late_init phase;
@@ -253,8 +253,8 @@ void __kunit_test_suites_exit(struct kunit_suite **suites);
* tests from the same place, and at the very least to do so after
* everything else is definitely initialized.
*/
-#define kunit_test_suites(...) \
- static struct kunit_suite *suites[] = { __VA_ARGS__, NULL}; \
+#define kunit_test_suites(suites_list...) \
+ static struct kunit_suite *suites[] = {suites_list, NULL}; \
static int kunit_test_suites_init(void) \
{ \
return __kunit_test_suites_init(suites); \
--
2.20.1
Add test which adds a tree of software_nodes, checks that the nodes
exist, and then removes the tree. This exercises a bug reported by
Naresh Kamboju <naresh.kamboju(a)linaro.org>, and pretty much just takes a
test case from the test_printf Kselftest module and refocusses it on
adding and then removing a tree of software_nodes.
Signed-off-by: Brendan Higgins <brendanhiggins(a)google.com>
---
I am not sure if this should be rolled into the property entry test, or
should be moved somewhere else; nevertheless, testing the software node
API seems like a good idea and this seems like a good place to start.
---
drivers/base/test/Kconfig | 14 ++++++++
drivers/base/test/Makefile | 2 ++
drivers/base/test/software-node-test.c | 46 ++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
create mode 100644 drivers/base/test/software-node-test.c
diff --git a/drivers/base/test/Kconfig b/drivers/base/test/Kconfig
index 305c7751184a..b42f385fe233 100644
--- a/drivers/base/test/Kconfig
+++ b/drivers/base/test/Kconfig
@@ -11,3 +11,17 @@ config TEST_ASYNC_DRIVER_PROBE
config KUNIT_DRIVER_PE_TEST
bool "KUnit Tests for property entry API"
depends on KUNIT=y
+config KUNIT_DRIVER_SOFTWARE_NODE_TEST
+ bool "KUnit Tests for software node API"
+ depends on KUNIT=y
+ help
+ This builds the software node API tests.
+
+ KUnit tests run during boot and output the results to the debug log
+ in TAP format (http://testanything.org/). Only useful for kernel devs
+ and are not for inclusion into a production build.
+
+ For more information on KUnit and unit tests in general please refer
+ to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+ If unsure, say N.
diff --git a/drivers/base/test/Makefile b/drivers/base/test/Makefile
index 3ca56367c84b..63325e8a5288 100644
--- a/drivers/base/test/Makefile
+++ b/drivers/base/test/Makefile
@@ -2,3 +2,5 @@
obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o
obj-$(CONFIG_KUNIT_DRIVER_PE_TEST) += property-entry-test.o
+
+obj-$(CONFIG_KUNIT_DRIVER_SOFTWARE_NODE_TEST) += software-node-test.o
diff --git a/drivers/base/test/software-node-test.c b/drivers/base/test/software-node-test.c
new file mode 100644
index 000000000000..0609cbd9aa0a
--- /dev/null
+++ b/drivers/base/test/software-node-test.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+// Unit tests for software node API
+//
+// Copyright 2020 Google LLC.
+
+#include <kunit/test.h>
+#include <linux/property.h>
+#include <linux/types.h>
+
+static void software_node_test_register_nodes(struct kunit *test)
+{
+ const struct software_node softnodes[] = {
+ { .name = "first", },
+ { .name = "second", .parent = &softnodes[0], },
+ { .name = "third", .parent = &softnodes[1], },
+ {}
+ };
+ const char * const full_name = "first/second/third";
+ char *buf;
+
+ buf = kunit_kzalloc(test, strlen(full_name), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+ KUNIT_ASSERT_EQ(test, software_node_register_nodes(softnodes), 0);
+
+ /* Check that all the nodes exist. */
+ KUNIT_ASSERT_EQ(test,
+ (size_t)sprintf(buf, "%pfw",
+ software_node_fwnode(&softnodes[2])),
+ strlen(full_name));
+ KUNIT_EXPECT_STREQ(test, buf, full_name);
+
+ software_node_unregister_nodes(softnodes);
+}
+
+static struct kunit_case software_node_test_cases[] = {
+ KUNIT_CASE(software_node_test_register_nodes),
+ {}
+};
+
+static struct kunit_suite software_node_test_suite = {
+ .name = "software-node",
+ .test_cases = software_node_test_cases,
+};
+
+kunit_test_suite(software_node_test_suite);
base-commit: 8632e9b5645bbc2331d21d892b0d6961c1a08429
--
2.26.0.110.g2183baf09c-goog
From: Tim Bird <tim.bird(a)sony.com>
Add ksft-compile-test.sh. This is a program used to test
cross-compilation and installation of selftest tests.
See the test usage for help
This program currently tests 3 scenarios out of a larger matrix
of possibly interesting scenarios. For each scenario, it conducts
multiple tests for correctness. This version tests:
1) does the test compile
2) is the kernel source directory clean after the compile
3) does the test install operation succeed
4) does the test run script reference the test
Signed-off-by: Tim Bird <tim.bird(a)sony.com>
---
MAINTAINERS | 6 +
tools/testing/selftests/ksft-compile-test.sh | 567 +++++++++++++++++++++++++++
2 files changed, 573 insertions(+)
create mode 100755 tools/testing/selftests/ksft-compile-test.sh
diff --git a/MAINTAINERS b/MAINTAINERS
index cc1d18c..a6289c7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9127,6 +9127,12 @@ S: Maintained
F: tools/testing/selftests/
F: Documentation/dev-tools/kselftest*
+KERNEL SELFTEST SELFTEST
+M: Tim Bird <tim.bird(a)sony.com>
+L: linux-kselftest(a)vger.kernel.org
+S: Maintained
+F: tools/testing/selftests/ksft-compile-test.sh
+
KERNEL UNIT TESTING FRAMEWORK (KUnit)
M: Brendan Higgins <brendanhiggins(a)google.com>
L: linux-kselftest(a)vger.kernel.org
diff --git a/tools/testing/selftests/ksft-compile-test.sh b/tools/testing/selftests/ksft-compile-test.sh
new file mode 100755
index 0000000..e36e858
--- /dev/null
+++ b/tools/testing/selftests/ksft-compile-test.sh
@@ -0,0 +1,567 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-only OR MIT
+#
+# ksft-compile-test.sh - test compiling Linux kernel selftests under lots of
+# different configurations. This is used to check that cross-compilation
+# and install works properly for a newly submitted test target, and
+# also that changes to existing test Makefiles don't regress with regard to
+# this functionality.
+#
+# Copyright 2020 Sony Corporation
+#
+# Here are the things that Shuah Kahn asked for on 3/6/2020
+# 1. Cross-compilation & relocatable build support
+# 2. Generates objects in objdir/kselftest without cluttering main objdir
+# 3. Leave source directory clean
+# 4. Installs correctly in objdir/kselftest/kselftest_install and adds
+# itself to run_kselftest.sh script generated during install.
+#
+# Would be nice to make sure other features also work:
+# 5. can use absolute, relative, or current directory for output directory
+# 6. can use ~ in output directory path
+#
+# matrix of build combinations:
+# dimensions:
+# cwd: top-level, build-dir, tools/testing/selftests/<target>
+# change-dir: <none>, -C tools/testing/selftests (selftests)
+# make-target: <none>, kselftest-install, install
+# output-dir: <none>, KBUILD_OUTPUT-rel, KBUILD_OUTPUT-abs, O-rel, O-abs
+#
+# NOTE: you should not put your output directory inside your source directory
+# Parts of the kbuild system don't like this.
+#
+# The test matrix is not full:
+# <cwd>,<change-dir>,<make target>,<output-dir>
+# top, none, kselftest-install, none
+# top, none, kselftest-install, KBO-rel
+# 2 top, none, kselftest-install, KBO-abs
+# top, none, kselftest-install, O-rel
+# 1 top, none, kselftest-install, O-abs
+# top, selftests, none , none
+# top, selftests, none , KBO-rel
+# 3 top, selftests, none , KBO-abs
+# top, selftests, none , O-rel
+# 4 top, selftests, none , O-abs
+# build-dir, none, kselftest-install, none
+# build-dir, none, kselftest-install, KBO-rel
+# build-dir, none, kselftest-install, KBO-abs
+# build-dir, none, kselftest-install, O-rel
+# build-dir, none, kselftest-install, O-abs
+# build-dir, selftests, none, none
+# build-dir, selftests, none, KBO-rel
+# build-dir, selftests, none, KBO-abs
+# build-dir, selftests, none, kselftest-install, O-rel
+# build-dir, selftests, none, O-abs
+# 5 target, none, none, none
+# 6 target, none, install, none
+# target, none, none, KBO-rel
+# target, none, install, KBO-rel
+# target, none, none, KBO-abs
+# target, none, install, KBO-abs
+# target, none, none, O-rel
+# target, none, install, O-rel
+# target, none, none, O-abs
+# target, none, install, O-abs
+#
+# 1 = Shuah preferred test (top-level, kselftest-install, with O=)
+# 3 = Fuego (Tim's) default build style
+#
+# To do for this test:
+#
+
+usage() {
+ cat <<HERE
+Usage: ksft-compile-test.sh [-h|--help] [TARGETS="<targets>"] [<options>]
+
+compile_test.sh will test building selftest programs in the indicated
+target areas. The script tests various output-directory configurations.
+
+OPTIONS
+ -h, --help Show this usage help.
+ TARGETS="<targets>" Indicate the set of targets to test. <targets> is a
+ space-separated list of testing areas from
+ tools/testing/selftests/Makefile
+ O=<dir> Indicate a directory to use for output. Normally, the
+ program creates a temporary directory for testing, and
+ removes it when done. This sets -p, to avoid removing
+ the directory at the end of the test. Using O= with an
+ existing directory can save time (the kernel does not
+ need to be rebuilt). The directory must already exist.
+ -c <config-file> Specify a configuration file for the kernel.
+ If not specified, an appropriate defconfig will be used.
+ -p, --preserve Preserve files when this test completes.
+ If not specified, test will remove working files when
+ it completes.
+ -l <log-file> Specify the file to use for log output. All test output
+ goes to STDOUT (and STDERR) A subset of output
+ is placed in the logfile. If not specified, the
+ filename 'compile-test-log-<timestamp>.txt' is used.
+ -s, --summary Show summary of results at end of test.
+ -e <extra-data-file> Put contents of <extra-data-file> in the header of
+ the logfile (and in test output). This allows a CI
+ system to add additional information about the build
+ system, toolchain, etc. used for the test.
+ -C <kernel-src-dir> Use the indicated directory (instead of current
+ working directory) as the kernel source dir.
+
+ENVIRONMENT
+ Set ARCH and CROSS_COMPILE to values appropriate for your environment
+ (the same as for a Linux kernel image build)
+
+ You can use a TARGETS environment variable, instead of the TARGETS=
+ command line option.
+
+OUTPUT
+ Program output is in TAP13 format. The exit code indicates if the test was
+ 100% successful (SKIPS are counted as failures).
+HERE
+ exit 1
+}
+
+INDENT=3
+DEBUG=1
+
+dprint() {
+ if [ $DEBUG = 1 ] ; then
+ echo "$1"
+ fi
+}
+
+# parse command line options
+CONFIG_FILE=use_defconfig
+PRESERVE_FILES=0
+LOGFILE="$(pwd)/compile-test-log-$(date -Iseconds).txt"
+SHOW_SUMMARY=0
+SRC_TOP="$(realpath $(pwd))"
+
+while [ -n "$1" ] ; do
+ case $1 in
+ -h|--help)
+ usage
+ ;;
+ TARGETS=*)
+ TARGETS="${1#TARGETS=}"
+ export TARGETS
+ shift
+ ;;
+ O=*)
+ OUTPUT_DIR="${1#O=}"
+ shift
+ export OUTPUT_DIR
+ PRESERVE_FILES=1
+ if [ ! -d "$OUTPUT_DIR" ] ; then
+ echo "Error: output directory $OUTPUT_DIR does not exist"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ ;;
+ -c)
+ CONFIG_FILE="$2"
+ shift 2
+ if [ ! -f ${CONFIG_FILE} ] ; then
+ echo "Error: Can't read specified config file $CONFIG_FILE"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ ;;
+ -p|--preserve)
+ PRESERVE_FILES=1
+ shift
+ ;;
+ -l)
+ LOGFILE=="$2"
+ shift 2
+ if [ -z "$LOGFILE" ] ; then
+ echo "Error: No log-file specified with -l"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ echo "Using logfile $LOGFILE"
+ ;;
+ -s|--summary)
+ SHOW_SUMMARY=1
+ shift
+ ;;
+ -e)
+ EXTRA_DATA_FILE="$2"
+ shift 2
+ if [ -z "$EXTRA_DATA_FILE" ] ; then
+ echo "Error: No <extra-data-file> specified with -e"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ if [ ! -f "$EXTRA_DATA_FILE" ] ; then
+ echo "Error: Extra data file '$EXTRA_DATA_FILE' does not exist"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ echo "Using extra data file $EXTRA_DATA_FILE"
+ ;;
+ -C)
+ SRC_TOP="$(realpath $2)"
+ shift 2
+ if [ ! -d $SRC_TOP ] ; then
+ echo "Error: Kernel source dir '$SRC_TOP' does not exist"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+ if [ ! -f "$SRC_TOP/MAINTAINERS" ] ; then
+ echo "Error: $SRC_TOP doesn't seem to be a kernel source tree."
+ echo "Missing MAINTAINERS file."
+ exit 1
+ fi
+ echo "Using kernel source tree: $SRC_TOP"
+ cd $SRC_TOP
+ ;;
+ *)
+ echo "Error: Unknown option '$1'"
+ echo "Use '-h' to get program usage"
+ exit 1
+ ;;
+ esac
+done
+
+# for debugging option parsing
+dprint "TARGETS=$TARGETS"
+dprint "CONFIG_FILE=$CONFIG_FILE"
+dprint "LOGFILE=$LOGFILE"
+dprint "PRESERVE_FILES=$PRESERVE_FILES"
+dprint "OUTPUT_DIR=$OUTPUT_DIR"
+dprint "SRC_TOP=$SRC_TOP"
+
+#### logging routines
+# log_msg - put a single-line message in the logfile (and STDOUT)
+log_msg() {
+ echo "$1" | tee -a $LOGFILE
+}
+
+# log_result - put TAP-syntax prefix and description to logfile
+# $1 = result to log
+# $2 = result description (usually "$test_id", but may include SKIP)
+# Uses global TEST_NUM
+log_result() {
+ if [ $1 = 0 ] ; then
+ log_msg "ok $TEST_NUM $2"
+ else
+ log_msg "not ok $TEST_NUM $2"
+ fi
+}
+
+# log_cmd - put output of command into logfile
+# $1 - command to execute
+log_cmd() {
+ RETCODE=/tmp/$$-${RANDOM}
+ touch $RETCODE
+ bash -c "{ $1; echo \$? >$RETCODE ; } 2>&1 | tee -a $LOGFILE"
+ RESULT=$(cat $RETCODE)
+ rm -f $RETCODE
+ return $RESULT
+}
+
+# log_cmd_indented - put output of command into logfile, indented by INDENT
+# $1 - command to execute
+# Uses global INDENT
+log_cmd_indented() {
+ RETCODE=/tmp/$$-${RANDOM}
+ TMPOUT=/tmp/$$-${RANDOM}
+ touch $RETCODE
+ bash -c "{ $1; echo \$? >$RETCODE ; } 2>&1 | tee -a $TMPOUT"
+ RESULT=$(cat $RETCODE)
+
+ # could use sed here instead of pr, if needed
+ cat $TMPOUT | pr -to $INDENT >>$LOGFILE
+
+ rm -f $RETCODE $TMPOUT
+ return $RESULT
+}
+
+# do some sanity checks before we get started
+test_pre_check() {
+ # are we in the top directory of a kernel source tree?
+ if [ ! -f "MAINTAINERS" ] ; then
+ echo "Error: We're not in a kernel source tree (no MAINTAINERS file)"
+ echo "Use '-h' to get program usage"
+ exit 1
+ fi
+
+ if [ -z $ARCH ] ; then
+ ARCH_ARGS=""
+ else
+ ARCH_ARGS="ARCH=$ARCH"
+ fi
+ export ARCH_ARGS
+
+ if [ -z "$CROSS_COMPILE" -a -n "$ARCH_ARGS" ] ; then
+ echo "Warning: no CROSS_COMPILE prefix defined, but ARCH $ARCH specified"
+ echo "Usually, if you specify an ARCH you need to specify CROSS_COMPILE"
+ echo "Use '-h' to get program usage"
+ fi
+}
+
+# prepare for tests
+# on completion, following should be set:
+# INDENT, TARGET_LIST, NUM_MAKE_JOBS, KBUILD_DIR_REL, KBUILD_DIR_ABS
+# Uses: ARCH
+test_setup() {
+ echo "In test setup"
+
+ # read target list from test variable, if defined
+ if [ -n "${TARGETS}" ] ; then
+ TARGET_LIST="${TARGETS}"
+ else
+ # use hardcoded kselftest target list for now
+ TARGET_LIST="android arm64 bpf breakpoints capabilities cgroup \
+ clone3 cpufreq cpu-hotplug drivers/dma-buf efivarfs exec \
+ filesystems filesystems/binderfs filesystems/epoll firmware \
+ ftrace futex gpio intel_pstate ipc ir kcmp kexec kvm lib \
+ livepatch lkdtm membarrier memfd memory-hotplug mount mqueue \
+ net net/mptcp netfilter networking/timestamping nsfs pidfd \
+ powerpc proc pstore ptrace openat2 rseq rtc seccomp sigaltstack \
+ size sparc64 splice static_keys sync sysctl timens timers tmpfs \
+ tpm2 user vm x86 zram"
+ # FIXTHIS - query kernel for kselftest full target list
+ #TARGET_LIST=$(make --no-print-directory -s \
+ # -C tools/testing/selftests show_targets)
+ fi
+
+ # get number of parallel jobs to start in make
+ proc_count=$(cat /proc/cpuinfo | grep processor | wc -l)
+ NUM_MAKE_JOBS=$(( proc_count / 2 ))
+ if [ $NUM_MAKE_JOBS -lt 1 ] ; then
+ NUM_MAKE_JOBS=1
+ fi
+
+ if [ -z "$OUTPUT_DIR" ] ; then
+ # make output dir
+ tmp1=$(mktemp -d ../ksft-XXXXXX)
+ export KBUILD_DIR_REL="$tmp1"
+ export KBUILD_DIR_ABS=$(realpath $tmp1)
+ else
+ export KBUILD_DIR_REL=$(realpath --relative-to=$(pwd) $OUTPUT_DIR)
+ export KBUILD_DIR_ABS=$(realpath $OUTPUT_DIR)
+ fi
+ mkdir -p $KBUILD_DIR_ABS
+
+ # for setup, use KBUILD_OUTPUT environment var for output dir
+ KBUILD_OUTPUT=$KBUILD_DIR_ABS
+
+ if [ $CONFIG_FILE = "use_defconfig" ] ; then
+ make $ARCH_ARGS defconfig
+ else
+ cp $CONFIG_FILE $KBUILD_OUTPUT/.config
+ fi
+ make $ARCH_ARGS oldconfig
+
+ # this should only be needed once
+ make $ARCH_ARGS -j $NUM_MAKE_JOBS headers_install
+
+ make $ARCH_ARGS -j $NUM_MAKE_JOBS vmlinux
+}
+
+#
+# $1 = KBUILD_DIR
+# $2 = target
+check_output_dir() {
+ install_result=0
+ log_msg "# Contents of kselftest_install directory:"
+ if [ -d $1/kselftest/kselftest_install ] ; then
+ pushd $1/kselftest/kselftest_install >/dev/null
+
+ log_cmd_indented "ls -lR"
+ log_msg "# File types:"
+ log_cmd_indented "find . -type f | xargs file -n | \
+ sed \"s/BuildID.*, //\""
+
+ # check that run scripts has the target
+ if ! grep "^cd $2" run_kselftest.sh 2>&1 >/dev/null ; then
+ log_mesg "# Missing target $2 in run_kselftest.sh"
+ install_result=1
+ fi
+
+ popd >/dev/null
+ else
+ log_msg "# Missing $KBUILD_OUTPUT/kselftest/kselftest_install directory"
+ install_result=1
+ fi
+ return $install_result
+}
+
+# do_test - perform one test combination
+# $1 = method (string for use in test_id)
+# $2 = target
+# $3 = compile args
+# $4 = install args (if any)
+# $5 = clean args
+#
+# Uses: ARCH_ARGS, KBUILD_DIR and LOGFILE (indirectly), and SRC_TOP
+# Uses and sets: TEST_NUM
+#
+do_test() {
+ method=$1
+ target=$2
+ COMPILE_ARGS=$3
+ INSTALL_ARGS=$4
+ CLEAN_ARGS=$4
+
+ TARGET_DIR=$SRC_TOP/tools/testing/selftests/$target
+
+ SRC_LS_FILE1="$(mktemp)"
+ SRC_LS_FILE2="$(mktemp)"
+ ls -lR $TARGET_DIR >$SRC_LS_FILE1
+
+ test_id="$target compile $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ # do the compile
+ log_cmd_indented "make $ARCH_ARGS TARGETS=\"$target\" $COMPILE_ARGS"
+ compile_result=$?
+
+ log_result $compile_result "$test_id"
+
+ # check that nothing changed in the src directory
+ test_id="$target src tree clean after compile $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ ls -lR $TARGET_DIR >$SRC_LS_FILE2
+ log_cmd_indented "diff -u $SRC_LS_FILE1 $SRC_LS_FILE2"
+ src_clean_result=$?
+
+ if [ $src_clean_result != 0 ] ; then
+ log_msg "# File or directory changes found in $TARGET_DIR"
+ fi
+
+ log_result $src_clean_result "$test_id"
+ rm $SRC_LS_FILE1
+ rm $SRC_LS_FILE2
+
+ test_id="$target install $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ if [ -n "INSTALL_ARGS" ] ; then
+ # skip the install test if it didn't compile
+ if [ $compile_result != 0 ] ; then
+ install_result=$compile_result
+ reason="compile failed"
+ log_result $install_result "$test_id # SKIP - $reason"
+
+ else
+ # now do install
+ log_cmd_indented "make $ARCH_ARGS TARGETS=\"$target\" $INSTALL_ARGS"
+ install_result=$?
+ log_result $install_result "$test_id"
+ fi
+ else
+ install_result=$compile_result
+ log_result $install_result "$test_id"
+ fi
+
+ test_id="$target check install output $method"
+ TEST_NUM=$(( TEST_NUM + 1 ))
+ log_msg "# $TEST_NUM $test_id"
+
+ # check results
+ if [ $install_result = 0 ] ; then
+ check_output_dir $KBUILD_DIR $target
+ install_output_result=$?
+ log_result $install_output_result "$test_id"
+ else
+ log_result $install_result "$test_id # SKIP - install failed"
+ fi
+
+ # clean up after test
+ make $ARCH_ARGS TARGETS=\"$target\" $CLEAN_ARGS
+
+ # clear out install directory for next test
+ rm -rf $KBUILD_DIR/kselftest/kselftest_install
+ mkdir -p $KBUILD_DIR/kselftest/kselftest_install
+}
+
+test_run() {
+ export KBUILD_DIR=$KBUILD_DIR_ABS
+ NUM_SCENARIOS=3
+ TESTS_PER_SCENARIO=4
+
+ # output the header
+ log_msg "ARCH=$ARCH"
+ log_msg "CROSS_COMPILE=$CROSS_COMPILE"
+ if [ -f "$EXTRA_DATA_FILE" ] ; then
+ log_msg "=== Test Details ==="
+ log_cmd "cat $EXTRA_DATA_FILE"
+ log_msg "==="
+ fi
+ log_msg "TAP VERSION 13"
+
+ target_count=$(echo $TARGET_LIST | wc -w)
+ export test_count=$(( target_count * $NUM_SCENARIOS * $TESTS_PER_SCENARIO ))
+ log_msg "1..$test_count"
+
+ # disable 'stop-on-error'
+ set +e
+
+ export TEST_NUM=0
+ for target in $TARGET_LIST ; do
+ echo "########## Doing tests for target $target ##########"
+
+ # clean out directory to force a re-build
+ make $ARCH_ARGS TARGETS=\"$target\" -C tools/testing/selftests clean
+
+ ### MATRIX SCENARIO: KBUILD_OUTPUT,-C
+ export KBUILD_OUTPUT="$KBUILD_DIR"
+ method="KBUILD_OUTPUT,-C"
+ COMPILE_ARGS="-C tools/testing/selftests"
+ INSTALL_ARGS="$COMPILE_ARGS install"
+ CLEAN_ARGS="$COMPILE_ARGS clean"
+ do_test "$method" $target "$COMPILE_ARGS" "$INSTALL_ARGS" "$CLEAN_ARGS"
+
+ ### MATRIX SCENARIO: O,-C
+ unset KBUILD_OUTPUT
+ O_TMP="$KBUILD_DIR"
+ method="O,-C"
+ COMPILE_ARGS="-C tools/testing/selftests O=$O_TMP"
+ INSTALL_ARGS="$COMPILE_ARGS install"
+ CLEAN_ARGS="$COMPILE_ARGS clean"
+ do_test "$method" $target "$COMPILE_ARGS" "$INSTALL_ARGS" "$CLEAN_ARGS"
+
+ ### MATRIX SCENARIO: O,top
+ method="O,top"
+ COMPILE_ARGS="O=$O_TMP kselftest-install"
+ INSTALL_ARGS=""
+ CLEAN_ARGS="O=$O_TMP kselftest-clean"
+ do_test "$method" $target "$COMPILE_ARGS" "$INSTALL_ARGS" "$CLEAN_ARGS"
+
+ done
+ set -e
+}
+
+test_cleanup() {
+ echo "In test cleanup"
+ if [ -z "$OUTPUT_DIR" ] ; then
+ if [ "$PRESERVE_FILES" = 0 ] ; then
+ rm -rf $KBUILD_DIR_ABS
+ else
+ echo "Build data was left in directory $KBUILD_DIR_ABS"
+ fi
+ else
+ echo "Not removing files in user-specified output dir $OUTPUT_DIR"
+ fi
+}
+
+# this is main()
+test_pre_check
+test_setup
+dprint "TARGET_LIST=$TARGET_LIST"
+test_run
+test_cleanup
+
+echo "Done. Log file is in $LOGFILE"
+
+if [ "$SHOW_SUMMARY" = 1 ] ; then
+ ok_count=$(grep ^ok $LOGFILE | wc -l)
+ fail_count=$(grep "^not ok" $LOGFILE | grep -v SKIP | wc -l)
+ skip_count=$(grep "^not ok" $LOGFILE | grep SKIP | wc -l)
+ total=$(( ok_count + fail_count + skip_count ))
+ echo "OK: $ok_count, FAIL: $fail_count, SKIP: $skip_count, TOTAL: $total"
+fi
--
2.1.4