[PATCH v3 2/9] KVM: selftests: Provide executables path option to the KVM selftest runner

Vipin Sharma
2025-09-30T16:36:52Z

Add 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.

Signed-off-by: Vipin Sharma <vipinsh@google.com>
---
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(-)

diff --git a/tools/testing/selftests/kvm/runner/__main__.py b/tools/testing/selftests/kvm/runner/__main__.py
index 8d1a78450e41..943c3bfe2eb6 100644
--- a/tools/testing/selftests/kvm/runner/__main__.py
+++ b/tools/testing/selftests/kvm/runner/__main__.py
@@ -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__":
diff --git a/tools/testing/selftests/kvm/runner/selftest.py b/tools/testing/selftests/kvm/runner/selftest.py
index 34005f83f0c3..a94b6d4cda05 100644
--- a/tools/testing/selftests/kvm/runner/selftest.py
+++ b/tools/testing/selftests/kvm/runner/selftest.py
@@ -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
diff --git a/tools/testing/selftests/kvm/runner/test_runner.py b/tools/testing/selftests/kvm/runner/test_runner.py
index 4418777d75e3..acc9fb3dabde 100644
--- a/tools/testing/selftests/kvm/runner/test_runner.py
+++ b/tools/testing/selftests/kvm/runner/test_runner.py
@@ -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)
--
2.51.0.618.g983fd99d29-goog