Makefile: run tests in parallel

This commit is contained in:
Michele Guerini Rocco 2024-04-12 17:31:53 +02:00
parent babca8bdc4
commit 097fa42329
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
2 changed files with 34 additions and 6 deletions

View File

@ -79,6 +79,9 @@ FFLAGS += -J$(OBJDIR) -I$(INCDIR) -ffree-line-length-none -fPIC -frecursive
LDFLAGS += -L$(LIBDIR) LDFLAGS += -L$(LIBDIR)
CPPFLAGS += -DREVISION=\"$(GIT_REV)$(GIT_DIRTY)\" -DPREFIX=\"$(PREFIX)\" CPPFLAGS += -DREVISION=\"$(GIT_REV)$(GIT_DIRTY)\" -DPREFIX=\"$(PREFIX)\"
# Sync the output from jobs running in parallel
MAKEFLAGS += --output-sync
ifndef DETERMINISTIC ifndef DETERMINISTIC
ifdef AR_DEFAULT_DETERMINISTIC ifdef AR_DEFAULT_DETERMINISTIC
# Write timestamps to allow partial updates # Write timestamps to allow partial updates
@ -122,9 +125,12 @@ all: $(BINARIES) $(LIBRARIES)
clean: clean:
rm -r $(BUILDDIR) rm -r $(BUILDDIR)
# Run tests # Run all tests
check: $(GRAY) check: $(shell python -Bm tests --list-cases)
python -Bm tests --binary $^
# Run a test case
tests.%: $(GRAY)
python -Bm tests '$@' --binary '$(GRAY)'
# Install libraries, binaries and documentation # Install libraries, binaries and documentation
install: $(BINARIES) $(LIBRARIES) $(SHAREDIR)/doc $(MANPAGES) install: $(BINARIES) $(LIBRARIES) $(SHAREDIR)/doc $(MANPAGES)

View File

@ -3,9 +3,24 @@ import unittest
import tests import tests
def get_cases(suite):
'''
Get a list of TestCase from a TestSuite
'''
if hasattr(suite, '__iter__'):
res = set()
for x in suite:
res |= get_cases(x)
return res
mod = type(suite).__module__
cls = type(suite).__name__
return {f'{mod}.{cls}'}
if __name__ == '__main__': if __name__ == '__main__':
# handle custom CLI arguments # handle custom CLI arguments
parser = argparse.ArgumentParser(add_help=False) parser = argparse.ArgumentParser(prog='tests.main')
parser.add_argument('--keep-failed', action='store_true', parser.add_argument('--keep-failed', action='store_true',
help='whether to keep output files of failed tests') help='whether to keep output files of failed tests')
parser.add_argument('--visual', action='store_true', parser.add_argument('--visual', action='store_true',
@ -15,8 +30,15 @@ if __name__ == '__main__':
'current ones') 'current ones')
parser.add_argument('--binary', type=str, default='build/bin/gray', parser.add_argument('--binary', type=str, default='build/bin/gray',
help='the gray binary to be tested') help='the gray binary to be tested')
parser.add_argument('--list-cases', action='store_true',
help='only list the test cases')
options, other_args = parser.parse_known_args() options, other_args = parser.parse_known_args()
tests.options = options tests.options = options
# start the test runner if options.list_cases:
unittest.main(module=None, argv=["tests.main"] + other_args) # list all test cases
suite = unittest.TestLoader().discover('.')
print(*sorted(get_cases(suite)), sep='\n')
else:
# start the test runner
unittest.main(module=None, argv=["tests.main"] + other_args)