summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-07-31 18:08:44 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-07-31 18:15:43 +0300
commit385b653e229ce1c7f1115005d4cb30edbcb884a0 (patch)
treeba1400cfbb8819d4975dfc9ed10ee2674a30b9d0
parent2ce4e51cfc5be4b4aeeae331f9accffad46e6e1b (diff)
kmstest: Implement test runner when executed directly
Run all tests from the current directory when the kmstest.py script it executed directly, as opposed to being imported by individual tests. This simplifies running all tests. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rwxr-xr-xtests/kmstest.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/kmstest.py b/tests/kmstest.py
index 960c27f..e84d8fe 100755
--- a/tests/kmstest.py
+++ b/tests/kmstest.py
@@ -334,7 +334,17 @@ class KMSTest(object):
if use_default_key_handler:
self.loop.register(sys.stdin, selectors.EVENT_READ, self.__read_key)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *err):
+ self.card = None
+ self.loop.close()
+ self.logger.close()
+
def __del__(self):
+ self.card = None
+ self.loop.close()
self.logger.close()
def atomic_crtc_disable(self, crtc, sync=True):
@@ -520,3 +530,33 @@ class KMSTest(object):
sys.stdout.write(f'\rTesting {self.test_name}: SUCCESS\n')
sys.stdout.flush()
+
+if __name__ == '__main__':
+ import importlib
+ import inspect
+ import os
+
+ files = []
+ for path in os.scandir():
+ if path.is_file() and path.name.startswith('kms-test-') and path.name.endswith('.py'):
+ files.append(path.name)
+
+ files.sort()
+ for file in files:
+ print(f'- {file}')
+ module = importlib.import_module(file[:-3])
+ tests = []
+ for name in dir(module):
+ obj = getattr(module, name)
+ if not isinstance(obj, type):
+ continue
+
+ if 'KMSTest' in [cls.__name__ for cls in inspect.getmro(obj)]:
+ tests.append(obj)
+
+ for test in tests:
+ # Use a context manager to ensure proper cleanup after each test,
+ # otherwise state from one test may leak to the other based on when
+ # objects end up being deleted.
+ with test() as test:
+ test.execute()