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