KVM: selftests: Create KVM selftests runner
Subsystems (4)
v4 cover KVM: selftests: Create KVM selftests runner
Hello,
This is v4 of KVM selftest runner.
To recap, KVM Selftest Runner allows running KVM selftests with added features not present in default kselftest infrastructure like parallelism, user friendly output, saving output hierarchically, etc. Check README file in the patch 9.
This series is also available on github at:
https://github.com/shvipin/linux kvm/selftests/runner-v4
v4:
- Copy runner code and default test case files to out-of-tree build directory.
- Added comparison with kernel selftest framework.
- Added python minimum version (3.6) check for the runner.
- Bug fix where runner was not handling the child process output if returned in bytes instead of string.
v3: https://lore.kernel.org/kvm/[email protected]/
- Created "tests_install" rule in Makefile.kvm to auto generate default testcases, which will be ignored in .gitignore.
- Changed command line option names to pass testcase files, directories, executable paths, print based on test status, and what to print. Removed certain other options based on feedback in v2.
- Merged command.py into selftest.py
- Fixed issue where timed out test's stdout and stderr were not printed.
- Reduced python version from 3.7 to 3.6.
- Fixed issue where test status numerical value was printed instead of text like PASSED, FAILED, SKIPPED, etc.
- Added README.rst.
v2: https://lore.kernel.org/kvm/[email protected]/
- Automatic default test generation.
- Command line flag to provide executables location
- Dump output to filesystem with timestamp
- Accept absolute path of *.test files/directory location
- Sticky status at bottom for the current state of runner.
- Knobs to control output verbosity
- Colored output for terminals.
v1: https://lore.kernel.org/kvm/[email protected]/
- Parallel test execution.
- Dumping separate output for each test.
- Timeout for test execution
- Specify single test or a test directory.
RFC: https://lore.kernel.org/kvm/[email protected]/
Vipin Sharma (9):
KVM: selftest: Create KVM selftest runner
KVM: selftests: Provide executables path option to the KVM selftest
runner
KVM: selftests: Add timeout option in selftests runner
KVM: selftests: Add option to save selftest runner output to a
directory
KVM: selftests: Run tests concurrently in KVM selftests runner
KVM: selftests: Add various print flags to KVM selftest runner
KVM: selftests: Print sticky KVM selftests runner status at bottom
KVM: selftests: Add rule to generate default tests for KVM selftests
runner
KVM: selftests: Provide README.rst for KVM selftests runner
tools/testing/selftests/kvm/.gitignore | 6 +- tools/testing/selftests/kvm/Makefile.kvm | 26 ++- tools/testing/selftests/kvm/runner/README.rst | 95 +++++++++ .../testing/selftests/kvm/runner/__main__.py | 189 ++++++++++++++++++ .../testing/selftests/kvm/runner/selftest.py | 99 +++++++++ .../selftests/kvm/runner/test_runner.py | 83 ++++++++ .../2slot_5vcpu_10iter.test | 1 + .../no_dirty_log_protect.test | 1 + 8 files changed, 498 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/kvm/runner/README.rst create mode 100644 tools/testing/selftests/kvm/runner/__main__.py create mode 100644 tools/testing/selftests/kvm/runner/selftest.py create mode 100644 tools/testing/selftests/kvm/runner/test_runner.py create mode 100644 tools/testing/selftests/kvm/tests/dirty_log_perf_test/2slot_5vcpu_10iter.test create mode 100644 tools/testing/selftests/kvm/tests/dirty_log_perf_test/no_dirty_log_protect.test
base-commit: df83746075778958954aa0460cca55f4b3fc9c02
Signature · 1 line
2.53.0.1118.gaef5881109-goog
PATCH v4 1/9 KVM: selftest: Create KVM selftest runner
Implement a basic KVM selftest runner in Python to run selftests. Add command line options to select individual testcase file or a directory containing multiple testcase files.
After selecting the tests to run, start their execution and print their final execution status (passed, failed, skipped, no run), stdout and stderr on terminal.
Print execution status in colors on the terminals where it is supported to easily distinguish different statuses of the tests execution.
If a test fails or times out, then return with a non-zero exit code after all of the tests execution have completed. If none of the tests fails or times out then exit with status 0
Provide some sample test configuration files to demonstrate the execution of the runner.
Runner can be started from tools/testing/selftests/kvm directory as:
python3 runner --dirs tests
OR
python3 runner --testcases \
tests/dirty_log_perf_test/no_dirty_log_protect.test
This is a very basic implementation of the runner. Next patches will enhance the runner by adding more features like parallelization, dumping output to file system, time limit, out-of-tree builds run, etc.
--- tools/testing/selftests/kvm/.gitignore | 4 +- .../testing/selftests/kvm/runner/__main__.py | 99 +++++++++++++++++++ .../testing/selftests/kvm/runner/selftest.py | 66 +++++++++++++ .../selftests/kvm/runner/test_runner.py | 37 +++++++ .../2slot_5vcpu_10iter.test | 1 + .../no_dirty_log_protect.test | 1 + 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/kvm/runner/__main__.py create mode 100644 tools/testing/selftests/kvm/runner/selftest.py create mode 100644 tools/testing/selftests/kvm/runner/test_runner.py create mode 100644 tools/testing/selftests/kvm/tests/dirty_log_perf_test/2slot_5vcpu_10iter.test create mode 100644 tools/testing/selftests/kvm/tests/dirty_log_perf_test/no_dirty_log_protect.test
tools/testing/selftests/kvm/.gitignore +3 -1
@@ -3,10 +3,12 @@ !/**/ !*.c !*.h +!*.py !*.S !*.sh +!*.test !.gitignore !config !settings !Makefile -!Makefile.kvm +!Makefile.kvm
tools/testing/selftests/kvm/runner/__main__.py new file +99 -0
99 lines not on this page · raw message
tools/testing/selftests/kvm/runner/selftest.py new file +66 -0
66 lines not on this page · raw message
tools/testing/selftests/kvm/runner/test_runner.py new file +37 -0
@@ -0,0 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright 2025 Google LLC +# +# Author: [email protected] (Vipin Sharma) + +import logging +from selftest import Selftest +from selftest import SelftestStatus + +logger = logging.getLogger("runner") + + +class TestRunner: + def __init__(self, testcases): + self.tests = [] + + for testcase in testcases: + self.tests.append(Selftest(testcase)) + + def _log_result(self, test_result): + logger.info("*** stdout ***\n" + test_result.stdout) + logger.info("*** stderr ***\n" + test_result.stderr) + logger.log(test_result.status, + f"[{test_result.status.name}] {test_result.test_path}") + + def start(self): + ret = 0 + + for test in self.tests: + test.run() + self._log_result(test) + + if (test.status not in [SelftestStatus.PASSED, + SelftestStatus.NO_RUN, + SelftestStatus.SKIPPED]): + ret = 1 + return ret
tools/testing/selftests/kvm/tests/dirty_log_perf_test/2slot_5vcpu_10iter.test new file +1 -0
@@ -0,0 +1 @@ +dirty_log_perf_test -x 2 -v 5 -i 10
tools/testing/selftests/kvm/tests/dirty_log_perf_test/no_dirty_log_protect.test new file +1 -0
@@ -0,0 +1 @@ +dirty_log_perf_test -g
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 15 lines · Vipin Sharma
[...snip...]
tools/testing/selftests/kvm/runner/__main__.py new file +12
-0+def setup_logging(): + class TerminalColorFormatter(logging.Formatter): + reset = "\033[0m" + red_bold = "\033[31;1m" + green = "\033[32m" + yellow = "\033[33m" + blue = "\033[34m" + + COLORS = { + SelftestStatus.PASSED: green, + SelftestStatus.NO_RUN: blue, + SelftestStatus.SKIPPED: yellow,
tools/testing/selftests/kvm/runner/__main__.py line 58
Quoted 10 lines
tools/testing/selftests/kvm/runner/__main__.py new file +10
-0+ SelftestStatus.FAILED: red_bold + } + + def __init__(self, fmt=None, datefmt=None): + super().__init__(fmt, datefmt) + + def format(self, record): + return (self.COLORS.get(record.levelno, "") + + super().format(record) + self.reset) +
The commit message above says the printing will be in colors when the terminal supports it, but if I'm reading this correctly, the colors will always be printed.
I was expecting something like if the output is piped to some file or like "not TTY" then don't print colors.
Would you consider not printing in color at all? Or adding some kind of "turn off all display magic" flag?
I also saw code for a sticky footer in another patch in this series, that's probably not nice for other stuff wrapping this runner.
Quoted 9 lines
tools/testing/selftests/kvm/runner/__main__.py new file +9
-0+ logger = logging.getLogger("runner") + logger.setLevel(logging.INFO) + + ch = logging.StreamHandler() + ch_formatter = TerminalColorFormatter(fmt="%(asctime)s | %(message)s", + datefmt="%H:%M:%S") + ch.setFormatter(ch_formatter) + logger.addHandler(ch) +
tools/testing/selftests/kvm/runner/__main__.py line 77
Quoted 10 lines
tools/testing/selftests/kvm/runner/__main__.py new file +10
-0+ +def fetch_testcases_in_dirs(dirs): + testcases = [] + for dir in dirs: + for root, child_dirs, files in os.walk(dir): + for file in files: + testcases.append(os.path.join(root, file)) + return testcases + +
Sean pointed me here from guest_memfd tests [1]. The Makefiles allow us to generate test configs at build time. For [1], I could configure all the test parameters statically or at build time.
[1] https://lore.kernel.org/all/[email protected]/
Perhaps for a future extension, but would you consider taking the output of some program as input for cases to run?
My (future) use case is that with hugepages, I want to run something like
./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18
And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
Quoted 12 lines
tools/testing/selftests/kvm/runner/__main__.py new file +12
-0+def fetch_testcases(args): + testcases = args.testcases + testcases.extend(fetch_testcases_in_dirs(args.dirs)) + # Remove duplicates + testcases = list(dict.fromkeys(testcases)) + return testcases + + +def main(): + args = cli() + setup_logging() + testcases = fetch_testcases(args)
tools/testing/selftests/kvm/runner/__main__.py line 99
Quoted 10 lines
tools/testing/selftests/kvm/runner/__main__.py new file +10
-0+ return TestRunner(testcases).start() + + +if __name__ == "__main__": + PYTHON_VERSION = (3, 6) + if sys.version_info < PYTHON_VERSION: + print(f"Minimum required python version {PYTHON_VERSION}, found {sys.version}") + sys.exit(1) + + sys.exit(main())
This shouldn't block merge: why not align with the kernel's official required python version?
Quoted 29 lines
[...snip...]
tools/testing/selftests/kvm/runner/selftest.py new file +26
-0+class Selftest: + """ + Represents a single selftest. + + Extract the test execution command from test file and executes it. + """ + + def __init__(self, test_path): + test_command = pathlib.Path(test_path).read_text().strip() + if not test_command: + raise ValueError("Empty test command in " + test_path) + + test_command = os.path.join(".", test_command) + self.exists = os.path.isfile(test_command.split(maxsplit=1)[0]) + self.test_path = test_path + self.command = test_command + self.status = SelftestStatus.NO_RUN + self.stdout = "" + self.stderr = "" + + def run(self): + if not self.exists: + self.stderr = "File doesn't exist." + return + + run_args = {
tools/testing/selftests/kvm/runner/selftest.py line 59
Quoted 10 lines
tools/testing/selftests/kvm/runner/selftest.py new file +10
-0+ "universal_newlines": True, + "shell": True, + "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE + } + proc = subprocess.run(self.command, **run_args) + + out, err = proc.stdout, proc.stderr + self.stdout = out.decode("utf-8", "replace") if isinstance(out, bytes) else (out or "") + self.stderr = err.decode("utf-8", "replace") if isinstance(err, bytes) else (err or "")
I think it would be useful to capture stdout and stderr in order that it was output, so that the output being saved shows everything interleaved. I think the order could be useful in debugging.
I can see benefits in knowing which was on stdout and which was on stderr too, so is there some way of having both?
tools/testing/selftests/kvm/runner/selftest.py line 66
Quoted 7 lines
tools/testing/selftests/kvm/runner/selftest.py new file +7
-0+ + if proc.returncode == 0: + self.status = SelftestStatus.PASSED + elif proc.returncode == 4: + self.status = SelftestStatus.SKIPPED + else: + self.status = SelftestStatus.FAILED
Using this class-based pattern requires us to do Selftest(test_path).run(). Would you consider using a function-based pattern, like run_selftest(test_path) instead?
Quoted 3 lines
[...snip...]
Sean Christopherson
reviewerRe: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 11 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 9 lines · Sean Christopherson
Quoted 8 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18
Quoted 7 lines
Quoted 3 lines
And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
That should work too. So at build time I'd make it define all the possible HugeTLB sizes on every arch, and then skip as necessary.
Why though, why not find the supported sizes at runtime?
Sean Christopherson
reviewerRe: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 15 lines · Ackerley Tng
Quoted 13 lines · Sean Christopherson
Quoted 11 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
Quoted 6 lines
Quoted 3 lines
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
That should work too. So at build time I'd make it define all the possible HugeTLB sizes on every arch, and then skip as necessary.
Not necessarily at "build time", the testcases can also come from your local environment.
Quoted 1 line
Why though, why not find the supported sizes at runtime?
You can find the supported sizes at runtime, just not in the test runner. I want the runner itself to be largely oblivious to what's its running. Disallowing more or less _any_ test specific configuration/setup in the runner is the only way I see of keeping the runner strictly focused on running tests/testcases.
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 26 lines · Sean Christopherson
Quoted 15 lines · Ackerley Tng
Quoted 13 lines · Sean Christopherson
Quoted 11 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
Quoted 6 lines
Quoted 3 lines
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
That should work too. So at build time I'd make it define all the possible HugeTLB sizes on every arch, and then skip as necessary.
Not necessarily at "build time", the testcases can also come from your local environment.
Quoted 6 lines
Quoted 1 line
Why though, why not find the supported sizes at runtime?
You can find the supported sizes at runtime, just not in the test runner. I want the runner itself to be largely oblivious to what's its running. Disallowing more or less _any_ test specific configuration/setup in the runner is the only way I see of keeping the runner strictly focused on running tests/testcases.
The runner should 100% focus on running tests, I think it's hard for the runner to avoid the process of test discovery though.
The current test discovery process is to go down the tree of directories and find files, 1 file == 1 testcase. Each file should (statically) contain a single command.
Since you're not opposed to runtime discovery of test cases, how about something like:
if the test case file has executable permissions
execute it and get back a list of test cases to be run.
else
read it as a single test case.
I'd then use the executable version, check HugeTLB setup on the machine under test and return bunch of separate commands to be run (each with a different HugeTLB size).
The runner still doesn't need to deal test-specific config, that's part of the executable that tells the runner what to run.
Sean Christopherson
reviewerRe: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 42 lines · Ackerley Tng
Quoted 26 lines · Sean Christopherson
Quoted 15 lines · Ackerley Tng
Quoted 13 lines · Sean Christopherson
Quoted 11 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
Quoted 6 lines
Quoted 3 lines
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
That should work too. So at build time I'd make it define all the possible HugeTLB sizes on every arch, and then skip as necessary.
Not necessarily at "build time", the testcases can also come from your local environment.
Quoted 6 lines
Quoted 1 line
Why though, why not find the supported sizes at runtime?
You can find the supported sizes at runtime, just not in the test runner. I want the runner itself to be largely oblivious to what's its running. Disallowing more or less _any_ test specific configuration/setup in the runner is the only way I see of keeping the runner strictly focused on running tests/testcases.
The runner should 100% focus on running tests, I think it's hard for the runner to avoid the process of test discovery though.
The current test discovery process is to go down the tree of directories and find files, 1 file == 1 testcase. Each file should (statically) contain a single command.
Quoted 5 lines
Since you're not opposed to runtime discovery of test cases, how about something like:
if the test case file has executable permissions
execute it and get back a list of test cases to be run.
I don't hate it, but I still dislike the idea. I am all in favor of runtime *discovery* of testcases, but I am staunchly opposed to runtime *definition* of testcases.
If I define guest_memfd testcases for 4KiB, 2MiB, and 1GiB pages, but the underlying system only support 4KiB and 2MiB, then I want to see a SKIP for the 1GiB testcase. If the definition is dynamic, then the 1GiB testcase simply won't exist.
Quoted 9 lines
else
read it as a single test case.I'd then use the executable version, check HugeTLB setup on the machine under test and return bunch of separate commands to be run (each with a different HugeTLB size).
The runner still doesn't need to deal test-specific config, that's part of the executable that tells the runner what to run.
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 49 lines · Sean Christopherson
Quoted 42 lines · Ackerley Tng
Quoted 26 lines · Sean Christopherson
Quoted 15 lines · Ackerley Tng
Quoted 13 lines · Sean Christopherson
Quoted 11 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
Quoted 6 lines
Quoted 3 lines
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
That should work too. So at build time I'd make it define all the possible HugeTLB sizes on every arch, and then skip as necessary.
Not necessarily at "build time", the testcases can also come from your local environment.
Quoted 6 lines
Quoted 1 line
Why though, why not find the supported sizes at runtime?
You can find the supported sizes at runtime, just not in the test runner. I want the runner itself to be largely oblivious to what's its running. Disallowing more or less _any_ test specific configuration/setup in the runner is the only way I see of keeping the runner strictly focused on running tests/testcases.
The runner should 100% focus on running tests, I think it's hard for the runner to avoid the process of test discovery though.
The current test discovery process is to go down the tree of directories and find files, 1 file == 1 testcase. Each file should (statically) contain a single command.
Quoted 5 lines
Since you're not opposed to runtime discovery of test cases, how about something like:
if the test case file has executable permissions
execute it and get back a list of test cases to be run.
Quoted 9 lines
I don't hate it, but I still dislike the idea. I am all in favor of runtime *discovery* of testcases, but I am staunchly opposed to runtime *definition* of testcases.
If I define
guest_memfdtestcases for 4KiB, 2MiB, and 1GiB pages, but the underlying system only support 4KiB and 2MiB, then I want to see a SKIP for the 1GiB testcase. If the definition is dynamic, then the 1GiB testcase simply won't exist.
Seeing the SKIP is a huge advantage over dynamic definition. Thanks for explaining. Makes a lot of sense now to have everything defined statically.
Quoted 9 lines
Quoted 9 lines
else
read it as a single test case.I'd then use the executable version, check HugeTLB setup on the machine under test and return bunch of separate commands to be run (each with a different HugeTLB size).
The runner still doesn't need to deal test-specific config, that's part of the executable that tells the runner what to run.
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 48 lines · Ackerley Tng
Quoted 46 lines · Sean Christopherson
Quoted 45 lines · Ackerley Tng
Quoted 26 lines · Sean Christopherson
Quoted 15 lines · Ackerley Tng
Quoted 13 lines · Sean Christopherson
Quoted 11 lines · Ackerley Tng
Vipin Sharma <[email protected]> writes:
My (future) use case is that with hugepages, I want to run something like./guest_memfd_test --order=0 ./guest_memfd_test --order=9 ./guest_memfd_test --order=18And 0, 9 and 18 are the supported HugeTLB orders on the machine being tested. I'd like to iterate over supported HugeTLB orders at runner runtime instead of at build time.
Quoted 6 lines
Quoted 3 lines
No. The right way to handle this is to define testcases for the "interesting" sizes, and then rely on the test itself to SKIP if the size is unsupported. This is no different than a test that requires EPT, or nested VMX, or nested SVM, etc.
That should work too. So at build time I'd make it define all the possible HugeTLB sizes on every arch, and then skip as necessary.
Not necessarily at "build time", the testcases can also come from your local environment.
Quoted 6 lines
Quoted 1 line
Why though, why not find the supported sizes at runtime?
You can find the supported sizes at runtime, just not in the test runner. I want the runner itself to be largely oblivious to what's its running. Disallowing more or less _any_ test specific configuration/setup in the runner is the only way I see of keeping the runner strictly focused on running tests/testcases.
The runner should 100% focus on running tests, I think it's hard for the runner to avoid the process of test discovery though.
The current test discovery process is to go down the tree of directories and find files, 1 file == 1 testcase. Each file should (statically) contain a single command.
Since you're not opposed to runtime discovery of test cases, how about something like:
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
if the test case file has executable permissions
execute it and get back a list of test cases to be run.I don't hate it, but I still dislike the idea. I am all in favor of runtime *discovery* of testcases, but I am staunchly opposed to runtime *definition* of testcases.
I don't think we should support this kind of usecase. Our goal is to keep test runner as simple as possible. This will add one extra parsing logic in the runner and also add more wrapper scripts in kvm selftests for tests to create their own dynamic variants.
If dynamic variation is needed, then there is one option in this runner. As testcases are executed by runner in a shell environment. This basically means the test will run as a shell script and provide variable expansion or call other terminal commands if present. One can define interesting configuration which can be dynamic based on the host in a testcase file. For example if one writes a test command as:
dirty_log_perf_test -x 1 -v $(nproc) -i $(( (RANDOM % 5) + 2 ))
This will run above dirty_log_perf_test with the number of vCPUs equal to the host CPU count and some randomly selected iteration count between 2 to 6.
This way one can provide interesting configurations which can test max of a system in a separate test directory which can be invoked when needed.
For predefined input values of a test, either one can write multiple *.test files or use kselftest harness and add kselftest API based test cases. Both option will still require that test should SKIP if something needed is not present on the host as mentioned below.
Quoted 10 lines
Quoted 6 lines
If I define
guest_memfdtestcases for 4KiB, 2MiB, and 1GiB pages, but the underlying system only support 4KiB and 2MiB, then I want to see a SKIP for the 1GiB testcase. If the definition is dynamic, then the 1GiB testcase simply won't exist.Seeing the SKIP is a huge advantage over dynamic definition. Thanks for explaining. Makes a lot of sense now to have everything defined statically.
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
In reply to Ackerley TngQuoted 23 lines · Ackerley Tng
Quoted 21 lines · Vipin Sharma
[...snip...]
tools/testing/selftests/kvm/runner/__main__.py new file +18
-0+def setup_logging(): + class TerminalColorFormatter(logging.Formatter): + reset = "\033[0m" + red_bold = "\033[31;1m" + green = "\033[32m" + yellow = "\033[33m" + blue = "\033[34m" + + COLORS = { + SelftestStatus.PASSED: green, + SelftestStatus.NO_RUN: blue, + SelftestStatus.SKIPPED: yellow, + SelftestStatus.FAILED: red_bold + } + + def __init__(self, fmt=None, datefmt=None): + super().__init__(fmt, datefmt) +
Quoted 8 lines
tools/testing/selftests/kvm/runner/__main__.py line 58
Quoted 4 lines
tools/testing/selftests/kvm/runner/__main__.py new file +4
-0+ def format(self, record): + return (self.COLORS.get(record.levelno, "") + + super().format(record) + self.reset) +The commit message above says the printing will be in colors when the terminal supports it, but if I'm reading this correctly, the colors will always be printed.
I meant if a terminal doesn't have support for printing color output then it won't be printed in color. Almost all modern terminal supports these ANSI escape sequence, so it will always be printed. Its kind of a dumb statement I wrote in the commit log.
Quoted 6 lines
I was expecting something like if the output is piped to some file or like "not TTY" then don't print colors.
Would you consider not printing in color at all? Or adding some kind of "turn off all display magic" flag?
Good point about color on/off. I can make following changes in following priority, starting with the highest:
1. If NO_COLOR enivornment variable is set then don't print color at all.
2. If FORCE_COLOR environment variable is set then print color (default).
3. If output is not TTY then don't print color.
4. Print color.
Quoted 4 lines
I also saw code for a sticky footer in another patch in this series, that's probably not nice for other stuff wrapping this runner.
For sticky update, I can hide it if there is no TTY.
Quoted 11 lines
tools/testing/selftests/kvm/runner/__main__.py line 99
Quoted 7 lines
tools/testing/selftests/kvm/runner/__main__.py new file +7
-0+if __name__ == "__main__": + PYTHON_VERSION = (3, 6) + if sys.version_info < PYTHON_VERSION: + print(f"Minimum required python version {PYTHON_VERSION}, found {sys.version}") + sys.exit(1) + + sys.exit(main())This shouldn't block merge: why not align with the kernel's official required python version?
When I first proposed official version was 3.5, it got upgraded to 3.9 in commit 5e25b972a22b ("docs: changes: update Python minimal version")
I was using some APIs which were not present in 3.5 and 3.6 was the minimum version I was able to run all the features I needed.
It just stayed that version and I never checked to keep it in sync with the latest python version.
Quoted 17 lines
tools/testing/selftests/kvm/runner/selftest.py line 59
Quoted 12 lines
tools/testing/selftests/kvm/runner/selftest.py new file +12
-0+ + run_args = { + "universal_newlines": True, + "shell": True, + "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE + } + proc = subprocess.run(self.command, **run_args) + + out, err = proc.stdout, proc.stderr + self.stdout = out.decode("utf-8", "replace") if isinstance(out, bytes) else (out or "") + self.stderr = err.decode("utf-8", "replace") if isinstance(err, bytes) else (err or "")I think it would be useful to capture stdout and stderr in order that it was output, so that the output being saved shows everything interleaved. I think the order could be useful in debugging.
Quoted 3 lines
I can see benefits in knowing which was on stdout and which was on stderr too, so is there some way of having both?
Both approaches are useful, I am not sure how to achieve what you are asking reliably.
However, I think separate stdout and stderr is more useful in automation/CI tools. Considering, runner is for the human use I am more inclined on having combined output of stdout and stderr as you are suggsting.
I will change it to combined output in next version, new filename will be "out" consisting of both stdout and stderr. If there is ever need for separate dumps we can revisit it.
One thing we will lose is in current approach, non-zero stderr is signal of finding errored out runs. Not a big loss as same information can be grepped using master log file.
Quoted 8 lines
tools/testing/selftests/kvm/runner/selftest.py line 66
Quoted 7 lines
tools/testing/selftests/kvm/runner/selftest.py new file +7
-0+ + if proc.returncode == 0: + self.status = SelftestStatus.PASSED + elif proc.returncode == 4: + self.status = SelftestStatus.SKIPPED + else: + self.status = SelftestStatus.FAILED
Quoted 4 lines
Using this class-based pattern requires us to do Selftest(test_path).run(). Would you consider using a function-based pattern, like
run_selftest(test_path)instead?
I find current class model provides an easy way to group data in hierarchy. For example, test_runner has list of selftests which it needs to execute. Selftests have their own test command, output data, result status, etc.
Both are suitable to implement runner. But I am little hesitant to change it now considering it is already written. If you can provide benefits of using functions approach here then I am open to rewrite.
Quoted 3 lines
Quoted 3 lines
[...snip...]
Re: [PATCH v4 1/9] KVM: selftest: Create KVM selftest runner
Quoted 13 lines · Vipin Sharma
[...snip...]
Quoted 6 lines
I was expecting something like if the output is piped to some file or like "not TTY" then don't print colors.
Would you consider not printing in color at all? Or adding some kind of "turn off all display magic" flag?
Good point about color on/off. I can make following changes in following priority, starting with the highest:
Quoted 7 lines
1. If
NO_COLORenivornment variable is set then don't print color at all.
2. IfFORCE_COLORenvironment variable is set then print color (default).
3. If output is not TTY then don't print color.
4. Print color.
I think we can take reference from what grep does.
+ --color=auto (default), if output is piped or redirected, no color.
+ --color=always
+ --color=never
Quoted 18 lines
Quoted 4 lines
I also saw code for a sticky footer in another patch in this series, that's probably not nice for other stuff wrapping this runner.
For sticky update, I can hide it if there is no TTY.
Quoted 11 lines
tools/testing/selftests/kvm/runner/__main__.py line 99
Quoted 7 lines
tools/testing/selftests/kvm/runner/__main__.py new file +7
-0+if __name__ == "__main__": + PYTHON_VERSION = (3, 6) + if sys.version_info < PYTHON_VERSION: + print(f"Minimum required python version {PYTHON_VERSION}, found {sys.version}") + sys.exit(1) + + sys.exit(main())This shouldn't block merge: why not align with the kernel's official required python version?
Quoted 9 lines
When I first proposed official version was 3.5, it got upgraded to 3.9 in commit
5e25b972a22b("docs: changes: update Python minimal version")I was using some APIs which were not present in 3.5 and 3.6 was the minimum version I was able to run all the features I needed.
It just stayed that version and I never checked to keep it in sync with the latest python version.
I see, no worries, not a huge issue.
Quoted 28 lines
Quoted 17 lines
tools/testing/selftests/kvm/runner/selftest.py line 59
Quoted 12 lines
tools/testing/selftests/kvm/runner/selftest.py new file +12
-0+ + run_args = { + "universal_newlines": True, + "shell": True, + "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE + } + proc = subprocess.run(self.command, **run_args) + + out, err = proc.stdout, proc.stderr + self.stdout = out.decode("utf-8", "replace") if isinstance(out, bytes) else (out or "") + self.stderr = err.decode("utf-8", "replace") if isinstance(err, bytes) else (err or "")I think it would be useful to capture stdout and stderr in order that it was output, so that the output being saved shows everything interleaved. I think the order could be useful in debugging.
Quoted 3 lines
I can see benefits in knowing which was on stdout and which was on stderr too, so is there some way of having both?
Both approaches are useful, I am not sure how to achieve what you are asking reliably.
However, I think separate stdout and stderr is more useful in automation/CI tools. Considering, runner is for the human use I am more inclined on having combined output of stdout and stderr as you are suggsting.
Quoted 8 lines
I will change it to combined output in next version, new filename will be "out" consisting of both stdout and stderr. If there is ever need for separate dumps we can revisit it.
One thing we will lose is in current approach, non-zero stderr is signal of finding errored out runs. Not a big loss as same information can be grepped using master log file.
Here's an idea to have both:
import selectors
process = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
bufsize=1,
)
sel = selectors.DefaultSelector() sel.register(process.stdout, selectors.EVENT_READ) sel.register(process.stderr, selectors.EVENT_READ)
output_lines = []
stdout_lines = []
stderr_lines = []
while True:
events = sel.select()
for key, mask in events:
line = key.fileobj.readline()
if not line:
sel.unregister(key.fileobj)
continue
if key.fileobj is process.stdout:
# append to stdout_lines... Might need to deal
with newlines?
# perhaps even print it from the runner's stdout, so
# the runner gives faster feedback for a human
elif key.fileobj is process.stderr:
# do something equivalent for stderr_lines output_lines.append(line)
if not sel.get_map():
break
process.wait()
I'm also okay if it's first combined, and this can be an extension if it's really needed.
Quoted 18 lines
Quoted 8 lines
tools/testing/selftests/kvm/runner/selftest.py line 66
Quoted 7 lines
tools/testing/selftests/kvm/runner/selftest.py new file +7
-0+ + if proc.returncode == 0: + self.status = SelftestStatus.PASSED + elif proc.returncode == 4: + self.status = SelftestStatus.SKIPPED + else: + self.status = SelftestStatus.FAILEDQuoted 4 lines
Using this class-based pattern requires us to do Selftest(test_path).run(). Would you consider using a function-based pattern, like
run_selftest(test_path)instead?I find current class model provides an easy way to group data in hierarchy. For example,
test_runnerhas list of selftests which it needs to execute. Selftests have their own test command, output data, result status, etc.
Quoted 5 lines
Both are suitable to implement runner. But I am little hesitant to change it now considering it is already written. If you can provide benefits of using functions approach here then I am open to rewrite.
I think the classes approach introduces more boilerplate which isn't necessary. I don't think there's any state stored in the classes and so this is a good fit for using functions. After removing the boilerplate, we might actually be able to put everything nicely into 1 file! That's not to say classes can't be in 1 file, I think we're more used to classes being in separate files.
__main__.py is already mostly in a non-class style, which makes the rest being in the class style more jarring.
Most of the kernel is C which is mostly procedural where you need to implement your own OOP, so I wish the accompanying python would follow a more procedural/function-based style rather than directly reach for OO.
I'm also heavily influenced by Jack Diederich's talk [1], which is a fun talk but may be too long to watch, so [2] is a text overview.
[1] https://youtu.be/o9pEzgHorH0
[2] https://szuckerman.github.io/stop_writing_classes.html
I guess this might be more of a philosophy/preference thing, feel free to go ahead if others express preference for the class style.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
[...snip...]
PATCH v4 2/9 KVM: selftests: Provide executables path option to the KVM selftest runner
In reply to Vipin SharmaAdd command line option, -p/--path, to specify the directory where test binaries exist. If this option is not provided then default to the current directory.
Example:
python3 runner --dirs test -p ~/build/selftests
This option enables executing tests from out-of-tree builds.
--- tools/testing/selftests/kvm/runner/__main__.py | 8 +++++++- tools/testing/selftests/kvm/runner/selftest.py | 4 ++-- tools/testing/selftests/kvm/runner/test_runner.py | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-)
tools/testing/selftests/kvm/runner/__main__.py +7 -1
@@ -31,6 +31,12 @@ def cli(): default=[], help="Run the testcases present in the given directory and all of its sub directories. Provide the space separated paths to add multiple directories.") + parser.add_argument("-p", + "--path", + nargs='?', + default=".", + help="Finds the test executables in the given path. Default is the current directory.") + return parser.parse_args()
@@ -87,7 +93,7 @@ def main(): args = cli() setup_logging() testcases = fetch_testcases(args) - return TestRunner(testcases).start() + return TestRunner(testcases, args).start() if __name__ == "__main__":
tools/testing/selftests/kvm/runner/selftest.py +2 -2
@@ -28,12 +28,12 @@ class Selftest: Extract the test execution command from test file and executes it. """ - def __init__(self, test_path): + def __init__(self, test_path, path): test_command = pathlib.Path(test_path).read_text().strip() if not test_command: raise ValueError("Empty test command in " + test_path) - test_command = os.path.join(".", test_command) + test_command = os.path.join(path, test_command) self.exists = os.path.isfile(test_command.split(maxsplit=1)[0]) self.test_path = test_path self.command = test_command
tools/testing/selftests/kvm/runner/test_runner.py +2 -2
@@ -11,11 +11,11 @@ logger = logging.getLogger("runner") class TestRunner: - def __init__(self, testcases): + def __init__(self, testcases, args): self.tests = [] for testcase in testcases: - self.tests.append(Selftest(testcase)) + self.tests.append(Selftest(testcase, args.path)) def _log_result(self, test_result): logger.info("*** stdout ***\n" + test_result.stdout)
Signature · 1 line
2.53.0.1118.gaef5881109-goog
PATCH v4 3/9 KVM: selftests: Add timeout option in selftests runner
In reply to Vipin SharmaAdd a command line argument in KVM selftest runner to limit amount of time (seconds) given to a test for execution. Kill the test if it exceeds the given timeout. Define a new SelftestStatus.TIMED_OUT to denote a selftest final result. Add terminal color for status messages of timed out tests.
Set the default value of 120 seconds for all tests.
--- .../testing/selftests/kvm/runner/__main__.py | 9 +++++- .../testing/selftests/kvm/runner/selftest.py | 29 ++++++++++++------- .../selftests/kvm/runner/test_runner.py | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-)
tools/testing/selftests/kvm/runner/__main__.py +8 -1
@@ -37,6 +37,11 @@ def cli(): default=".", help="Finds the test executables in the given path. Default is the current directory.") + parser.add_argument("--timeout", + default=120, + type=int, + help="Timeout, in seconds, before runner kills the running test. (Default: 120 seconds)") + return parser.parse_args()
@@ -44,6 +49,7 @@ def setup_logging(): class TerminalColorFormatter(logging.Formatter): reset = "\033[0m" red_bold = "\033[31;1m" + red = "\033[31;1m" green = "\033[32m" yellow = "\033[33m" blue = "\033[34m"
@@ -52,7 +58,8 @@ def setup_logging(): SelftestStatus.PASSED: green, SelftestStatus.NO_RUN: blue, SelftestStatus.SKIPPED: yellow, - SelftestStatus.FAILED: red_bold + SelftestStatus.FAILED: red_bold, + SelftestStatus.TIMED_OUT: red } def __init__(self, fmt=None, datefmt=None):
tools/testing/selftests/kvm/runner/selftest.py +18 -11
@@ -17,6 +17,7 @@ class SelftestStatus(enum.IntEnum): NO_RUN = 22 SKIPPED = 23 FAILED = 24 + TIMED_OUT = 25 def __str__(self): return str.__str__(self.name)
@@ -28,7 +29,7 @@ class Selftest: Extract the test execution command from test file and executes it. """ - def __init__(self, test_path, path): + def __init__(self, test_path, path, timeout): test_command = pathlib.Path(test_path).read_text().strip() if not test_command: raise ValueError("Empty test command in " + test_path)
@@ -37,6 +38,7 @@ class Selftest: self.exists = os.path.isfile(test_command.split(maxsplit=1)[0]) self.test_path = test_path self.command = test_command + self.timeout = timeout self.status = SelftestStatus.NO_RUN self.stdout = "" self.stderr = ""
@@ -50,17 +52,22 @@ class Selftest: "universal_newlines": True, "shell": True, "stdout": subprocess.PIPE, - "stderr": subprocess.PIPE + "stderr": subprocess.PIPE, + "timeout": self.timeout, } - proc = subprocess.run(self.command, **run_args) + try: + proc = subprocess.run(self.command, **run_args) + out, err = proc.stdout, proc.stderr + + if proc.returncode == 0: + self.status = SelftestStatus.PASSED + elif proc.returncode == 4: + self.status = SelftestStatus.SKIPPED + else: + self.status = SelftestStatus.FAILED + except subprocess.TimeoutExpired as e: + self.status = SelftestStatus.TIMED_OUT + out, err = e.stdout, e.stderr - out, err = proc.stdout, proc.stderr self.stdout = out.decode("utf-8", "replace") if isinstance(out, bytes) else (out or "") self.stderr = err.decode("utf-8", "replace") if isinstance(err, bytes) else (err or "") - - if proc.returncode == 0: - self.status = SelftestStatus.PASSED - elif proc.returncode == 4: - self.status = SelftestStatus.SKIPPED - else: - self.status = SelftestStatus.FAILED
tools/testing/selftests/kvm/runner/test_runner.py +1 -1
@@ -15,7 +15,7 @@ class TestRunner: self.tests = [] for testcase in testcases: - self.tests.append(Selftest(testcase, args.path)) + self.tests.append(Selftest(testcase, args.path, args.timeout)) def _log_result(self, test_result): logger.info("*** stdout ***\n" + test_result.stdout)
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Sean Christopherson
reviewerRe: [PATCH v4 3/9] KVM: selftests: Add timeout option in selftests runner
Quoted 40 lines · Vipin Sharma
Add a command line argument in KVM selftest runner to limit amount of time (seconds) given to a test for execution. Kill the test if it exceeds the given timeout. Define a new SelftestStatus.TIMED_OUT to denote a selftest final result. Add terminal color for status messages of timed out tests.
Set the default value of 120 seconds for all tests.
Signed-off-by Vipin Sharma <[email protected]>--- .../testing/selftests/kvm/runner/__main__.py | 9 +++++- .../testing/selftests/kvm/runner/selftest.py | 29 ++++++++++++------- .../selftests/kvm/runner/test_runner.py | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-)tools/testing/selftests/kvm/runner/__main__.py +6
-0@@ -37,6 +37,11 @@ def cli(): default=".", help="Finds the test executables in the given path. Default is the current directory.") + parser.add_argument("--timeout", + default=120, + type=int, + help="Timeout, in seconds, before runner kills the running test. (Default: 120 seconds)") + return parser.parse_args()@@ -44,6 +49,7 @@ def setup_logging(): class TerminalColorFormatter(logging.Formatter): reset = "\033[0m" red_bold = "\033[31;1m" + red = "\033[31;1m" green = "\033[32m" yellow = "\033[33m" blue = "\033[34m"
tools/testing/selftests/kvm/runner/__main__.py def setup_logging(): · line 62
Quoted 6 lines
tools/testing/selftests/kvm/runner/__main__.py +2
-1@@ -52,7 +58,8 @@ def setup_logging(): SelftestStatus.PASSED: green, SelftestStatus.NO_RUN: blue, SelftestStatus.SKIPPED: yellow, - SelftestStatus.FAILED: red_bold + SelftestStatus.FAILED: red_bold, + SelftestStatus.TIMED_OUT: red
Responding here because it's easier to see...
In my experience, uniquely identifying segfaults can be super helpful, e.g. (with the stderr/stdout changes too).
tools/testing/selftests/kvm/runner/__main__.py +1 -0
@@ -122,6 +122,7 @@ def setup_logging(args): SelftestStatus.NO_RUN: blue, SelftestStatus.SKIPPED: yellow, SelftestStatus.FAILED: red_bold, + SelftestStatus.SEGFAULT: red_bold, SelftestStatus.TIMED_OUT: red }
tools/testing/selftests/kvm/runner/selftest.py +4 -1
@@ -18,7 +18,8 @@ class SelftestStatus(enum.IntEnum): NO_RUN = 22 SKIPPED = 23 FAILED = 24 - TIMED_OUT = 25 + SEGFAULT = 25 + TIMED_OUT = 26 def __str__(self): return str.__str__(self.name)
@@ -63,6 +64,8 @@ class Selftest: self.status = SelftestStatus.PASSED elif proc.returncode == 4: self.status = SelftestStatus.SKIPPED + elif proc.returncode == 139: + self.state = SelftestStatus.SEGFAULT else: self.status = SelftestStatus.FAILED except subprocess.TimeoutExpired as e:
tools/testing/selftests/kvm/runner/test_runner.py +8 -2
@@ -21,6 +21,7 @@ class TestRunner: self.print_stds = { SelftestStatus.PASSED: args.print_passed, SelftestStatus.FAILED: args.print_failed, + SelftestStatus.SEGFAULT: args.print_failed, SelftestStatus.SKIPPED: args.print_skipped, SelftestStatus.TIMED_OUT: args.print_timed_out, SelftestStatus.NO_RUN: args.print_no_run
@@ -38,6 +39,7 @@ class TestRunner: print(f"\r\033[1mTotal: {self.tests_ran}/{len(self.tests)}" \ f"\033[32;1m Passed: {self.status[SelftestStatus.PASSED]}" \ f"\033[31;1m Failed: {self.status[SelftestStatus.FAILED]}" \ + f"\033[31;1m Segfaults: {self.status[SelftestStatus.SEGFAULT]}" \ f"\033[33;1m Skipped: {self.status[SelftestStatus.SKIPPED]}"\ f"\033[91;1m Timed Out: {self.status[SelftestStatus.TIMED_OUT]}"\ f"\033[34;1m No Run: {self.status[SelftestStatus.NO_RUN]}\033[0m",
@@ -47,10 +49,14 @@ class TestRunner: print_level = self.print_stds.get(test_result.status, "full") print("\033[2K", end="\r", flush=True) - if (print_level == "full" or print_level == "stdout"): + if (print_level == "full"): logger.info("*** stdout ***\n" + test_result.stdout) - if (print_level == "full" or print_level == "stderr"): logger.info("*** stderr ***\n" + test_result.stderr) + elif (print_level == "stdout"): + logger.info(test_result.stdout) + elif (print_level == "stderr"): + logger.info(test_result.stderr) + if (print_level != "off"): logger.log(test_result.status, f"[{test_result.status.name}] {test_result.test_path}")
Re: [PATCH v4 3/9] KVM: selftests: Add timeout option in selftests runner
Quoted 50 lines · Sean Christopherson
Quoted 40 lines · Vipin Sharma
Add a command line argument in KVM selftest runner to limit amount of time (seconds) given to a test for execution. Kill the test if it exceeds the given timeout. Define a new SelftestStatus.TIMED_OUT to denote a selftest final result. Add terminal color for status messages of timed out tests.
Set the default value of 120 seconds for all tests.
Signed-off-by Vipin Sharma <[email protected]>--- .../testing/selftests/kvm/runner/__main__.py | 9 +++++- .../testing/selftests/kvm/runner/selftest.py | 29 ++++++++++++------- .../selftests/kvm/runner/test_runner.py | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-)tools/testing/selftests/kvm/runner/__main__.py +6
-0@@ -37,6 +37,11 @@ def cli(): default=".", help="Finds the test executables in the given path. Default is the current directory.") + parser.add_argument("--timeout", + default=120, + type=int, + help="Timeout, in seconds, before runner kills the running test. (Default: 120 seconds)") + return parser.parse_args()@@ -44,6 +49,7 @@ def setup_logging(): class TerminalColorFormatter(logging.Formatter): reset = "\033[0m" red_bold = "\033[31;1m" + red = "\033[31;1m" green = "\033[32m" yellow = "\033[33m" blue = "\033[34m"tools/testing/selftests/kvm/runner/__main__.py def setup_logging(): · line 62
Quoted 6 lines
tools/testing/selftests/kvm/runner/__main__.py +2
-1@@ -52,7 +58,8 @@ def setup_logging(): SelftestStatus.PASSED: green, SelftestStatus.NO_RUN: blue, SelftestStatus.SKIPPED: yellow, - SelftestStatus.FAILED: red_bold + SelftestStatus.FAILED: red_bold, + SelftestStatus.TIMED_OUT: redResponding here because it's easier to see...
Quoted 2 lines
In my experience, uniquely identifying segfaults can be super helpful, e.g. (with the stderr/stdout changes too).
Sounds good to me, patch below looks fine.
Quoted 72 lines
tools/testing/selftests/kvm/runner/__main__.py +1
-0@@ -122,6 +122,7 @@ def setup_logging(args): SelftestStatus.NO_RUN: blue, SelftestStatus.SKIPPED: yellow, SelftestStatus.FAILED: red_bold, + SelftestStatus.SEGFAULT: red_bold, SelftestStatus.TIMED_OUT: red }tools/testing/selftests/kvm/runner/selftest.py +4
-1@@ -18,7 +18,8 @@ class SelftestStatus(enum.IntEnum): NO_RUN = 22 SKIPPED = 23 FAILED = 24 - TIMED_OUT = 25 + SEGFAULT = 25 + TIMED_OUT = 26 def __str__(self): return str.__str__(self.name)@@ -63,6 +64,8 @@ class Selftest: self.status = SelftestStatus.PASSED elif proc.returncode == 4: self.status = SelftestStatus.SKIPPED + elif proc.returncode == 139: + self.state = SelftestStatus.SEGFAULT else: self.status = SelftestStatus.FAILED except subprocess.TimeoutExpired as e:tools/testing/selftests/kvm/runner/test_runner.py +8
-2@@ -21,6 +21,7 @@ class TestRunner: self.print_stds = { SelftestStatus.PASSED: args.print_passed, SelftestStatus.FAILED: args.print_failed, + SelftestStatus.SEGFAULT: args.print_failed, SelftestStatus.SKIPPED: args.print_skipped, SelftestStatus.TIMED_OUT: args.print_timed_out, SelftestStatus.NO_RUN: args.print_no_run@@ -38,6 +39,7 @@ class TestRunner: print(f"\r\033[1mTotal: {self.tests_ran}/{len(self.tests)}" \ f"\033[32;1m Passed: {self.status[SelftestStatus.PASSED]}" \ f"\033[31;1m Failed: {self.status[SelftestStatus.FAILED]}" \ + f"\033[31;1m Segfaults: {self.status[SelftestStatus.SEGFAULT]}" \ f"\033[33;1m Skipped: {self.status[SelftestStatus.SKIPPED]}"\ f"\033[91;1m Timed Out: {self.status[SelftestStatus.TIMED_OUT]}"\ f"\033[34;1m No Run: {self.status[SelftestStatus.NO_RUN]}\033[0m",@@ -47,10 +49,14 @@ class TestRunner: print_level = self.print_stds.get(test_result.status, "full") print("\033[2K", end="\r", flush=True) - if (print_level == "full" or print_level == "stdout"): + if (print_level == "full"): logger.info("*** stdout ***\n" + test_result.stdout) - if (print_level == "full" or print_level == "stderr"): logger.info("*** stderr ***\n" + test_result.stderr) + elif (print_level == "stdout"): + logger.info(test_result.stdout) + elif (print_level == "stderr"): + logger.info(test_result.stderr) + if (print_level != "off"): logger.log(test_result.status, f"[{test_result.status.name}] {test_result.test_path}")
PATCH v4 4/9 KVM: selftests: Add option to save selftest runner output to a directory
In reply to Vipin SharmaAdd a command line flag, -o/--output, to selftest runner which enables it to save individual tests output (stdout & stderr) stream to a directory in a hierarchical way. Create folder hierarchy same as tests hieararcy given by --testcases and --dirs.
Also, add a command line flag, --append-output-time, which will append timestamp (format YYYY.M.DD.HH.MM.SS) to the directory name given in --output flag.
Example:
python3 runner --dirs test -o test_result --append_output_time
This will create test_result.2025.06.06.08.45.57 directory.
--- .../testing/selftests/kvm/runner/__main__.py | 34 +++++++++++++++-- .../testing/selftests/kvm/runner/selftest.py | 38 ++++++++++++++++--- .../selftests/kvm/runner/test_runner.py | 4 +- 3 files changed, 65 insertions(+), 11 deletions(-)
tools/testing/selftests/kvm/runner/__main__.py +30 -4
@@ -7,6 +7,8 @@ import argparse import logging import os import sys +import datetime +import pathlib from test_runner import TestRunner from selftest import SelftestStatus
@@ -42,10 +44,20 @@ def cli(): type=int, help="Timeout, in seconds, before runner kills the running test. (Default: 120 seconds)") + parser.add_argument("-o", + "--output", + nargs='?', + help="Dumps test runner output which includes each test execution result, their stdouts and stderrs hierarchically in the given directory.") + + parser.add_argument("--append-output-time", + action="store_true", + default=False, + help="Appends timestamp to the output directory.") + return parser.parse_args() -def setup_logging(): +def setup_logging(args): class TerminalColorFormatter(logging.Formatter): reset = "\033[0m" red_bold = "\033[31;1m"
@@ -72,12 +84,26 @@ def setup_logging(): logger = logging.getLogger("runner") logger.setLevel(logging.INFO) + formatter_args = { + "fmt": "%(asctime)s | %(message)s", + "datefmt": "%H:%M:%S" + } + ch = logging.StreamHandler() - ch_formatter = TerminalColorFormatter(fmt="%(asctime)s | %(message)s", - datefmt="%H:%M:%S") + ch_formatter = TerminalColorFormatter(**formatter_args) ch.setFormatter(ch_formatter) logger.addHandler(ch) + if args.output != None: + if (args.append_output_time): + args.output += datetime.datetime.now().strftime(".%Y.%m.%d.%H.%M.%S") + pathlib.Path(args.output).mkdir(parents=True, exist_ok=True) + logging_file = os.path.join(args.output, "log") + fh = logging.FileHandler(logging_file) + fh_formatter = logging.Formatter(**formatter_args) + fh.setFormatter(fh_formatter) + logger.addHandler(fh) + def fetch_testcases_in_dirs(dirs): testcases = []
@@ -98,7 +124,7 @@ def fetch_testcases(args): def main(): args = cli() - setup_logging() + setup_logging(args) testcases = fetch_testcases(args) return TestRunner(testcases, args).start()
tools/testing/selftests/kvm/runner/selftest.py +32 -6
@@ -7,6 +7,7 @@ import pathlib import enum import os import subprocess +import contextlib class SelftestStatus(enum.IntEnum): """
@@ -29,7 +30,7 @@ class Selftest: Extract the test execution command from test file and executes it. """ - def __init__(self, test_path, path, timeout): + def __init__(self, test_path, path, timeout, output_dir): test_command = pathlib.Path(test_path).read_text().strip() if not test_command: raise ValueError("Empty test command in " + test_path)
@@ -39,15 +40,14 @@ class Selftest: self.test_path = test_path self.command = test_command self.timeout = timeout + if output_dir is not None: + output_dir = os.path.join(output_dir, test_path.lstrip("./")) + self.output_dir = output_dir self.status = SelftestStatus.NO_RUN self.stdout = "" self.stderr = "" - def run(self): - if not self.exists: - self.stderr = "File doesn't exist." - return - + def _run(self, output=None, error=None): run_args = { "universal_newlines": True, "shell": True,
@@ -70,4 +70,30 @@ class Selftest: out, err = e.stdout, e.stderr self.stdout = out.decode("utf-8", "replace") if isinstance(out, bytes) else (out or "") + if output is not None: + output.write(self.stdout) + self.stderr = err.decode("utf-8", "replace") if isinstance(err, bytes) else (err or "") + if error is not None: + error.write(self.stderr) + + def run(self): + if not self.exists: + self.stderr = "File doesn't exist." + return + + if self.output_dir is not None: + pathlib.Path(self.output_dir).mkdir(parents=True, exist_ok=True) + + output = None + error = None + with contextlib.ExitStack() as stack: + if self.output_dir is not None: + output_path = os.path.join(self.output_dir, "stdout") + output = stack.enter_context( + open(output_path, encoding="utf-8", mode="w")) + + error_path = os.path.join(self.output_dir, "stderr") + error = stack.enter_context( + open(error_path, encoding="utf-8", mode="w")) + return self._run(output, error)
tools/testing/selftests/kvm/runner/test_runner.py +3 -1
@@ -13,9 +13,11 @@ logger = logging.getLogger("runner") class TestRunner: def __init__(self, testcases, args): self.tests = [] + self.output_dir = args.output for testcase in testcases: - self.tests.append(Selftest(testcase, args.path, args.timeout)) + self.tests.append(Selftest(testcase, args.path, args.timeout, + args.output)) def _log_result(self, test_result): logger.info("*** stdout ***\n" + test_result.stdout)
Signature · 1 line
2.53.0.1118.gaef5881109-goog
PATCH v4 5/9 KVM: selftests: Run tests concurrently in KVM selftests runner
In reply to Vipin SharmaAdd a command line argument, --jobs, to specify how many tests can execute concurrently. Set default to 1.
Example:
python3 runner --test-dirs tests -j 10
--- .../testing/selftests/kvm/runner/__main__.py | 6 ++++ .../selftests/kvm/runner/test_runner.py | 28 +++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-)
tools/testing/selftests/kvm/runner/__main__.py +6 -0
@@ -54,6 +54,12 @@ def cli(): default=False, help="Appends timestamp to the output directory.") + parser.add_argument("-j", + "--jobs", + default=1, + type=int, + help="Maximum number of tests that can be run concurrently. (Default: 1)") + return parser.parse_args()
tools/testing/selftests/kvm/runner/test_runner.py +20 -8
@@ -4,6 +4,8 @@ # Author: [email protected] (Vipin Sharma) import logging +import concurrent.futures + from selftest import Selftest from selftest import SelftestStatus
@@ -14,11 +16,16 @@ class TestRunner: def __init__(self, testcases, args): self.tests = [] self.output_dir = args.output + self.jobs = args.jobs for testcase in testcases: self.tests.append(Selftest(testcase, args.path, args.timeout, args.output)) + def _run_test(self, test): + test.run() + return test + def _log_result(self, test_result): logger.info("*** stdout ***\n" + test_result.stdout) logger.info("*** stderr ***\n" + test_result.stderr)
@@ -28,12 +35,17 @@ class TestRunner: def start(self): ret = 0 - for test in self.tests: - test.run() - self._log_result(test) - - if (test.status not in [SelftestStatus.PASSED, - SelftestStatus.NO_RUN, - SelftestStatus.SKIPPED]): - ret = 1 + with concurrent.futures.ProcessPoolExecutor(max_workers=self.jobs) as executor: + all_futures = [] + for test in self.tests: + future = executor.submit(self._run_test, test) + all_futures.append(future) + + for future in concurrent.futures.as_completed(all_futures): + test_result = future.result() + self._log_result(test_result) + if (test_result.status not in [SelftestStatus.PASSED, + SelftestStatus.NO_RUN, + SelftestStatus.SKIPPED]): + ret = 1 return ret
Signature · 1 line
2.53.0.1118.gaef5881109-goog
PATCH v4 6/9 KVM: selftests: Add various print flags to KVM selftest runner
In reply to Vipin SharmaAdd various print flags to selectively print outputs on terminal based on test execution status (passed, failed, timed out, skipped, no run).
For each status provide further options (off, full, stderr, stdout, status) to choose verbosity of their prints. Make "full" the default choice.
Example: To print stderr for the failed tests and only status for the passed test:
python3 runner --test-dirs tests --print-failed stderr \ --print-passed status
Above command with disable print off skipped, timed out, and no run tests.
--- .../testing/selftests/kvm/runner/__main__.py | 45 +++++++++++++++++++ .../selftests/kvm/runner/test_runner.py | 19 ++++++-- 2 files changed, 60 insertions(+), 4 deletions(-)
tools/testing/selftests/kvm/runner/__main__.py +45 -0
@@ -9,6 +9,7 @@ import os import sys import datetime import pathlib +import textwrap from test_runner import TestRunner from selftest import SelftestStatus
@@ -60,6 +61,50 @@ def cli(): type=int, help="Maximum number of tests that can be run concurrently. (Default: 1)") + status_choices = ["off", "full", "stdout", "stderr", "status"] + status_help_text = textwrap.dedent('''\ + Control output of the {} test (default is full). + off : dont print anything. + full : print stdout, stderr, and status of the test. + stdout: print stdout and status of the test. + stderr: print stderr and status of the test. + status: only print the status of test execution and no other output.'''); + + parser.add_argument("--print-passed", + default="full", + const="full", + nargs='?', + choices=status_choices, + help = status_help_text.format("passed")) + + parser.add_argument("--print-failed", + default="full", + const="full", + nargs='?', + choices=status_choices, + help = status_help_text.format("failed")) + + parser.add_argument("--print-skipped", + default="full", + const="full", + nargs='?', + choices=status_choices, + help = status_help_text.format("skipped")) + + parser.add_argument("--print-timed-out", + default="full", + const="full", + nargs='?', + choices=status_choices, + help = status_help_text.format("timed-out")) + + parser.add_argument("--print-no-run", + default="full", + const="full", + nargs='?', + choices=status_choices, + help = status_help_text.format("no-run")) + return parser.parse_args()
tools/testing/selftests/kvm/runner/test_runner.py +15 -4
@@ -17,6 +17,13 @@ class TestRunner: self.tests = [] self.output_dir = args.output self.jobs = args.jobs + self.print_stds = { + SelftestStatus.PASSED: args.print_passed, + SelftestStatus.FAILED: args.print_failed, + SelftestStatus.SKIPPED: args.print_skipped, + SelftestStatus.TIMED_OUT: args.print_timed_out, + SelftestStatus.NO_RUN: args.print_no_run + } for testcase in testcases: self.tests.append(Selftest(testcase, args.path, args.timeout,
@@ -27,10 +34,14 @@ class TestRunner: return test def _log_result(self, test_result): - logger.info("*** stdout ***\n" + test_result.stdout) - logger.info("*** stderr ***\n" + test_result.stderr) - logger.log(test_result.status, - f"[{test_result.status.name}] {test_result.test_path}") + print_level = self.print_stds.get(test_result.status, "full") + + if (print_level == "full" or print_level == "stdout"): + logger.info("*** stdout ***\n" + test_result.stdout) + if (print_level == "full" or print_level == "stderr"): + logger.info("*** stderr ***\n" + test_result.stderr) + if (print_level != "off"): + logger.log(test_result.status, f"[{test_result.status.name}] {test_result.test_path}") def start(self): ret = 0
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Sean Christopherson
reviewerRe: [PATCH v4 6/9] KVM: selftests: Add various print flags to KVM selftest runner
tools/testing/selftests/kvm/runner/test_runner.py class TestRunner: · line 40
Quoted 12 lines · Vipin Sharma
tools/testing/selftests/kvm/runner/test_runner.py +4
-4@@ -27,10 +34,14 @@ class TestRunner: return test def _log_result(self, test_result): - logger.info("*** stdout ***\n" + test_result.stdout) - logger.info("*** stderr ***\n" + test_result.stderr) - logger.log(test_result.status, - f"[{test_result.status.name}] {test_result.test_path}") + print_level = self.print_stds.get(test_result.status, "full") + + if (print_level == "full" or print_level == "stdout"): + logger.info("*** stdout ***\n" + test_result.stdout)
IMO, when the print_level is exactly stdout or stderr, the runner shouldn't spit out the "*** std{out,err} ***" line, as it's pure noise. E.g.
print("\033[2K", end="\r", flush=True)
if (print_level == "full"):
logger.info("*** stdout ***\n" + test_result.stdout)
logger.info("*** stderr ***\n" + test_result.stderr)
elif (print_level == "stdout"):
logger.info(test_result.stdout)
elif (print_level == "stderr"):
logger.info(test_result.stderr)Quoted 10 lines
tools/testing/selftests/kvm/runner/test_runner.py +4
-0+ if (print_level == "full" or print_level == "stderr"): + logger.info("*** stderr ***\n" + test_result.stderr) + if (print_level != "off"): + logger.log(test_result.status, f"[{test_result.status.name}] {test_result.test_path}") def start(self): ret = 0Signature · 1 line
2.53.0.1118.gaef5881109-goog
Re: [PATCH v4 6/9] KVM: selftests: Add various print flags to KVM selftest runner
Quoted 17 lines · Sean Christopherson
tools/testing/selftests/kvm/runner/test_runner.py class TestRunner: · line 40
Quoted 12 lines · Vipin Sharma
tools/testing/selftests/kvm/runner/test_runner.py +4
-4@@ -27,10 +34,14 @@ class TestRunner: return test def _log_result(self, test_result): - logger.info("*** stdout ***\n" + test_result.stdout) - logger.info("*** stderr ***\n" + test_result.stderr) - logger.log(test_result.status, - f"[{test_result.status.name}] {test_result.test_path}") + print_level = self.print_stds.get(test_result.status, "full") + + if (print_level == "full" or print_level == "stdout"): + logger.info("*** stdout ***\n" + test_result.stdout)IMO, when the
print_levelis exactly stdout or stderr, the runner shouldn't spit out the "*** std{out,err} ***" line, as it's pure noise. E.g.
Quoted 9 lines
print("\033[2K", end="\r", flush=True)
if (print_level == "full"):
logger.info("*** stdout ***\n" + test_result.stdout)
logger.info("*** stderr ***\n" + test_result.stderr)
elif (print_level == "stdout"):
logger.info(test_result.stdout)
elif (print_level == "stderr"):
logger.info(test_result.stderr)I agree.
PATCH v4 7/9 KVM: selftests: Print sticky KVM selftests runner status at bottom
In reply to Vipin SharmaPrint current state of the KVM selftest runner during its execution. Show it as the bottom most line, make it sticky and colored. Provide the following information:
- Total number of tests selected for run.
- How many have executed.
- Total for each end state.
Example:
Total: 3/3 Passed: 1 Failed: 1 Skipped: 0 Timed Out: 0 No Run: 1
--- .../selftests/kvm/runner/test_runner.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/testing/selftests/kvm/runner/test_runner.py +21 -0
@@ -15,6 +15,7 @@ logger = logging.getLogger("runner") class TestRunner: def __init__(self, testcases, args): self.tests = [] + self.status = {x: 0 for x in SelftestStatus} self.output_dir = args.output self.jobs = args.jobs self.print_stds = {
@@ -33,9 +34,19 @@ class TestRunner: test.run() return test + def _sticky_update(self): + print(f"\r\033[1mTotal: {self.tests_ran}/{len(self.tests)}" \ + f"\033[32;1m Passed: {self.status[SelftestStatus.PASSED]}" \ + f"\033[31;1m Failed: {self.status[SelftestStatus.FAILED]}" \ + f"\033[33;1m Skipped: {self.status[SelftestStatus.SKIPPED]}"\ + f"\033[91;1m Timed Out: {self.status[SelftestStatus.TIMED_OUT]}"\ + f"\033[34;1m No Run: {self.status[SelftestStatus.NO_RUN]}\033[0m", + end="\r", flush=True) + def _log_result(self, test_result): print_level = self.print_stds.get(test_result.status, "full") + print("\033[2K", end="\r", flush=True) if (print_level == "full" or print_level == "stdout"): logger.info("*** stdout ***\n" + test_result.stdout) if (print_level == "full" or print_level == "stderr"):
@@ -43,8 +54,16 @@ class TestRunner: if (print_level != "off"): logger.log(test_result.status, f"[{test_result.status.name}] {test_result.test_path}") + self.status[test_result.status] += 1 + # Sticky bottom line + self._sticky_update() + def start(self): ret = 0 + self.tests_ran = 0 + + # Show initial progress + self._sticky_update() with concurrent.futures.ProcessPoolExecutor(max_workers=self.jobs) as executor: all_futures = []
@@ -54,9 +73,11 @@ class TestRunner: for future in concurrent.futures.as_completed(all_futures): test_result = future.result() + self.tests_ran += 1 self._log_result(test_result) if (test_result.status not in [SelftestStatus.PASSED, SelftestStatus.NO_RUN, SelftestStatus.SKIPPED]): ret = 1 + print("\n") return ret
Signature · 1 line
2.53.0.1118.gaef5881109-goog
PATCH v4 8/9 KVM: selftests: Add rule to generate default tests for KVM selftests runner
In reply to Vipin SharmaAdd 'tests_install' rule in the Makefile.kvm to auto generate default testcases for KVM selftests runner. Preserve the hierarchy of test executables for autogenerated files. Remove these testcases on invocation of 'make clean'.
Autogeneration of default test files allows runner to execute default testcases easily. These default testcases don't need to be checked in as they are just executing the test without any command line options.
--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile.kvm | 26 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/.gitignore +1 -0
@@ -7,6 +7,7 @@ !*.S !*.sh !*.test +default.test !.gitignore !config !settings
tools/testing/selftests/kvm/Makefile.kvm +25 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only include ../../../build/Build.include -all: +all: tests_install LIBKVM += lib/assert.c LIBKVM += lib/elf.c
@@ -330,11 +330,15 @@ $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o $(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(ARCH)/%.o: $(ARCH)/%.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ +# Default testcases for KVM selftests runner will be generated in this directory. +DEFAULT_TESTCASES = testcases_default_gen + EXTRA_CLEAN += $(GEN_HDRS) \ $(LIBKVM_OBJS) \ $(SPLIT_TEST_GEN_OBJ) \ $(TEST_DEP_FILES) \ $(TEST_GEN_OBJ) \ + $(OUTPUT)/$(DEFAULT_TESTCASES) \ cscope.* $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS)
@@ -363,3 +367,23 @@ cscope: find . -name '*.c' \ -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files cscope -b + +# Generate runner testcases in DEFAULT_TESTCASES directory. +# $(OUTPUT) is either CWD or specified in the make command. +tests_install: list_progs = $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS)) +tests_install: + $(foreach tc, $(TEST_PROGS), \ + $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(patsubst %.sh,%,$(tc)))) + $(foreach tc, $(TEST_PROGS), \ + $(shell echo $(tc) > $(patsubst %.sh,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) + + $(foreach tc, $(list_progs), \ + $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(tc))) + $(foreach tc, $(list_progs), \ + $(shell echo $(tc) > $(patsubst %,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) + + @if [ ! -d $(OUTPUT)/runner ]; then \ + cp -r $(selfdir)/kvm/runner $(OUTPUT); \ + fi + + @:
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Sean Christopherson
reviewerRe: [PATCH v4 8/9] KVM: selftests: Add rule to generate default tests for KVM selftests runner
Quoted 41 lines · Vipin Sharma
Add '
tests_install' rule in the Makefile.kvm to auto generate default testcases for KVM selftests runner. Preserve the hierarchy of test executables for autogenerated files. Remove these testcases on invocation of 'make clean'.Autogeneration of default test files allows runner to execute default testcases easily. These default testcases don't need to be checked in as they are just executing the test without any command line options.
Signed-off-by Vipin Sharma <[email protected]>--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile.kvm | 26 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)tools/testing/selftests/kvm/.gitignore +1
-0@@ -7,6 +7,7 @@ !*.S !*.sh !*.test +default.test !.gitignore !config !settingstools/testing/selftests/kvm/Makefile.kvm +1
-1@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only include ../../../build/Build.include -all: +all: tests_install LIBKVM += lib/assert.c LIBKVM += lib/elf.c
tools/testing/selftests/kvm/Makefile.kvm $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o · line 334
Quoted 5 lines
tools/testing/selftests/kvm/Makefile.kvm +2
-0@@ -330,11 +330,15 @@ $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o $(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(ARCH)/%.o: $(ARCH)/%.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ +# Default testcases for KVM selftests runner will be generated in this directory. +DEFAULT_TESTCASES = testcases_default_gen
That's a cumbersome name. It was also written by Yoda :-) How about default_testcases?
Quoted 11 lines
tools/testing/selftests/kvm/Makefile.kvm +2
-0+ EXTRA_CLEAN += $(GEN_HDRS) \ $(LIBKVM_OBJS) \ $(SPLIT_TEST_GEN_OBJ) \ $(TEST_DEP_FILES) \ $(TEST_GEN_OBJ) \ + $(OUTPUT)/$(DEFAULT_TESTCASES) \ cscope.* $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS)
tools/testing/selftests/kvm/Makefile.kvm cscope: · line 374
Quoted 8 lines
tools/testing/selftests/kvm/Makefile.kvm +5
-0@@ -363,3 +367,23 @@ cscope: find . -name '*.c' \ -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files cscope -b + +# Generate runner testcases in DEFAULT_TESTCASES directory. +# $(OUTPUT) is either CWD or specified in the make command. +tests_install: list_progs = $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS)) +tests_install:
This is very much *not* an install. In fact, install is broken, because the runner isn't added to TEST_FILES.
Another issue with install is that it flattens the directory structures, i.e. drops the $ARCH/ subdirectories. That causes issues for the default.test testcases due to them using partially qualified paths.
And coming back to this with fresh eyes, I don't love generating the testcases for the "normal" build. It necessitates adding default.test to .gitignore, effectively requires copying the runner to the output directory, and is pure noise for folks that don't want to utilize the runner.
Rather than generate testcases for the default build, what if we make this 100% opt-in, and take a hard dependency on install? That should obviate the need for ignoring default.test, because if someone is silly enough to install testcases in the source tree, they get to deal with the noise.
And we can commit to having the default testcases provide completely unqualified paths, so that the Just Work with the flattened output. If someone wants to run with an unflattened tree, then we should update the runner itself to handle multiple paths, a la the actual PATH variable.
The other nice thing is that we can make the runner opt-in, without requiring the user to run multiple make commands, by chaining testcases => install => all. If we try to generate testcases as an optional step to the normal build, then we'll end up being able to run install without having generated the testcases, which is "fine", but probably not what we want for people that are trying to use the runner.
The obvious downside is that it requires doing an install to get the default testcases, but IMO that's an acceptable tradeoff.
tools/testing/selftests/kvm/Makefile.kvm cscope: · line 385
Quoted 11 lines
tools/testing/selftests/kvm/Makefile.kvm +11
-0+ $(foreach tc, $(TEST_PROGS), \ + $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(patsubst %.sh,%,$(tc)))) + $(foreach tc, $(TEST_PROGS), \ + $(shell echo $(tc) > $(patsubst %.sh,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) + + $(foreach tc, $(list_progs), \ + $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(tc))) + $(foreach tc, $(list_progs), \ + $(shell echo $(tc) > $(patsubst %,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) + + @if [ ! -d $(OUTPUT)/runner ]; then \
This is very wrong, as this will fail to pick up any changes made to the runner.
All in all, this as fixup?
tools/testing/selftests/kvm/.gitignore +0 -1
@@ -8,7 +8,6 @@ !*.S !*.sh !*.test -default.test !.gitignore !config !settings
tools/testing/selftests/kvm/Makefile.kvm +11 -18
@@ -1,8 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only include ../../../build/Build.include -all: tests_install - LIBKVM += lib/assert.c LIBKVM += lib/elf.c LIBKVM += lib/guest_modes.c
@@ -347,15 +345,13 @@ $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o $(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(ARCH)/%.o: $(ARCH)/%.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ -# Default testcases for KVM selftests runner will be generated in this directory. -DEFAULT_TESTCASES = testcases_default_gen +TEST_FILES := $(selfdir)/kvm/runner EXTRA_CLEAN += $(GEN_HDRS) \ $(LIBKVM_OBJS) \ $(SPLIT_TEST_GEN_OBJ) \ $(TEST_DEP_FILES) \ $(TEST_GEN_OBJ) \ - $(OUTPUT)/$(DEFAULT_TESTCASES) \ cscope.* $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS)
@@ -386,21 +382,18 @@ cscope: cscope -b # Generate runner testcases in DEFAULT_TESTCASES directory. -# $(OUTPUT) is either CWD or specified in the make command. -tests_install: list_progs = $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS)) -tests_install: - $(foreach tc, $(TEST_PROGS), \ - $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(patsubst %.sh,%,$(tc)))) - $(foreach tc, $(TEST_PROGS), \ - $(shell echo $(tc) > $(patsubst %.sh,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) +DEFAULT_TESTCASES = default_testcases + +testcases: list_progs = $(notdir $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS))) +testcases: install + $(foreach tc, $(notdir $(TEST_PROGS)), \ + $(shell mkdir -p $(INSTALL_PATH)/$(DEFAULT_TESTCASES)/$(notdir $(patsubst %.sh,%,$(tc))))) + $(foreach tc, $(notdir $(TEST_PROGS)), \ + $(shell echo $(tc) > $(patsubst %.sh,$(INSTALL_PATH)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) $(foreach tc, $(list_progs), \ - $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(tc))) + $(shell mkdir -p $(INSTALL_PATH)/$(DEFAULT_TESTCASES)/$(tc))) $(foreach tc, $(list_progs), \ - $(shell echo $(tc) > $(patsubst %,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) - - @if [ ! -d $(OUTPUT)/runner ]; then \ - cp -r $(selfdir)/kvm/runner $(OUTPUT); \ - fi + $(shell echo $(tc) > $(patsubst %,$(INSTALL_PATH)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) @:
Quoted 7 lines
tools/testing/selftests/kvm/Makefile.kvm +4
-0+ cp -r $(selfdir)/kvm/runner $(OUTPUT); \ + fi + + @:Signature · 1 line
2.53.0.1118.gaef5881109-goog
Re: [PATCH v4 8/9] KVM: selftests: Add rule to generate default tests for KVM selftests runner
Quoted 6 lines · Sean Christopherson
Review
Quoted 2 lines · Vipin Sharma
(quoted diff) +2
-0+# Default testcases for KVM selftests runner will be generated in this directory. +DEFAULT_TESTCASES = testcases_default_genThat's a cumbersome name. It was also written by Yoda :-) How about
default_testcases?
No fun, you are!
Quoted 9 lines
Quoted 9 lines
tools/testing/selftests/kvm/Makefile.kvm +2
-0+ EXTRA_CLEAN += $(GEN_HDRS) \ $(LIBKVM_OBJS) \ $(SPLIT_TEST_GEN_OBJ) \ $(TEST_DEP_FILES) \ $(TEST_GEN_OBJ) \ + $(OUTPUT)/$(DEFAULT_TESTCASES) \ cscope.*
Quoted 13 lines
Review cscope: · line 374
Quoted 10 lines
$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS)
(quoted diff) +5
-0@@ -363,3 +367,23 @@ cscope: find . -name '*.c' \ -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files cscope -b + +# Generate runner testcases in DEFAULT_TESTCASES directory. +# $(OUTPUT) is either CWD or specified in the make command. +tests_install: list_progs = $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS)) +tests_install:This is very much *not* an install. In fact, install is broken, because the runner isn't added to
TEST_FILES.
I think this will also be not a good approach if we are moving towards opt-in. I added another option in your FIXUP below.
Quoted 9 lines
Another issue with install is that it flattens the directory structures, i.e. drops the $ARCH/ subdirectories. That causes issues for the default.test testcases due to them using partially qualified paths.
And coming back to this with fresh eyes, I don't love generating the testcases for the "normal" build. It necessitates adding default.test to .gitignore, effectively requires copying the runner to the output directory, and is pure noise for folks that don't want to utilize the runner.
Yes, this is true.
Quoted 18 lines
Rather than generate testcases for the default build, what if we make this 100% opt-in, and take a hard dependency on install? That should obviate the need for ignoring default.test, because if someone is silly enough to install testcases in the source tree, they get to deal with the noise.
And we can commit to having the default testcases provide completely unqualified paths, so that the Just Work with the flattened output. If someone wants to run with an unflattened tree, then we should update the runner itself to handle multiple paths, a la the actual PATH variable.
The other nice thing is that we can make the runner opt-in, without requiring the user to run multiple make commands, by chaining testcases => install => all. If we try to generate testcases as an optional step to the normal build, then we'll end up being able to run install without having generated the testcases, which is "fine", but probably not what we want for people that are trying to use the runner.
Quoted 3 lines
The obvious downside is that it requires doing an install to get the default testcases, but IMO that's an acceptable tradeoff.
I like the opt-in approach. However, there is a subtle difference when using 'testcases: install' vs 'all: tests_install'
Test cases can only be generated with
make -C tools/testing/selftests/kvm testcases
We will not be able to generate test cases from the selftest directory or the source root.
New command will be:
make -C tools/testing/selftests/kvm testscases INSTALL_PATH=<path>
I think this is fine, considering it is opt-in and user has to know how to run it. One advantage is that currently when a user runs:
make -C tools/testing/selftests/kvm install INSTALL_PATH=<path>
They don't get run_kselftest.sh to run those tests. With the new rule, they will have a runner to work with.
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+ $(foreach tc, $(TEST_PROGS), \ + $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(patsubst %.sh,%,$(tc)))) + $(foreach tc, $(TEST_PROGS), \ + $(shell echo $(tc) > $(patsubst %.sh,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) +
Quoted 8 lines
Review cscope: · line 385
Quoted 6 lines
(quoted diff) +6
-0+ $(foreach tc, $(list_progs), \ + $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(tc))) + $(foreach tc, $(list_progs), \ + $(shell echo $(tc) > $(patsubst %,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) + + @if [ ! -d $(OUTPUT)/runner ]; then \This is very wrong, as this will fail to pick up any changes made to the runner.
yeah, I think rsync would have been better.
Quoted 29 lines
All in all, this as fixup?
tools/testing/selftests/kvm/.gitignore +0
-1@@ -8,7 +8,6 @@ !*.S !*.sh !*.test -default.test !.gitignore !config !settingstools/testing/selftests/kvm/Makefile.kvm +0
-2@@ -1,8 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only include ../../../build/Build.include -all: tests_install - LIBKVM += lib/assert.c LIBKVM += lib/elf.c LIBKVM += lib/guest_modes.c
tools/testing/selftests/kvm/Makefile.kvm $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o · line 348
Quoted 6 lines
tools/testing/selftests/kvm/Makefile.kvm +1
-2@@ -347,15 +345,13 @@ $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o $(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(ARCH)/%.o: $(ARCH)/%.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ -# Default testcases for KVM selftests runner will be generated in this directory. -DEFAULT_TESTCASES = testcases_default_gen +TEST_FILES := $(selfdir)/kvm/runner
Downside of this one is that if someone is not planning to use runner they will still get this directory copied.
Should we instead add 'rsync -u' in 'testcases' rule below which can copy runner only when it is updated or not present? This would be similar to original patch but instead of 'cp' it will be 'rsync' command. This will also copy runner when someone is explicitly using it.
I think we should also include 'tests' directory which we are using for custom testcases and they also .
Quoted 30 lines
tools/testing/selftests/kvm/Makefile.kvm +8
-8EXTRA_CLEAN += $(GEN_HDRS) \ $(LIBKVM_OBJS) \ $(SPLIT_TEST_GEN_OBJ) \ $(TEST_DEP_FILES) \ $(TEST_GEN_OBJ) \ - $(OUTPUT)/$(DEFAULT_TESTCASES) \ cscope.* $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS)@@ -386,21 +382,18 @@ cscope: cscope -b # Generate runner testcases in DEFAULT_TESTCASES directory. -# $(OUTPUT) is either CWD or specified in the make command. -tests_install: list_progs = $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS)) -tests_install: - $(foreach tc, $(TEST_PROGS), \ - $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(patsubst %.sh,%,$(tc)))) - $(foreach tc, $(TEST_PROGS), \ - $(shell echo $(tc) > $(patsubst %.sh,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) +DEFAULT_TESTCASES = default_testcases + +testcases: list_progs = $(notdir $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS))) +testcases: install + $(foreach tc, $(notdir $(TEST_PROGS)), \ + $(shell mkdir -p $(INSTALL_PATH)/$(DEFAULT_TESTCASES)/$(notdir $(patsubst %.sh,%,$(tc))))) + $(foreach tc, $(notdir $(TEST_PROGS)), \ + $(shell echo $(tc) > $(patsubst %.sh,$(INSTALL_PATH)/$(DEFAULT_TESTCASES)/%/default.test,$(tc))))
tools/testing/selftests/kvm/Makefile.kvm cscope: · line 397
Quoted 10 lines
tools/testing/selftests/kvm/Makefile.kvm +2
-6$(foreach tc, $(list_progs), \ - $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(tc))) + $(shell mkdir -p $(INSTALL_PATH)/$(DEFAULT_TESTCASES)/$(tc))) $(foreach tc, $(list_progs), \ - $(shell echo $(tc) > $(patsubst %,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) - - @if [ ! -d $(OUTPUT)/runner ]; then \ - cp -r $(selfdir)/kvm/runner $(OUTPUT); \ - fi + $(shell echo $(tc) > $(patsubst %,$(INSTALL_PATH)/$(DEFAULT_TESTCASES)/%/default.test,$(tc))))
All looks good here.
Should I send a next version of this series with the changes you have suggested or you wanna take the diff you created and apply before merge?
Sean Christopherson
reviewerRe: [PATCH v4 8/9] KVM: selftests: Add rule to generate default tests for KVM selftests runner
Quoted 12 lines · Vipin Sharma
tools/testing/selftests/kvm/Makefile.kvm $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o · line 348
Quoted 7 lines · Sean Christopherson
tools/testing/selftests/kvm/Makefile.kvm +1
-2@@ -347,15 +345,13 @@ $(SPLIT_TEST_GEN_PROGS): $(OUTPUT)/%: $(OUTPUT)/%.o $(OUTPUT)/$(ARCH)/%.o $(SPLIT_TEST_GEN_OBJ): $(OUTPUT)/$(ARCH)/%.o: $(ARCH)/%.c $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ -# Default testcases for KVM selftests runner will be generated in this directory. -DEFAULT_TESTCASES = testcases_default_gen +TEST_FILES := $(selfdir)/kvm/runnerDownside of this one is that if someone is not planning to use runner they will still get this directory copied.
Quoted 4 lines
Should we instead add 'rsync -u' in 'testcases' rule below which can copy runner only when it is updated or not present? This would be similar to original patch but instead of 'cp' it will be 'rsync' command. This will also copy runner when someone is explicitly using it.
Hmm, but someone could be using the runner without (re)generating the default testcases. We could add a "runner" target, but that seems like overkill.
I'm good with either option, but I think my vote would be have the runner get copied on install, i.e. just do the "TEST_FILES := $(selfdir)/kvm/runner" above. But again, either way works for me.
Quoted 2 lines
I think we should also include 'tests' directory which we are using for custom testcases and they also .
Heh, they also what?
Quoted 42 lines
Quoted 29 lines
tools/testing/selftests/kvm/Makefile.kvm +8
-8EXTRA_CLEAN += $(GEN_HDRS) \ $(LIBKVM_OBJS) \ $(SPLIT_TEST_GEN_OBJ) \ $(TEST_DEP_FILES) \ $(TEST_GEN_OBJ) \ - $(OUTPUT)/$(DEFAULT_TESTCASES) \ cscope.* $(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c $(GEN_HDRS)@@ -386,21 +382,18 @@ cscope: cscope -b # Generate runner testcases in DEFAULT_TESTCASES directory. -# $(OUTPUT) is either CWD or specified in the make command. -tests_install: list_progs = $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS)) -tests_install: - $(foreach tc, $(TEST_PROGS), \ - $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(patsubst %.sh,%,$(tc)))) - $(foreach tc, $(TEST_PROGS), \ - $(shell echo $(tc) > $(patsubst %.sh,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) +DEFAULT_TESTCASES = default_testcases + +testcases: list_progs = $(notdir $(patsubst $(OUTPUT)/%,%,$(TEST_GEN_PROGS))) +testcases: install + $(foreach tc, $(notdir $(TEST_PROGS)), \ + $(shell mkdir -p $(INSTALL_PATH)/$(DEFAULT_TESTCASES)/$(notdir $(patsubst %.sh,%,$(tc))))) + $(foreach tc, $(notdir $(TEST_PROGS)), \ + $(shell echo $(tc) > $(patsubst %.sh,$(INSTALL_PATH)/$(DEFAULT_TESTCASES)/%/default.test,$(tc))))tools/testing/selftests/kvm/Makefile.kvm cscope: · line 397
Quoted 10 lines
tools/testing/selftests/kvm/Makefile.kvm +2
-6$(foreach tc, $(list_progs), \ - $(shell mkdir -p $(OUTPUT)/$(DEFAULT_TESTCASES)/$(tc))) + $(shell mkdir -p $(INSTALL_PATH)/$(DEFAULT_TESTCASES)/$(tc))) $(foreach tc, $(list_progs), \ - $(shell echo $(tc) > $(patsubst %,$(OUTPUT)/$(DEFAULT_TESTCASES)/%/default.test,$(tc)))) - - @if [ ! -d $(OUTPUT)/runner ]; then \ - cp -r $(selfdir)/kvm/runner $(OUTPUT); \ - fi + $(shell echo $(tc) > $(patsubst %,$(INSTALL_PATH)/$(DEFAULT_TESTCASES)/%/default.test,$(tc))))All looks good here.
Quoted 2 lines
Should I send a next version of this series with the changes you have suggested or you wanna take the diff you created and apply before merge?
Go ahead and send the next version. Given the number of tweaks, it'd be helpful to be closer to WYSIWYG. My changes are at:
https://github.com/sean-jc/linux slf/runner
if you want to use that as a reference and/or grab changes directly.
PATCH v4 9/9 KVM: selftests: Provide README.rst for KVM selftests runner
In reply to Vipin SharmaAdd README.rst for KVM selftest runner and explain how to use the runner.
--- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/runner/README.rst | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tools/testing/selftests/kvm/runner/README.rst
tools/testing/selftests/kvm/.gitignore +1 -0
@@ -4,6 +4,7 @@ !*.c !*.h !*.py +!*.rst !*.S !*.sh !*.test
tools/testing/selftests/kvm/runner/README.rst new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.53.0.1118.gaef5881109-goog
Sean Christopherson
reviewerRe: [PATCH v4 9/9] KVM: selftests: Provide README.rst for KVM selftests runner
Quoted 11 lines · Vipin Sharma
tools/testing/selftests/kvm/runner/README.rst new file +11
-0+Generate Default Tests +====================== + +Generate the default test case files using the provided make target:: + + # make tests_install + +This creates the ``testcases_default_gen`` directory containing ``default.test`` +files. Each KVM selftest has a directory with a ``default.test`` file. This file +contains the executable path relative to the KVM selftest root directory +(``/tools/testing/selftests/kvm``). For example, the ``dirty_log_perf_test``
tools/testing/selftests/kvm/runner/README.rst line 60
Quoted 10 lines
tools/testing/selftests/kvm/runner/README.rst new file +10
-0+entry looks like:: + + # cat testcases_default_gen/dirty_log_perf_test/default.test + dirty_log_perf_test + +In above testcase, the runner executes ``dirty_log_perf_test``. Testcase files +can provide extra arguments to the test:: + + # cat tests/dirty_log_perf_test/2slot_5vcpu_10iter.test + dirty_log_perf_test -x 2 -v 5 -i 10
This is obviously not about the default tests.
Quoted 4 lines
tools/testing/selftests/kvm/runner/README.rst new file +4
-0+ +In this case, the runner executes ``dirty_log_perf_test`` with the specified +options. +
tools/testing/selftests/kvm/runner/README.rst line 74
Quoted 10 lines
tools/testing/selftests/kvm/runner/README.rst new file +10
-0+Examples +======== + +Display all options:: + + # python3 runner -h + +Run all default tests:: + + # python3 runner -d testcases_default_gen
s/testcases_default_gen/$(DEFAULT_TESTCASES), because the user (like me) might change it.
Something like this, if we go testcases => install route?
Generate Default Tests
======================
Generate the default test case files using the provided make target::
# make testcases
Create a ``$(INSTALL_PATH)/$(DEFAULT_TESTCASES)`` directory and a sub-directory for each KVM selftest, and populate each selftest sub-directory with a ``default.test`` file, where ``default.test`` contains the unqualified executable path.
For example, the ``dirty_log_perf_test`` entry looks like::
# cat $(DEFAULT_TESTCASES)/dirty_log_perf_test/default.test dirty_log_perf_test
Note, the ``testcases`` target is dependent on the ``install`` target, i.e. installing testcases will also run ``install``.
Testcase Syntax
===============
Testcase files can provide extra arguments to the test::
# cat tests/dirty_log_perf_test/2slot_5vcpu_10iter.test dirty_log_perf_test -x 2 -v 5 -i 10
In this case, the runner executes ``dirty_log_perf_test`` with the specified options.
Examples
========
Display all options::
# python3 runner -h
Run all default tests::
# python3 runner -d $(DEFAULT_TESTCASES)
Run tests in parallel::
# python3 runner -d $(DEFAULT_TESTCASES) -j 40
Print only passed test status and failed test stderr::
# python3 runner -d $(DEFAULT_TESTCASES) --print-passed status \ --print-failed stderr
Run test binaries from a different directory (e.g., out-of-tree builds)::
# python3 runner -d $(DEFAULT_TESTCASES) -p /path/to/binaries
Save all test outputs (stdout, stderr, status) to a directory::
# python3 runner -d $(DEFAULT_TESTCASES) -o test_outputs
Run specific testcase files::
# python3 runner -t tests/dirty_log_perf_test/2slot_5vcpu_10iter.test
Quoted 24 lines
tools/testing/selftests/kvm/runner/README.rst new file +21
-0+ +Run tests in parallel:: + + # python3 runner -d testcases_default_gen -j 40 + +Print only passed test status and failed test stderr:: + + # python3 runner -d testcases_default_gen --print-passed status \ + --print-failed stderr + +Run test binaries from a different directory (e.g., out-of-tree builds):: + + # python3 runner -d testcases_default_gen -p /path/to/binaries + +Save all test outputs (stdout, stderr, status) to a directory:: + + # python3 runner -d testcases_default_gen -o test_outputs + +Run specific testcase files:: + + # python3 runner -t tests/dirty_log_perf_test/2slot_5vcpu_10iter.testSignature · 1 line
2.53.0.1118.gaef5881109-goog