blob: 4bbc3e2c44733a69c32591770374435de61894b8 [file] [log] [blame]
Zbigniew Jędrzejewski-Szmek3762f8e2018-09-20 16:34:14 +02001#!/usr/bin/env python3
2
3import dataclasses
4import glob
5import os
6import subprocess
7import sys
8try:
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
15except ImportError:
16 GREEN = YELLOW = RED = RESET_ALL = BRIGHT = ''
17
18@dataclasses.dataclass
19class Total:
20 total:int
21 good:int = 0
22 skip:int = 0
23 fail:int = 0
24
25tests = glob.glob('/usr/lib/systemd/tests/test-*')
26total = Total(total=len(tests))
27for 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
48print(f'{BRIGHT}OK: {total.good} SKIP: {total.skip} FAIL: {total.fail}{RESET_ALL}')
49sys.exit(total.fail > 0)