[PATCH v3 7/9] KVM: selftests: Print sticky KVM selftests runner status at bottom

Vipin Sharma
2025-09-30T16:37:01Z

Print 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

Signed-off-by: Vipin Sharma <vipinsh@google.com>
---
.../testing/selftests/kvm/runner/test_runner.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/tools/testing/selftests/kvm/runner/test_runner.py b/tools/testing/selftests/kvm/runner/test_runner.py
index e8e8fd91c1ad..42274e695b76 100644
--- a/tools/testing/selftests/kvm/runner/test_runner.py
+++ b/tools/testing/selftests/kvm/runner/test_runner.py
@@ -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,18 @@ 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")
+
def _log_result(self, test_result):
print_level = self.print_stds.get(test_result.status, "full")

+ print("\033[2K", end="\r")
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 +53,13 @@ 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

with concurrent.futures.ProcessPoolExecutor(max_workers=self.jobs) as executor:
all_futures = []
@@ -54,9 +69,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
--
2.51.0.618.g983fd99d29-goog