aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile18
-rw-r--r--rules.mk18
-rwxr-xr-xscripts/test_runner.py38
3 files changed, 57 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 34d166a..4f9bda5 100644
--- a/Makefile
+++ b/Makefile
@@ -40,20 +40,14 @@ clean:
@${MAKE} -C src clean
test:
- @echo " -> Running tests in ${ARCH}"
- @make -C ${ARCH} test > /dev/null
- @echo " -> Running tests in lib"
- @make -C lib test > /dev/null
- @echo " -> Running tests in src"
- @make -C src test > /dev/null
+ @make -C ${ARCH} test.quiet
+ @make -C lib test.quiet
+ @make -C src test.quiet
valgrind:
- @echo " -> Running valgrind on tests in ${ARCH}"
- @make -C ${ARCH} valgrind &> /dev/null
- @echo " -> Running valgrind on tests in lib"
- @make -C lib valgrind &> /dev/null
- @echo " -> Running valgrind on tests in src"
- @make -C src valgrind &> /dev/null
+ @make -C ${ARCH} valgrind.quiet
+ @make -C lib valgrind.quiet
+ @make -C src valgrind.quiet
# configure targets
.config: Kconfig
diff --git a/rules.mk b/rules.mk
index 75fa9f1..b22a3b3 100644
--- a/rules.mk
+++ b/rules.mk
@@ -119,14 +119,22 @@ test_%: test_%.cc
@echo ' CXX TEST $@'
@${HOST_CXX} ${HOST_CXXFLAGS} ${HOST_LDFLAGS} $< -o $@
-.PHONY: test.base valgrind.base clean.base FORCE
-test.base: ${TESTS}
+.PHONY: test test.quiet valgrind valgrind.quiet clean.base FORCE
+test: ${TESTS}
@echo " -> Running tests in $(shell pwd | xargs basename)"
- @$(foreach f,$^,echo " -> $f"; ./$f &&) echo "Done"
+ @../scripts/test_runner.py --verbose ${TESTS}
-valgrind.base: ${TESTS}
+test.quiet: ${TESTS}
+ @echo " -> Running tests in $(shell pwd | xargs basename)"
+ @../scripts/test_runner.py ${TESTS}
+
+valgrind: ${TESTS}
+ @echo " -> Running valgrind on tests in $(shell pwd | xargs basename)"
+ @../scripts/test_runner.py --verbose --valgrind ${TESTS}
+
+valgrind.quiet: ${TESTS}
@echo " -> Running valgrind on tests in $(shell pwd | xargs basename)"
- @$(foreach f,$^,echo " -> $f"; valgrind --leak-check=full ./$f;)
+ @../scripts/test_runner.py --valgrind ${TESTS}
clean.base: FORCE
@echo " -> Cleaning $(shell pwd | xargs basename)"
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
new file mode 100755
index 0000000..80c3e30
--- /dev/null
+++ b/scripts/test_runner.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+""" Test runner """
+
+import argparse
+import os
+import subprocess
+
+def main():
+ """ Main function"""
+
+ parser = argparse.ArgumentParser(description='Run test executables')
+ parser.add_argument('-v', '--verbose', action='store_true', help='Show test stdout/stderr')
+ parser.add_argument('--valgrind', action='store_true', help='Run tests under valgrind')
+ parser.add_argument('test', type=str, nargs='+', help='test executable to run')
+ args = parser.parse_args()
+
+ cwd = os.getcwd()
+ fail_count = 0
+
+ for test in args.test:
+ cmd = []
+ if args.valgrind:
+ cmd += [ 'valgrind', '--leak-check=full', '--error-exitcode=128' ]
+ cmd.append(os.path.join(cwd, test))
+ #print(cmd)
+
+ print(f' {test:.<48}', end='')
+ result = subprocess.run(cmd, capture_output=not args.verbose, check=False)
+ print('ok' if result.returncode == 0 else 'failed')
+ if result.returncode != 0:
+ fail_count += 1
+
+ print(f' Ran {len(args.test)} tests, {fail_count} failed')
+
+
+if __name__ == '__main__':
+ main()