diff mbox series

[kms-tests] kmstest: Print summary after running tests

Message ID 20231114210719.32739-1-laurent.pinchart@ideasonboard.com (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series [kms-tests] kmstest: Print summary after running tests | expand

Commit Message

Laurent Pinchart Nov. 14, 2023, 9:07 p.m. UTC
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

When running multiple tests, a summary helps getting a quick overview of
the results. Accumulate the number of success, skip and fail, and print
them at the end:

	28 tests: 24 SUCCESS, 4 SKIP, 0 FAIL

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 tests/kmstest.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)


base-commit: 2264236eefd15450320c0cdb34fa07ac0881f713
prerequisite-patch-id: d24ee333fe0548c916988bc5c1d9fb2c80d9f149
diff mbox series

Patch

diff --git a/tests/kmstest.py b/tests/kmstest.py
index a86d689347d9..3cc8f1a3e306 100755
--- a/tests/kmstest.py
+++ b/tests/kmstest.py
@@ -3,6 +3,7 @@ 
 # SPDX-FileCopyrightText: 2017-2019 Renesas Electronics Corporation
 
 import collections.abc
+from dataclasses import dataclass
 import errno
 import fcntl
 import os
@@ -329,6 +330,22 @@  class AtomicRequest(pykms.AtomicReq):
 
 
 class KMSTest(object):
+
+    @dataclass
+    class Stats:
+        success: int = 0
+        skip: int = 0
+        fail: int = 0
+
+        def __add__(self, other):
+            return KMSTest.Stats(success=self.success + other.success,
+                                 skip=self.skip + other.skip,
+                                 fail=self.fail + other.fail)
+
+        @property
+        def total(self):
+            return self.success + self.skip + self.fail
+
     def __init__(self, use_default_key_handler=False):
         if not getattr(self, 'main', None):
             raise RuntimeError('Test class must implement main method')
@@ -348,6 +365,8 @@  class KMSTest(object):
         if use_default_key_handler:
             self.loop.register(sys.stdin, selectors.EVENT_READ, self.__read_key)
 
+        self.__stats = KMSTest.Stats()
+
     def __enter__(self):
         return self
 
@@ -533,6 +552,8 @@  class KMSTest(object):
         sys.stdout.write(f'\rTesting {self.test_name}: FAIL\n')
         sys.stdout.flush()
 
+        self.__stats.fail += 1
+
     def skip(self, reason):
         """Complete a test with skip."""
         self.logger.log(f'Test skipped. Reason: {reason}')
@@ -540,6 +561,8 @@  class KMSTest(object):
         sys.stdout.write('SKIP\n')
         sys.stdout.flush()
 
+        self.__stats.skip += 1
+
     def success(self):
         """Complete a test with success."""
         self.logger.log('Test completed successfully')
@@ -547,6 +570,12 @@  class KMSTest(object):
         sys.stdout.write(f'\rTesting {self.test_name}: SUCCESS\n')
         sys.stdout.flush()
 
+        self.__stats.success += 1
+
+    @property
+    def stats(self):
+        return self.__stats
+
 
 if __name__ == '__main__':
     import argparse
@@ -567,6 +596,8 @@  if __name__ == '__main__':
             if path.is_file() and path.name.startswith('kms-test-') and path.name.endswith('.py'):
                 files.append(path.name)
 
+    stats = KMSTest.Stats()
+
     files.sort()
     for file in files:
         print(f'- {file}')
@@ -586,3 +617,6 @@  if __name__ == '__main__':
             # objects end up being deleted.
             with test() as test:
                 test.execute()
+                stats = stats + test.stats
+
+    print(f'{stats.total} tests: {stats.success} SUCCESS, {stats.skip} SKIP, {stats.fail} FAIL')