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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Laurent Pinchart <laurent.pinchart+renesas@xxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxx>
---
 tests/kmstest.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

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')

base-commit: 2264236eefd15450320c0cdb34fa07ac0881f713
prerequisite-patch-id: d24ee333fe0548c916988bc5c1d9fb2c80d9f149
-- 
Regards,

Laurent Pinchart




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux