]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
unittests: add a runner to execute all unittests
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 17 Mar 2026 18:09:29 +0000 (19:09 +0100)
committerJonathan Corbet <corbet@lwn.net>
Sun, 22 Mar 2026 21:02:29 +0000 (15:02 -0600)
We'll soon have multiple unit tests, add a runner that will
discover all of them and execute all tests.

It was opted to discover only files that starts with "test",
as this way unittest discover won't try adding libraries or
other stuff that might not contain unittest classes.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <2d9dd14f03d3d6394346fdaceeb3167d54d1dd0c.1773770483.git.mchehab+huawei@kernel.org>

tools/unittests/run.py [new file with mode: 0755]

diff --git a/tools/unittests/run.py b/tools/unittests/run.py
new file mode 100755 (executable)
index 0000000..8c19036
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/env python3
+import os
+import unittest
+import sys
+
+TOOLS_DIR=os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
+sys.path.insert(0, TOOLS_DIR)
+
+from lib.python.unittest_helper import TestUnits
+
+if __name__ == "__main__":
+    loader = unittest.TestLoader()
+
+    suite = loader.discover(start_dir=os.path.join(TOOLS_DIR, "unittests"),
+                            pattern="test*.py")
+
+    TestUnits().run("", suite=suite)