diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:25:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:25:50 +0000 |
commit | 19f4f86bfed21c5326ed2acebe1163f3a83e832b (patch) | |
tree | d59b9989ce55ed23693e80974d94c856f1c2c8b1 /test/run-unit-tests.py | |
parent | Initial commit. (diff) | |
download | systemd-d54215faec6264b9021f699873239ee9e4d99e5b.tar.xz systemd-d54215faec6264b9021f699873239ee9e4d99e5b.zip |
Adding upstream version 241.upstream/241upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/run-unit-tests.py')
-rwxr-xr-x | test/run-unit-tests.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/run-unit-tests.py b/test/run-unit-tests.py new file mode 100755 index 0000000..9a75cd4 --- /dev/null +++ b/test/run-unit-tests.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import argparse +import dataclasses +import glob +import os +import subprocess +import sys +try: + import colorama as c + GREEN = c.Fore.GREEN + YELLOW = c.Fore.YELLOW + RED = c.Fore.RED + RESET_ALL = c.Style.RESET_ALL + BRIGHT = c.Style.BRIGHT +except ImportError: + GREEN = YELLOW = RED = RESET_ALL = BRIGHT = '' + +@dataclasses.dataclass +class Total: + total:int + good:int = 0 + skip:int = 0 + fail:int = 0 + +def argument_parser(): + p = argparse.ArgumentParser() + p.add_argument('-u', '--unsafe', action='store_true', + help='run "unsafe" tests too') + return p + +opts = argument_parser().parse_args() + +tests = glob.glob('/usr/lib/systemd/tests/test-*') +if opts.unsafe: + tests += glob.glob('/usr/lib/systemd/tests/unsafe/test-*') + +total = Total(total=len(tests)) +for test in tests: + name = os.path.basename(test) + + ex = subprocess.run(test, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if ex.returncode == 0: + print(f'{GREEN}PASS: {name}{RESET_ALL}') + total.good += 1 + elif ex.returncode == 77: + print(f'{YELLOW}SKIP: {name}{RESET_ALL}') + total.skip += 1 + else: + print(f'{RED}FAIL: {name}{RESET_ALL}') + total.fail += 1 + + # stdout/stderr might not be valid unicode, let's just dump it to the terminal. + # Also let's reset the style afterwards, in case our output sets something. + sys.stdout.buffer.write(ex.stdout) + print(f'{RESET_ALL}{BRIGHT}') + sys.stdout.buffer.write(ex.stderr) + print(f'{RESET_ALL}') + +print(f'{BRIGHT}OK: {total.good} SKIP: {total.skip} FAIL: {total.fail}{RESET_ALL}') +sys.exit(total.fail > 0) |