2020-01-28 13:48:54 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
# Create Makefile targets to run tests, from Meson's test introspection data.
|
|
|
|
#
|
|
|
|
# Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
|
|
|
|
|
from collections import defaultdict
|
2020-09-04 14:06:06 +00:00
|
|
|
import itertools
|
2020-01-28 13:48:54 +00:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import sys
|
|
|
|
|
|
|
|
class Suite(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.tests = list()
|
|
|
|
self.slow_tests = list()
|
|
|
|
self.executables = set()
|
|
|
|
|
|
|
|
print('''
|
|
|
|
SPEED = quick
|
|
|
|
|
2020-09-01 13:58:48 +00:00
|
|
|
# $1 = environment, $2 = test command, $3 = test name, $4 = dir
|
|
|
|
.test-human-tap = $1 $(if $4,(cd $4 && $2),$2) < /dev/null | ./scripts/tap-driver.pl --test-name="$3" $(if $(V),,--show-failures-only)
|
2020-09-01 13:14:41 +00:00
|
|
|
.test-human-exitcode = $1 $(PYTHON) scripts/test-driver.py $(if $4,-C$4) $(if $(V),--verbose) -- $2 < /dev/null
|
2020-09-01 13:58:48 +00:00
|
|
|
.test-tap-tap = $1 $(if $4,(cd $4 && $2),$2) < /dev/null | sed "s/^[a-z][a-z]* [0-9]*/& $3/" || true
|
|
|
|
.test-tap-exitcode = printf "%s\\n" 1..1 "`$1 $(if $4,(cd $4 && $2),$2) < /dev/null > /dev/null || echo "not "`ok 1 $3"
|
2020-09-02 11:19:43 +00:00
|
|
|
.test.human-print = echo $(if $(V),'$1 $2','Running test $3') &&
|
2020-01-28 13:48:54 +00:00
|
|
|
.test.env = MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))}
|
|
|
|
|
|
|
|
# $1 = test name, $2 = test target (human or tap)
|
2020-09-02 11:19:43 +00:00
|
|
|
.test.run = $(call .test.$2-print,$(.test.env.$1),$(.test.cmd.$1),$(.test.name.$1)) $(call .test-$2-$(.test.driver.$1),$(.test.env.$1),$(.test.cmd.$1),$(.test.name.$1),$(.test.dir.$1))
|
2020-01-28 13:48:54 +00:00
|
|
|
|
2020-09-02 11:19:43 +00:00
|
|
|
.test.output-format = human
|
2020-01-28 13:48:54 +00:00
|
|
|
''')
|
|
|
|
|
2020-09-02 11:19:43 +00:00
|
|
|
introspect = json.load(sys.stdin)
|
2020-01-28 13:48:54 +00:00
|
|
|
i = 0
|
2020-09-02 11:19:43 +00:00
|
|
|
|
2020-09-04 14:06:06 +00:00
|
|
|
def process_tests(test, targets, suites):
|
2020-09-02 11:19:43 +00:00
|
|
|
global i
|
2020-01-28 13:48:54 +00:00
|
|
|
env = ' '.join(('%s=%s' % (shlex.quote(k), shlex.quote(v))
|
|
|
|
for k, v in test['env'].items()))
|
2020-08-26 15:10:02 +00:00
|
|
|
executable = test['cmd'][0]
|
|
|
|
try:
|
|
|
|
executable = os.path.relpath(executable)
|
|
|
|
except:
|
|
|
|
pass
|
2020-01-28 13:48:54 +00:00
|
|
|
if test['workdir'] is not None:
|
2020-08-26 15:10:02 +00:00
|
|
|
try:
|
|
|
|
test['cmd'][0] = os.path.relpath(executable, test['workdir'])
|
|
|
|
except:
|
|
|
|
test['cmd'][0] = executable
|
2020-01-28 13:48:54 +00:00
|
|
|
else:
|
|
|
|
test['cmd'][0] = executable
|
2020-09-01 13:58:48 +00:00
|
|
|
cmd = ' '.join((shlex.quote(x) for x in test['cmd']))
|
2020-01-28 13:48:54 +00:00
|
|
|
driver = test['protocol'] if 'protocol' in test else 'exitcode'
|
|
|
|
|
|
|
|
i += 1
|
2020-09-01 13:58:48 +00:00
|
|
|
if test['workdir'] is not None:
|
|
|
|
print('.test.dir.%d := %s' % (i, shlex.quote(test['workdir'])))
|
2020-09-04 14:06:06 +00:00
|
|
|
|
|
|
|
if 'depends' in test:
|
|
|
|
deps = (targets.get(x, []) for x in test['depends'])
|
|
|
|
deps = itertools.chain.from_iterable(deps)
|
|
|
|
else:
|
|
|
|
deps = ['all']
|
|
|
|
|
2020-01-28 13:48:54 +00:00
|
|
|
print('.test.name.%d := %s' % (i, test['name']))
|
|
|
|
print('.test.driver.%d := %s' % (i, driver))
|
2020-09-01 13:58:48 +00:00
|
|
|
print('.test.env.%d := $(.test.env) %s' % (i, env))
|
2020-01-28 13:48:54 +00:00
|
|
|
print('.test.cmd.%d := %s' % (i, cmd))
|
2020-08-13 13:28:11 +00:00
|
|
|
print('.test.deps.%d := %s' % (i, ' '.join(deps)))
|
2020-09-02 11:19:43 +00:00
|
|
|
print('.PHONY: run-test-%d' % (i,))
|
2020-08-13 13:28:11 +00:00
|
|
|
print('run-test-%d: $(.test.deps.%d)' % (i,i))
|
2020-09-02 11:19:43 +00:00
|
|
|
print('\t@$(call .test.run,%d,$(.test.output-format))' % (i,))
|
2020-01-28 13:48:54 +00:00
|
|
|
|
|
|
|
test_suites = test['suite'] or ['default']
|
|
|
|
is_slow = any(s.endswith('-slow') for s in test_suites)
|
|
|
|
for s in test_suites:
|
|
|
|
# The suite name in the introspection info is "PROJECT:SUITE"
|
|
|
|
s = s.split(':')[1]
|
|
|
|
if s.endswith('-slow'):
|
|
|
|
s = s[:-5]
|
|
|
|
if is_slow:
|
|
|
|
suites[s].slow_tests.append(i)
|
|
|
|
else:
|
|
|
|
suites[s].tests.append(i)
|
|
|
|
suites[s].executables.add(executable)
|
|
|
|
|
2020-09-02 11:19:43 +00:00
|
|
|
def emit_prolog(suites, prefix):
|
|
|
|
all_tap = ' '.join(('%s-report-%s.tap' % (prefix, k) for k in suites.keys()))
|
|
|
|
print('.PHONY: %s %s-report.tap %s' % (prefix, prefix, all_tap))
|
|
|
|
print('%s: run-tests' % (prefix,))
|
|
|
|
print('%s-report.tap %s: %s-report%%.tap: all' % (prefix, all_tap, prefix))
|
|
|
|
print('''\t$(MAKE) .test.output-format=tap --quiet -Otarget V=1 %s$* | ./scripts/tap-merge.pl | tee "$@" \\
|
|
|
|
| ./scripts/tap-driver.pl $(if $(V),, --show-failures-only)''' % (prefix, ))
|
|
|
|
|
|
|
|
def emit_suite(name, suite, prefix):
|
2020-01-28 13:48:54 +00:00
|
|
|
executables = ' '.join(suite.executables)
|
|
|
|
slow_test_numbers = ' '.join((str(x) for x in suite.slow_tests))
|
|
|
|
test_numbers = ' '.join((str(x) for x in suite.tests))
|
2020-09-02 11:19:43 +00:00
|
|
|
target = '%s-%s' % (prefix, name)
|
|
|
|
print('.test.quick.%s := %s' % (target, test_numbers))
|
|
|
|
print('.test.slow.%s := $(.test.quick.%s) %s' % (target, target, slow_test_numbers))
|
|
|
|
print('%s-build: %s' % (prefix, executables))
|
|
|
|
print('.PHONY: %s' % (target, ))
|
|
|
|
print('.PHONY: %s-report-%s.tap' % (prefix, name))
|
|
|
|
print('%s: run-tests' % (target, ))
|
|
|
|
print('ifneq ($(filter %s %s, $(MAKECMDGOALS)),)' % (target, prefix))
|
|
|
|
print('.tests += $(.test.$(SPEED).%s)' % (target, ))
|
|
|
|
print('endif')
|
2021-02-02 13:39:57 +00:00
|
|
|
print('all-%s-targets += %s' % (prefix, target))
|
2020-09-02 11:19:43 +00:00
|
|
|
|
2020-09-04 14:06:06 +00:00
|
|
|
targets = {t['id']: [os.path.relpath(f) for f in t['filename']]
|
|
|
|
for t in introspect['targets']}
|
|
|
|
|
2020-09-02 11:19:43 +00:00
|
|
|
testsuites = defaultdict(Suite)
|
2020-09-02 11:25:19 +00:00
|
|
|
for test in introspect['tests']:
|
2020-09-04 14:06:06 +00:00
|
|
|
process_tests(test, targets, testsuites)
|
2020-09-02 11:19:43 +00:00
|
|
|
emit_prolog(testsuites, 'check')
|
|
|
|
for name, suite in testsuites.items():
|
|
|
|
emit_suite(name, suite, 'check')
|
|
|
|
|
2020-09-02 11:25:19 +00:00
|
|
|
benchsuites = defaultdict(Suite)
|
|
|
|
for test in introspect['benchmarks']:
|
2020-09-04 14:06:06 +00:00
|
|
|
process_tests(test, targets, benchsuites)
|
2020-09-02 11:25:19 +00:00
|
|
|
emit_prolog(benchsuites, 'bench')
|
|
|
|
for name, suite in benchsuites.items():
|
|
|
|
emit_suite(name, suite, 'bench')
|
|
|
|
|
2020-09-02 11:19:43 +00:00
|
|
|
print('run-tests: $(patsubst %, run-test-%, $(.tests))')
|