mtest2make: add support for introspected test dependencies

Right now all "make check" targets depend blindly on "all".  If Meson
is 0.56.0 or newer, we can use the correct dependencies using the new
"depends" entry in "meson introspect --tests".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2020-09-04 10:06:06 -04:00
parent fd5eef85fe
commit 48a81fd5b4
2 changed files with 16 additions and 5 deletions

View File

@ -78,7 +78,7 @@ ${ninja-targets-c_COMPILER} ${ninja-targets-cpp_COMPILER}: .var.command += -MP
# reread (and MESON won't be empty anymore). # reread (and MESON won't be empty anymore).
ifneq ($(MESON),) ifneq ($(MESON),)
Makefile.mtest: build.ninja scripts/mtest2make.py Makefile.mtest: build.ninja scripts/mtest2make.py
$(MESON) introspect --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@ $(MESON) introspect --targets --tests --benchmarks | $(PYTHON) scripts/mtest2make.py > $@
-include Makefile.mtest -include Makefile.mtest
endif endif

View File

@ -5,6 +5,7 @@
# Author: Paolo Bonzini <pbonzini@redhat.com> # Author: Paolo Bonzini <pbonzini@redhat.com>
from collections import defaultdict from collections import defaultdict
import itertools
import json import json
import os import os
import shlex import shlex
@ -36,7 +37,7 @@ SPEED = quick
introspect = json.load(sys.stdin) introspect = json.load(sys.stdin)
i = 0 i = 0
def process_tests(test, suites): def process_tests(test, targets, suites):
global i global i
env = ' '.join(('%s=%s' % (shlex.quote(k), shlex.quote(v)) env = ' '.join(('%s=%s' % (shlex.quote(k), shlex.quote(v))
for k, v in test['env'].items())) for k, v in test['env'].items()))
@ -58,12 +59,19 @@ def process_tests(test, suites):
i += 1 i += 1
if test['workdir'] is not None: if test['workdir'] is not None:
print('.test.dir.%d := %s' % (i, shlex.quote(test['workdir']))) print('.test.dir.%d := %s' % (i, shlex.quote(test['workdir'])))
if 'depends' in test:
deps = (targets.get(x, []) for x in test['depends'])
deps = itertools.chain.from_iterable(deps)
else:
deps = ['all']
print('.test.name.%d := %s' % (i, test['name'])) print('.test.name.%d := %s' % (i, test['name']))
print('.test.driver.%d := %s' % (i, driver)) print('.test.driver.%d := %s' % (i, driver))
print('.test.env.%d := $(.test.env) %s' % (i, env)) print('.test.env.%d := $(.test.env) %s' % (i, env))
print('.test.cmd.%d := %s' % (i, cmd)) print('.test.cmd.%d := %s' % (i, cmd))
print('.PHONY: run-test-%d' % (i,)) print('.PHONY: run-test-%d' % (i,))
print('run-test-%d: all' % (i,)) print('run-test-%d: %s' % (i, ' '.join(deps)))
print('\t@$(call .test.run,%d,$(.test.output-format))' % (i,)) print('\t@$(call .test.run,%d,$(.test.output-format))' % (i,))
test_suites = test['suite'] or ['default'] test_suites = test['suite'] or ['default']
@ -102,16 +110,19 @@ def emit_suite(name, suite, prefix):
print('.tests += $(.test.$(SPEED).%s)' % (target, )) print('.tests += $(.test.$(SPEED).%s)' % (target, ))
print('endif') print('endif')
targets = {t['id']: [os.path.relpath(f) for f in t['filename']]
for t in introspect['targets']}
testsuites = defaultdict(Suite) testsuites = defaultdict(Suite)
for test in introspect['tests']: for test in introspect['tests']:
process_tests(test, testsuites) process_tests(test, targets, testsuites)
emit_prolog(testsuites, 'check') emit_prolog(testsuites, 'check')
for name, suite in testsuites.items(): for name, suite in testsuites.items():
emit_suite(name, suite, 'check') emit_suite(name, suite, 'check')
benchsuites = defaultdict(Suite) benchsuites = defaultdict(Suite)
for test in introspect['benchmarks']: for test in introspect['benchmarks']:
process_tests(test, benchsuites) process_tests(test, targets, benchsuites)
emit_prolog(benchsuites, 'bench') emit_prolog(benchsuites, 'bench')
for name, suite in benchsuites.items(): for name, suite in benchsuites.items():
emit_suite(name, suite, 'bench') emit_suite(name, suite, 'bench')