summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-05 20:35:30 +0200
committerGitHub <noreply@github.com>2018-10-05 20:35:30 +0200
commitad191df836b79b74ac300229536a512d308cdbf1 (patch)
tree0ad46d6eccfe8f1e5422f5457b813055f7e0f3c0 /test
parent8a89c5392d90d0a906debec729e3ccf7b5f63b09 (diff)
parentf5acf84dbed6365c484c577ba7245d4054750ef2 (diff)
downloadsystemd-ad191df836b79b74ac300229536a512d308cdbf1.tar.gz
Merge pull request #10134 from keszybz/test-runner
Some test-related fixed and a test runner for installed tests
Diffstat (limited to 'test')
-rw-r--r--test/meson.build8
-rwxr-xr-xtest/run-unit-tests.py61
2 files changed, 69 insertions, 0 deletions
diff --git a/test/meson.build b/test/meson.build
index 7e8f2cfa90..bf02e39f43 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -230,6 +230,14 @@ endif
############################################################
+if install_tests
+ install_data('run-unit-tests.py',
+ install_mode : 'rwxr-xr-x',
+ install_dir : testsdir)
+endif
+
+############################################################
+
# prepare test/sys tree
sys_script_py = find_program('sys-script.py')
custom_target(
diff --git a/test/run-unit-tests.py b/test/run-unit-tests.py
new file mode 100755
index 0000000000..9a75cd421e
--- /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)