1 #! /usr/bin/env python3
3 # Create Makefile targets to run tests, from Meson's test introspection data.
5 # Author: Paolo Bonzini <pbonzini@redhat.com>
7 from collections
import defaultdict
17 self
.speeds
= ['quick']
19 def names(self
, base
):
20 return [base
if speed
== 'quick' else f
'{base}-{speed}' for speed
in self
.speeds
]
26 .speed.quick = $(foreach s,$(sort $(filter-out %-slow, $1)), --suite $s)
27 .speed.slow = $(foreach s,$(sort $1), --suite $s)
29 .mtestargs = --no-rebuild -t 0
30 ifneq ($(SPEED), quick)
31 .mtestargs += --setup $(SPEED)
33 .mtestargs += $(subst -j,--num-processes , $(filter-out -j, $(lastword -j1 $(filter -j%, $(MAKEFLAGS)))))
35 .check.mtestargs = $(MTESTARGS) $(.mtestargs) $(if $(V),--verbose,--print-errorlogs)
36 .bench.mtestargs = $(MTESTARGS) $(.mtestargs) --benchmark --verbose''')
38 introspect
= json
.load(sys
.stdin
)
40 def process_tests(test
, targets
, suites
):
41 executable
= test
['cmd'][0]
43 executable
= os
.path
.relpath(executable
)
47 deps
= (targets
.get(x
, []) for x
in test
['depends'])
48 deps
= itertools
.chain
.from_iterable(deps
)
51 test_suites
= test
['suite'] or ['default']
53 # The suite name in the introspection info is "PROJECT:SUITE"
57 if s
.endswith('-slow'):
59 suites
[s
].speeds
.append('slow')
60 suites
[s
].deps
.update(deps
)
62 def emit_prolog(suites
, prefix
):
63 all_targets
= ' '.join((f
'{prefix}-{k}' for k
in suites
.keys()))
64 all_xml
= ' '.join((f
'{prefix}-report-{k}.junit.xml' for k
in suites
.keys()))
66 print(f
'all-{prefix}-targets = {all_targets}')
67 print(f
'all-{prefix}-xml = {all_xml}')
68 print(f
'.PHONY: {prefix} do-meson-{prefix} {prefix}-report.junit.xml $(all-{prefix}-targets) $(all-{prefix}-xml)')
69 print(f
'ifeq ($(filter {prefix}, $(MAKECMDGOALS)),)')
70 print(f
'.{prefix}.mtestargs += $(call .speed.$(SPEED), $(.{prefix}.mtest-suites))')
72 print(f
'{prefix}-build: run-ninja')
73 print(f
'{prefix} $(all-{prefix}-targets): do-meson-{prefix}')
74 print(f
'do-meson-{prefix}: run-ninja; $(if $(MAKE.n),,+)$(MESON) test $(.{prefix}.mtestargs)')
75 print(f
'{prefix}-report.junit.xml $(all-{prefix}-xml): {prefix}-report%.junit.xml: run-ninja')
76 print(f
'\t$(MAKE) {prefix}$* MTESTARGS="$(MTESTARGS) --logbase {prefix}-report$*" && ln -f meson-logs/$@ .')
78 def emit_suite(name
, suite
, prefix
):
79 deps
= ' '.join(suite
.deps
)
80 targets
= f
'{prefix}-{name} {prefix}-report-{name}.junit.xml {prefix} {prefix}-report.junit.xml'
82 print(f
'.{prefix}-{name}.deps = {deps}')
83 print(f
'ifneq ($(filter {prefix}-build {targets}, $(MAKECMDGOALS)),)')
84 print(f
'.{prefix}.build-suites += {name}')
86 print(f
'ifneq ($(filter {targets}, $(MAKECMDGOALS)),)')
87 print(f
'.{prefix}.mtest-suites += ' + ' '.join(suite
.names(name
)))
90 targets
= {t
['id']: [os
.path
.relpath(f
) for f
in t
['filename']]
91 for t
in introspect
['targets']}
93 testsuites
= defaultdict(Suite
)
94 for test
in introspect
['tests']:
95 process_tests(test
, targets
, testsuites
)
96 emit_prolog(testsuites
, 'check')
97 for name
, suite
in testsuites
.items():
98 emit_suite(name
, suite
, 'check')
100 benchsuites
= defaultdict(Suite
)
101 for test
in introspect
['benchmarks']:
102 process_tests(test
, targets
, benchsuites
)
103 emit_prolog(benchsuites
, 'bench')
104 for name
, suite
in benchsuites
.items():
105 emit_suite(name
, suite
, 'bench')