hw/ppc/spapr_drc.c: use g_auto in spapr_dt_drc()
[qemu.git] / scripts / mtest2make.py
blob4d542e8aaa0c4a28d3d1776c164c0a1e65807e68
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
8 import itertools
9 import json
10 import os
11 import shlex
12 import sys
14 class Suite(object):
15 def __init__(self):
16 self.deps = set()
17 self.speeds = ['quick']
19 def names(self, base):
20 return [base if speed == 'quick' else f'{base}-{speed}' for speed in self.speeds]
23 print('''
24 SPEED = quick
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)
33 endif
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]
43 try:
44 executable = os.path.relpath(executable)
45 except:
46 pass
48 deps = (targets.get(x, []) for x in test['depends'])
49 deps = itertools.chain.from_iterable(deps)
50 deps = list(deps)
52 test_suites = test['suite'] or ['default']
53 for s in test_suites:
54 # The suite name in the introspection info is "PROJECT:SUITE"
55 s = s.split(':')[1]
56 if s == 'slow' or s == 'thorough':
57 continue
58 if s.endswith('-slow'):
59 s = s[:-5]
60 suites[s].speeds.append('slow')
61 if s.endswith('-thorough'):
62 s = s[:-9]
63 suites[s].speeds.append('thorough')
64 suites[s].deps.update(deps)
66 def emit_prolog(suites, prefix):
67 all_targets = ' '.join((f'{prefix}-{k}' for k in suites.keys()))
68 all_xml = ' '.join((f'{prefix}-report-{k}.junit.xml' for k in suites.keys()))
69 print()
70 print(f'all-{prefix}-targets = {all_targets}')
71 print(f'all-{prefix}-xml = {all_xml}')
72 print(f'.PHONY: {prefix} do-meson-{prefix} {prefix}-report.junit.xml $(all-{prefix}-targets) $(all-{prefix}-xml)')
73 print(f'ifeq ($(filter {prefix}, $(MAKECMDGOALS)),)')
74 print(f'.{prefix}.mtestargs += $(call .speed.$(SPEED), $(.{prefix}.mtest-suites))')
75 print(f'endif')
76 print(f'{prefix}-build: run-ninja')
77 print(f'{prefix} $(all-{prefix}-targets): do-meson-{prefix}')
78 print(f'do-meson-{prefix}: run-ninja; $(if $(MAKE.n),,+)$(MESON) test $(.{prefix}.mtestargs)')
79 print(f'{prefix}-report.junit.xml $(all-{prefix}-xml): {prefix}-report%.junit.xml: run-ninja')
80 print(f'\t$(MAKE) {prefix}$* MTESTARGS="$(MTESTARGS) --logbase {prefix}-report$*" && ln -f meson-logs/$@ .')
82 def emit_suite_deps(name, suite, prefix):
83 deps = ' '.join(suite.deps)
84 targets = f'{prefix}-{name} {prefix}-report-{name}.junit.xml {prefix} {prefix}-report.junit.xml'
85 print()
86 print(f'.{prefix}-{name}.deps = {deps}')
87 print(f'ifneq ($(filter {prefix}-build {targets}, $(MAKECMDGOALS)),)')
88 print(f'.{prefix}.build-suites += {name}')
89 print(f'endif')
91 def emit_suite(name, suite, prefix):
92 emit_suite_deps(name, suite, prefix)
93 targets = f'{prefix}-{name} {prefix}-report-{name}.junit.xml {prefix} {prefix}-report.junit.xml'
94 print(f'ifneq ($(filter {targets}, $(MAKECMDGOALS)),)')
95 print(f'.{prefix}.mtest-suites += ' + ' '.join(suite.names(name)))
96 print(f'endif')
98 targets = {t['id']: [os.path.relpath(f) for f in t['filename']]
99 for t in introspect['targets']}
101 testsuites = defaultdict(Suite)
102 for test in introspect['tests']:
103 process_tests(test, targets, testsuites)
104 # HACK: check-block is a separate target so that it runs with --verbose;
105 # only write the dependencies
106 emit_suite_deps('block', testsuites['block'], 'check')
107 del testsuites['block']
108 emit_prolog(testsuites, 'check')
109 for name, suite in testsuites.items():
110 emit_suite(name, suite, 'check')
112 benchsuites = defaultdict(Suite)
113 for test in introspect['benchmarks']:
114 process_tests(test, targets, benchsuites)
115 emit_prolog(benchsuites, 'bench')
116 for name, suite in benchsuites.items():
117 emit_suite(name, suite, 'bench')