The KUnit documentation was not very organized. There was little
information related to KUnit architecture and the importance of unit
testing.
Add some new pages, expand and reorganize the existing documentation.
Reword pages to make information and style more consistent.
Changes since v4:
https://lore.kernel.org/linux-kselftest/20211216055958.634097-1-sharinder@g…
-- Replaced kunit_suitememorydiagram.png with kunit_suitememorydiagram.svg
Changes since v3:
https://lore.kernel.org/linux-kselftest/20211210052812.1998578-1-sharinder@…
--Reworded sentences as per comments
--Replaced Elixir links with kernel.org links or kernel-doc references
Changes since v2:
https://lore.kernel.org/linux-kselftest/20211207054019.1455054-1-sharinder@…
--Reworded sentences as per comments
--Expanded the explaination in usage.rst for accessing the current test example
--Standardized on US english in style.rst
Changes since v1:
https://lore.kernel.org/linux-kselftest/20211203042437.740255-1-sharinder@g…
--Fixed spelling mistakes
--Restored paragraph about kunit_tool introduction
--Added note about CONFIG_KUNIT_ALL_TESTS (Thanks Tim Bird for review
comments)
-- Miscellaneous changes
Harinder Singh (7):
Documentation: KUnit: Rewrite main page
Documentation: KUnit: Rewrite getting started
Documentation: KUnit: Added KUnit Architecture
Documentation: kunit: Reorganize documentation related to running
tests
Documentation: KUnit: Rework writing page to focus on writing tests
Documentation: KUnit: Restyle Test Style and Nomenclature page
Documentation: KUnit: Restyled Frequently Asked Questions
.../dev-tools/kunit/architecture.rst | 204 +++++++
Documentation/dev-tools/kunit/faq.rst | 73 ++-
Documentation/dev-tools/kunit/index.rst | 172 +++---
Documentation/dev-tools/kunit/run_manual.rst | 57 ++
Documentation/dev-tools/kunit/run_wrapper.rst | 247 ++++++++
Documentation/dev-tools/kunit/start.rst | 198 +++---
Documentation/dev-tools/kunit/style.rst | 105 ++--
Documentation/dev-tools/kunit/usage.rst | 578 ++++++++----------
8 files changed, 1047 insertions(+), 587 deletions(-)
create mode 100644 Documentation/dev-tools/kunit/architecture.rst
create mode 100644 Documentation/dev-tools/kunit/run_manual.rst
create mode 100644 Documentation/dev-tools/kunit/run_wrapper.rst
base-commit: 4c388a8e740d3235a194f330c8ef327deef710f6
--
2.34.1.173.g76aa8bc2d0-goog
Some testcases allow for optional commandline parameters but as of now
there is now way to provide such arguments to the runner script.
Add support to retrieve such optional command parameters fron environment
variables named so as to include the all-uppercase test executable name,
sanitized substituting any non-acceptable varname characters with "_",
following the pattern:
KSELFTEST_<UPPERCASE_SANITIZED_TEST_NAME>_ARGS="options"
Optional command parameters support is not available if 'tr' is not
installed on the test system.
Signed-off-by: Cristian Marussi <cristian.marussi(a)arm.com>
---
v2 --> v3
- improved varname sanitation
v1 --> v2
- using env vars instead of settings file
- added missing varname sanitation
Used to configure tests as in:
rtctest --> KSELFTEST_RTCTEST_ARGS="/dev/rtc1"
cpu-on-off-test.sh --> KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10"
---
tools/testing/selftests/kselftest/runner.sh | 30 ++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index a9ba782d8ca0..294619ade49f 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -18,6 +18,8 @@ if [ -z "$BASE_DIR" ]; then
exit 1
fi
+TR_CMD=$(command -v tr)
+
# If Perl is unavailable, we must fall back to line-at-a-time prefixing
# with sed instead of unbuffered output.
tap_prefix()
@@ -49,6 +51,31 @@ run_one()
# Reset any "settings"-file variables.
export kselftest_timeout="$kselftest_default_timeout"
+
+ # Safe default if tr not available
+ kselftest_cmd_args_ref="KSELFTEST_ARGS"
+
+ # Optional arguments for this command, possibly defined as an
+ # environment variable built using the test executable in all
+ # uppercase and sanitized substituting non acceptable shell
+ # variable name characters with "_" as in:
+ #
+ # KSELFTEST_<UPPERCASE_SANITIZED_TESTNAME>_ARGS="<options>"
+ #
+ # e.g.
+ #
+ # rtctest --> KSELFTEST_RTCTEST_ARGS="/dev/rtc1"
+ #
+ # cpu-on-off-test.sh --> KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10"
+ #
+ if [ -n "$TR_CMD" ]; then
+ BASENAME_SANITIZED=$(echo "$BASENAME_TEST" | \
+ $TR_CMD -d "[:blank:][:cntrl:]" | \
+ $TR_CMD -c "[:alnum:]_" "_" | \
+ $TR_CMD [:lower:] [:upper:])
+ kselftest_cmd_args_ref="KSELFTEST_${BASENAME_SANITIZED}_ARGS"
+ fi
+
# Load per-test-directory kselftest "settings" file.
settings="$BASE_DIR/$DIR/settings"
if [ -r "$settings" ] ; then
@@ -69,7 +96,8 @@ run_one()
echo "# Warning: file $TEST is missing!"
echo "not ok $test_num $TEST_HDR_MSG"
else
- cmd="./$BASENAME_TEST"
+ eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}"
+ cmd="./$BASENAME_TEST $kselftest_cmd_args"
if [ ! -x "$TEST" ]; then
echo "# Warning: file $TEST is not executable"
--
2.17.1
livepatch's consistency model requires that no live patched function
must be found on any task's stack during a transition process after a
live patch is applied. It is achieved by walking through stacks of all
blocked tasks.
The user might also want to define more functions to search for without
them being patched at all. It may either help with preparing a live
patch, which would otherwise require adding more functions just to
achieve the consistency, or it can be used to overcome deficiencies the
stack checking inherently has.
Consider the following example, in which GCC may optimize function
parent() so that a part of it is moved to a different section
(child.cold()) and parent() jumps to it. If both parent() and child2()
are to patching targets, things can break easily if a task sleeps in
child.cold() and new patched child2() changes ABI. parent() is not found
on the stack, child.cold() jumps back to parent() eventually and new
child2() is called.
parent(): /* to-be-patched */
...
jmp child.cold() /* cannot be patched */
...
schedule()
...
jmp <back>
...
call child2() /* to-be-patched */
...
The patch set adds a new API which allows the user to specify such
functions.
v1: https://lore.kernel.org/all/20211119090327.12811-1-mbenes@suse.cz/
Changes:
--------
v2:
- no separate klp_funcs, stack_only attribute is defined
- tests rewritten
Miroslav Benes (2):
livepatch: Allow user to specify functions to search for on a stack
selftests/livepatch: Test of the API for specifying functions to
search for on a stack
include/linux/livepatch.h | 3 +
kernel/livepatch/core.c | 28 ++-
kernel/livepatch/patch.c | 6 +
kernel/livepatch/transition.c | 5 +-
lib/livepatch/Makefile | 5 +-
lib/livepatch/test_klp_func_stack_only_demo.c | 66 ++++++++
.../test_klp_func_stack_only_demo2.c | 61 +++++++
lib/livepatch/test_klp_func_stack_only_mod.c | 70 ++++++++
tools/testing/selftests/livepatch/Makefile | 3 +-
.../livepatch/test-func-stack-only.sh | 159 ++++++++++++++++++
10 files changed, 402 insertions(+), 4 deletions(-)
create mode 100644 lib/livepatch/test_klp_func_stack_only_demo.c
create mode 100644 lib/livepatch/test_klp_func_stack_only_demo2.c
create mode 100644 lib/livepatch/test_klp_func_stack_only_mod.c
create mode 100755 tools/testing/selftests/livepatch/test-func-stack-only.sh
--
2.34.1
The KUnit documentation was not very organized. There was little
information related to KUnit architecture and the importance of unit
testing.
Add some new pages, expand and reorganize the existing documentation.
Reword pages to make information and style more consistent.
Changes since v1:
https://lore.kernel.org/linux-kselftest/20211203042437.740255-1-sharinder@g…
--Fixed spelling mistakes
--Restored paragraph about kunit_tool introduction
--Added note about CONFIG_KUNIT_ALL_TESTS (Thanks Tim Bird for review
comments)
-- Miscellaneous changes
Harinder Singh (7):
Documentation: KUnit: Rewrite main page
Documentation: KUnit: Rewrite getting started
Documentation: KUnit: Added KUnit Architecture
Documentation: kunit: Reorganize documentation related to running
tests
Documentation: KUnit: Rework writing page to focus on writing tests
Documentation: KUnit: Restyle Test Style and Nomenclature page
Documentation: KUnit: Restyled Frequently Asked Questions
.../dev-tools/kunit/architecture.rst | 206 +++++++
Documentation/dev-tools/kunit/faq.rst | 73 ++-
Documentation/dev-tools/kunit/index.rst | 172 +++---
.../kunit/kunit_suitememorydiagram.png | Bin 0 -> 24174 bytes
Documentation/dev-tools/kunit/run_manual.rst | 57 ++
Documentation/dev-tools/kunit/run_wrapper.rst | 247 ++++++++
Documentation/dev-tools/kunit/start.rst | 198 +++---
Documentation/dev-tools/kunit/style.rst | 101 ++--
Documentation/dev-tools/kunit/usage.rst | 570 ++++++++----------
9 files changed, 1039 insertions(+), 585 deletions(-)
create mode 100644 Documentation/dev-tools/kunit/architecture.rst
create mode 100644 Documentation/dev-tools/kunit/kunit_suitememorydiagram.png
create mode 100644 Documentation/dev-tools/kunit/run_manual.rst
create mode 100644 Documentation/dev-tools/kunit/run_wrapper.rst
base-commit: 4c388a8e740d3235a194f330c8ef327deef710f6
--
2.34.1.400.ga245620fadb-goog
The KUnit documentation was not very organized. There was little
information related to KUnit architecture and the importance of unit
testing.
Add some new pages, expand and reorganize the existing documentation.
Reword pages to make information and style more consistent.
Changes since v2:
https://lore.kernel.org/linux-kselftest/20211207054019.1455054-1-sharinder@…
--Reworded sentences as per comments
--Expanded the explaination in usage.rst for accessing the current test example
--Standardized on US english in style.rst
Changes since v1:
https://lore.kernel.org/linux-kselftest/20211203042437.740255-1-sharinder@g…
--Fixed spelling mistakes
--Restored paragraph about kunit_tool introduction
--Added note about CONFIG_KUNIT_ALL_TESTS (Thanks Tim Bird for review
comments)
-- Miscellaneous changes
Harinder Singh (7):
Documentation: KUnit: Rewrite main page
Documentation: KUnit: Rewrite getting started
Documentation: KUnit: Added KUnit Architecture
Documentation: kunit: Reorganize documentation related to running
tests
Documentation: KUnit: Rework writing page to focus on writing tests
Documentation: KUnit: Restyle Test Style and Nomenclature page
Documentation: KUnit: Restyled Frequently Asked Questions
.../dev-tools/kunit/architecture.rst | 206 +++++++
Documentation/dev-tools/kunit/faq.rst | 73 ++-
Documentation/dev-tools/kunit/index.rst | 172 +++---
.../kunit/kunit_suitememorydiagram.png | Bin 0 -> 24174 bytes
Documentation/dev-tools/kunit/run_manual.rst | 57 ++
Documentation/dev-tools/kunit/run_wrapper.rst | 247 ++++++++
Documentation/dev-tools/kunit/start.rst | 198 +++---
Documentation/dev-tools/kunit/style.rst | 105 ++--
Documentation/dev-tools/kunit/usage.rst | 578 ++++++++----------
9 files changed, 1049 insertions(+), 587 deletions(-)
create mode 100644 Documentation/dev-tools/kunit/architecture.rst
create mode 100644 Documentation/dev-tools/kunit/kunit_suitememorydiagram.png
create mode 100644 Documentation/dev-tools/kunit/run_manual.rst
create mode 100644 Documentation/dev-tools/kunit/run_wrapper.rst
base-commit: 4c388a8e740d3235a194f330c8ef327deef710f6
--
2.34.1.173.g76aa8bc2d0-goog
From: David Gow <davidgow(a)google.com>
The --jobs parameter for kunit_tool currently defaults to 8 CPUs,
regardless of the number available. For systems with significantly more
(or less), this is not as efficient. Instead, default --jobs to the
number of CPUs available to the process: while there are as many
superstitions as to exactly what the ideal jobs:CPU ratio is, this seems
sufficiently sensible to me.
A new helper function to get the default number of jobs is added:
get_default_jobs() -- this is used in kunit_tool_test instead of a
hardcoded value, or an explicit call to len(os.sched_getaffinity()), so
should be more flexible if this needs to change in the future.
Signed-off-by: David Gow <davidgow(a)google.com>
Signed-off-by: Daniel Latypov <dlatypov(a)google.com>
Reviewed-by: Daniel Latypov <dlatypov(a)google.com>
Reviewed-by: Brendan Higgins <brendanhiggins(a)google.com>
---
Changes since v2:
- Rebased by Daniel Latypov onto linxu-kselftest kunit branch.
There was a trivial conflict in kunit_tool_test.py.
Changes since v1:
https://lore.kernel.org/linux-kselftest/20211211084928.410669-1-davidgow@go…
- Use len(os.sched_getaffinity()) instead of os.cpu_count(), which gives
the number of available processors (to this process), rather than the
total.
- Fix kunit_tool_test.py, which had 8 jobs hardcoded in a couple of
places.
- Thanks to Daniel Latypov for these suggestions.
---
tools/testing/kunit/kunit.py | 5 ++++-
tools/testing/kunit/kunit_tool_test.py | 5 +++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index f1be71811369..7a706f96f68d 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -282,6 +282,9 @@ def massage_argv(argv: Sequence[str]) -> Sequence[str]:
return f'{arg}={pseudo_bool_flag_defaults[arg]}'
return list(map(massage_arg, argv))
+def get_default_jobs() -> int:
+ return len(os.sched_getaffinity(0))
+
def add_common_opts(parser) -> None:
parser.add_argument('--build_dir',
help='As in the make command, it specifies the build '
@@ -332,7 +335,7 @@ def add_build_opts(parser) -> None:
parser.add_argument('--jobs',
help='As in the make command, "Specifies the number of '
'jobs (commands) to run simultaneously."',
- type=int, default=8, metavar='jobs')
+ type=int, default=get_default_jobs(), metavar='jobs')
def add_exec_opts(parser) -> None:
parser.add_argument('--timeout',
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index b80e333a20cb..352369dffbd9 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -527,7 +527,7 @@ class KUnitMainTest(unittest.TestCase):
def test_build_passes_args_pass(self):
kunit.main(['build'], self.linux_source_mock)
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
- self.linux_source_mock.build_kernel.assert_called_once_with(False, 8, '.kunit', None)
+ self.linux_source_mock.build_kernel.assert_called_once_with(False, kunit.get_default_jobs(), '.kunit', None)
self.assertEqual(self.linux_source_mock.run_kernel.call_count, 0)
def test_exec_passes_args_pass(self):
@@ -633,8 +633,9 @@ class KUnitMainTest(unittest.TestCase):
def test_build_builddir(self):
build_dir = '.kunit'
+ jobs = kunit.get_default_jobs()
kunit.main(['build', '--build_dir', build_dir], self.linux_source_mock)
- self.linux_source_mock.build_kernel.assert_called_once_with(False, 8, build_dir, None)
+ self.linux_source_mock.build_kernel.assert_called_once_with(False, jobs, build_dir, None)
def test_exec_builddir(self):
build_dir = '.kunit'
base-commit: 1ee2ba89bea86d6389509e426583b49ac19b86f2
--
2.34.1.173.g76aa8bc2d0-goog
After upgrading mypy and pytype from pip, we see 2 new errors when
running ./tools/testing/kunit/run_checks.py.
Error #1: mypy and pytype
They now deduce that importlib.util.spec_from_file_location() can return
None and note that we're not checking for this.
We validate that the arch is valid (i.e. the file exists) beforehand.
Add in an `asssert spec is not None` to appease the checkers.
Error #2: pytype bug https://github.com/google/pytype/issues/1057
It doesn't like `from datetime import datetime`, specifically that a
type shares a name with a module.
We can workaround this by either
* renaming the import or just using `import datetime`
* passing the new `--fix-module-collisions` flag to pytype.
We pick the first option for now because
* the flag is quite new, only in the 2021.11.29 release.
* I'd prefer if people can just run `pytype <file>`
Signed-off-by: Daniel Latypov <dlatypov(a)google.com>
Reviewed-by: Brendan Higgins <brendanhiggins(a)google.com>
---
v1 -> v2: rebase on top of linx-kselftest kunit branch.
Only conflict was a deleted import in kunit_parser.py
---
tools/testing/kunit/kunit_kernel.py | 1 +
tools/testing/kunit/kunit_parser.py | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 12085e04a80c..44bbe54f25f1 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -209,6 +209,7 @@ def get_source_tree_ops_from_qemu_config(config_path: str,
# exists as a file.
module_path = '.' + os.path.join(os.path.basename(QEMU_CONFIGS_DIR), os.path.basename(config_path))
spec = importlib.util.spec_from_file_location(module_path, config_path)
+ assert spec is not None
config = importlib.util.module_from_spec(spec)
# See https://github.com/python/typeshed/pull/2626 for context.
assert isinstance(spec.loader, importlib.abc.Loader)
diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py
index 66a7f2fb314a..05ff334761dd 100644
--- a/tools/testing/kunit/kunit_parser.py
+++ b/tools/testing/kunit/kunit_parser.py
@@ -12,7 +12,7 @@
from __future__ import annotations
import re
-from datetime import datetime
+import datetime
from enum import Enum, auto
from functools import reduce
from typing import Iterable, Iterator, List, Optional, Tuple
@@ -517,7 +517,7 @@ ANSI_LEN = len(red(''))
def print_with_timestamp(message: str) -> None:
"""Prints message with timestamp at beginning."""
- print('[%s] %s' % (datetime.now().strftime('%H:%M:%S'), message))
+ print('[%s] %s' % (datetime.datetime.now().strftime('%H:%M:%S'), message))
def format_test_divider(message: str, len_message: int) -> str:
"""
base-commit: 1ee2ba89bea86d6389509e426583b49ac19b86f2
--
2.34.1.173.g76aa8bc2d0-goog
When kernel.h is used in the headers it adds a lot into dependency hell,
especially when there are circular dependencies are involved.
Replace kernel.h inclusion with the list of what is really being used.
Signed-off-by: Andy Shevchenko <andriy.shevchenko(a)linux.intel.com>
---
Andrew, please take it through your tree since KUnit maintainer is non-responsive
by unknown (to me) reasons.
include/kunit/assert.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/kunit/assert.h b/include/kunit/assert.h
index ad889b539ab3..ccbc36c0b02f 100644
--- a/include/kunit/assert.h
+++ b/include/kunit/assert.h
@@ -10,7 +10,7 @@
#define _KUNIT_ASSERT_H
#include <linux/err.h>
-#include <linux/kernel.h>
+#include <linux/printk.h>
struct kunit;
struct string_stream;
--
2.33.0