[PATCH v3 6/9] KVM: selftests: Add various print flags to KVM selftest runner
Vipin Sharma
vipinsh at google.com
Tue Sep 30 09:36:32 PDT 2025
Add 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.
Signed-off-by: Vipin Sharma <vipinsh at google.com>
---
.../testing/selftests/kvm/runner/__main__.py | 45 +++++++++++++++++++
.../selftests/kvm/runner/test_runner.py | 19 ++++++--
2 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/kvm/runner/__main__.py b/tools/testing/selftests/kvm/runner/__main__.py
index b98f72c9f7ee..4867e89c30f2 100644
--- a/tools/testing/selftests/kvm/runner/__main__.py
+++ b/tools/testing/selftests/kvm/runner/__main__.py
@@ -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.
+ 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()
diff --git a/tools/testing/selftests/kvm/runner/test_runner.py b/tools/testing/selftests/kvm/runner/test_runner.py
index 92eec18fe5c6..e8e8fd91c1ad 100644
--- a/tools/testing/selftests/kvm/runner/test_runner.py
+++ b/tools/testing/selftests/kvm/runner/test_runner.py
@@ -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
--
2.51.0.618.g983fd99d29-goog
More information about the kvm-riscv
mailing list