]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/run-unit-tests.py
network: make all failures in route configuration fatal
[thirdparty/systemd.git] / test / run-unit-tests.py
CommitLineData
3762f8e3
ZJS
1#!/usr/bin/env python3
2
f5acf84d 3import argparse
3762f8e3
ZJS
4import dataclasses
5import glob
6import os
7import subprocess
8import sys
9try:
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
16except ImportError:
17 GREEN = YELLOW = RED = RESET_ALL = BRIGHT = ''
18
19@dataclasses.dataclass
20class Total:
21 total:int
22 good:int = 0
23 skip:int = 0
24 fail:int = 0
25
f5acf84d
ZJS
26def 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
32opts = argument_parser().parse_args()
33
3762f8e3 34tests = glob.glob('/usr/lib/systemd/tests/test-*')
f5acf84d
ZJS
35if opts.unsafe:
36 tests += glob.glob('/usr/lib/systemd/tests/unsafe/test-*')
37
3762f8e3
ZJS
38total = Total(total=len(tests))
39for 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
60print(f'{BRIGHT}OK: {total.good} SKIP: {total.skip} FAIL: {total.fail}{RESET_ALL}')
61sys.exit(total.fail > 0)