Zbigniew Jędrzejewski-Szmek | 3762f8e | 2018-09-20 16:34:14 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import dataclasses |
| 4 | import glob |
| 5 | import os |
| 6 | import subprocess |
| 7 | import sys |
| 8 | try: |
| 9 | import colorama as c |
| 10 | GREEN = c.Fore.GREEN |
| 11 | YELLOW = c.Fore.YELLOW |
| 12 | RED = c.Fore.RED |
| 13 | RESET_ALL = c.Style.RESET_ALL |
| 14 | BRIGHT = c.Style.BRIGHT |
| 15 | except ImportError: |
| 16 | GREEN = YELLOW = RED = RESET_ALL = BRIGHT = '' |
| 17 | |
| 18 | @dataclasses.dataclass |
| 19 | class Total: |
| 20 | total:int |
| 21 | good:int = 0 |
| 22 | skip:int = 0 |
| 23 | fail:int = 0 |
| 24 | |
| 25 | tests = glob.glob('/usr/lib/systemd/tests/test-*') |
| 26 | total = Total(total=len(tests)) |
| 27 | for test in tests: |
| 28 | name = os.path.basename(test) |
| 29 | |
| 30 | ex = subprocess.run(test, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 31 | if ex.returncode == 0: |
| 32 | print(f'{GREEN}PASS: {name}{RESET_ALL}') |
| 33 | total.good += 1 |
| 34 | elif ex.returncode == 77: |
| 35 | print(f'{YELLOW}SKIP: {name}{RESET_ALL}') |
| 36 | total.skip += 1 |
| 37 | else: |
| 38 | print(f'{RED}FAIL: {name}{RESET_ALL}') |
| 39 | total.fail += 1 |
| 40 | |
| 41 | # stdout/stderr might not be valid unicode, let's just dump it to the terminal. |
| 42 | # Also let's reset the style afterwards, in case our output sets something. |
| 43 | sys.stdout.buffer.write(ex.stdout) |
| 44 | print(f'{RESET_ALL}{BRIGHT}') |
| 45 | sys.stdout.buffer.write(ex.stderr) |
| 46 | print(f'{RESET_ALL}') |
| 47 | |
| 48 | print(f'{BRIGHT}OK: {total.good} SKIP: {total.skip} FAIL: {total.fail}{RESET_ALL}') |
| 49 | sys.exit(total.fail > 0) |