]> git.ipfire.org Git - thirdparty/systemd.git/blob - test/run-unit-tests.py
Merge pull request #12802 from irtimmer/fix-openssl
[thirdparty/systemd.git] / test / run-unit-tests.py
1 #!/usr/bin/env python3
2
3 import argparse
4 import dataclasses
5 import glob
6 import os
7 import subprocess
8 import sys
9 try:
10 import colorama as c
11 GREEN = c.Fore.GREEN
12 YELLOW = c.Fore.YELLOW
13 RED = c.Fore.RED
14 RESET_ALL = c.Style.RESET_ALL
15 BRIGHT = c.Style.BRIGHT
16 except ImportError:
17 GREEN = YELLOW = RED = RESET_ALL = BRIGHT = ''
18
19 @dataclasses.dataclass
20 class Total:
21 total:int
22 good:int = 0
23 skip:int = 0
24 fail:int = 0
25
26 def argument_parser():
27 p = argparse.ArgumentParser()
28 p.add_argument('-u', '--unsafe', action='store_true',
29 help='run "unsafe" tests too')
30 return p
31
32 opts = argument_parser().parse_args()
33
34 tests = glob.glob('/usr/lib/systemd/tests/test-*')
35 if opts.unsafe:
36 tests += glob.glob('/usr/lib/systemd/tests/unsafe/test-*')
37
38 total = Total(total=len(tests))
39 for test in tests:
40 name = os.path.basename(test)
41
42 ex = subprocess.run(test, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
43 if ex.returncode == 0:
44 print(f'{GREEN}PASS: {name}{RESET_ALL}')
45 total.good += 1
46 elif ex.returncode == 77:
47 print(f'{YELLOW}SKIP: {name}{RESET_ALL}')
48 total.skip += 1
49 else:
50 print(f'{RED}FAIL: {name}{RESET_ALL}')
51 total.fail += 1
52
53 # stdout/stderr might not be valid unicode, let's just dump it to the terminal.
54 # Also let's reset the style afterwards, in case our output sets something.
55 sys.stdout.buffer.write(ex.stdout)
56 print(f'{RESET_ALL}{BRIGHT}')
57 sys.stdout.buffer.write(ex.stderr)
58 print(f'{RESET_ALL}')
59
60 print(f'{BRIGHT}OK: {total.good} SKIP: {total.skip} FAIL: {total.fail}{RESET_ALL}')
61 sys.exit(total.fail > 0)