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 %-thorough, $1)), --suite $s)
27 .speed.slow = $(foreach s,$(sort $(filter-out %-thorough, $1)), --suite $s)
28 .speed.thorough = $(foreach s,$(sort $1), --suite $s)
30 .mtestargs = --no-rebuild -t 0
31 ifneq ($(SPEED), quick)
32 .mtestargs += --setup $(SPEED)
34 .mtestargs += $(subst -j,--num-processes , $(filter-out -j, $(lastword -j1 $(filter -j%, $(MAKEFLAGS)))))
36 .check.mtestargs = $(MTESTARGS) $(.mtestargs) $(if $(V),--verbose,--print-errorlogs)
37 .bench.mtestargs = $(MTESTARGS) $(.mtestargs) --benchmark --verbose''')
39 introspect
= json
.load(sys
.stdin
)
41 def process_tests(test
, targets
, suites
):
42 executable
= test
['cmd'][0]
44 executable
= os
.path
.relpath(executable
)
48 deps
= (targets
.get(x
, []) for x
in test
['depends'])
49 deps
= itertools
.chain
.from_iterable(deps
)
52 test_suites
= test
['suite'] or ['default']
54 # The suite name in the introspection info is "PROJECT" or "PROJECT:SUITE"
57 if s
== 'slow' or s
== 'thorough':
59 if s
.endswith('-slow'):
61 suites
[s
].speeds
.append('slow')
62 if s
.endswith('-thorough'):
64 suites
[s
].speeds
.append('thorough')
65 suites
[s
].deps
.update(deps
)
67 def emit_prolog(suites
, prefix
):
68 all_targets
= ' '.join((f
'{prefix}-{k}' for k
in suites
.keys()))
69 all_xml
= ' '.join((f
'{prefix}-report-{k}.junit.xml' for k
in suites
.keys()))
71 print(f
'all-{prefix}-targets = {all_targets}')
72 print(f
'all-{prefix}-xml = {all_xml}')
73 print(f
'.PHONY: {prefix} do-meson-{prefix} {prefix}-report.junit.xml $(all-{prefix}-targets) $(all-{prefix}-xml)')
74 print(f
'ifeq ($(filter {prefix}, $(MAKECMDGOALS)),)')
75 print(f
'.{prefix}.mtestargs += $(call .speed.$(SPEED), $(.{prefix}.mtest-suites))')
77 print(f
'{prefix}-build: run-ninja')
78 print(f
'{prefix} $(all-{prefix}-targets): do-meson-{prefix}')
79 print(f
'do-meson-{prefix}: run-ninja; $(if $(MAKE.n),,+)$(MESON) test $(.{prefix}.mtestargs)')
80 print(f
'{prefix}-report.junit.xml $(all-{prefix}-xml): {prefix}-report%.junit.xml: run-ninja')
81 print(f
'\t$(MAKE) {prefix}$* MTESTARGS="$(MTESTARGS) --logbase {prefix}-report$*" && ln -f meson-logs/$@ .')
83 def emit_suite_deps(name
, suite
, prefix
):
84 deps
= ' '.join(suite
.deps
)
85 targets
= [f
'{prefix}-{name}', f
'{prefix}-report-{name}.junit.xml', f
'{prefix}', f
'{prefix}-report.junit.xml',
88 print(f
'.{prefix}-{name}.deps = {deps}')
90 print(f
'.ninja-goals.{t} += $(.{prefix}-{name}.deps)')
92 def emit_suite(name
, suite
, prefix
):
93 emit_suite_deps(name
, suite
, prefix
)
94 targets
= f
'{prefix}-{name} {prefix}-report-{name}.junit.xml {prefix} {prefix}-report.junit.xml'
95 print(f
'ifneq ($(filter {targets}, $(MAKECMDGOALS)),)')
96 print(f
'.{prefix}.mtest-suites += ' + ' '.join(suite
.names(name
)))
99 targets
= {t
['id']: [os
.path
.relpath(f
) for f
in t
['filename']]
100 for t
in introspect
['targets']}
102 testsuites
= defaultdict(Suite
)
103 for test
in introspect
['tests']:
104 process_tests(test
, targets
, testsuites
)
105 emit_prolog(testsuites
, 'check')
106 for name
, suite
in testsuites
.items():
107 emit_suite(name
, suite
, 'check')
109 benchsuites
= defaultdict(Suite
)
110 for test
in introspect
['benchmarks']:
111 process_tests(test
, targets
, benchsuites
)
112 emit_prolog(benchsuites
, 'bench')
113 for name
, suite
in benchsuites
.items():
114 emit_suite(name
, suite
, 'bench')