target/riscv: Enable the Hypervisor extension by default
[qemu/ar7.git] / scripts / mtest2make.py
blob7067bdadf57b2384fa93d5482d0d5c443688d1bf
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, $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)
32 endif
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]
42 try:
43 executable = os.path.relpath(executable)
44 except:
45 pass
47 deps = (targets.get(x, []) for x in test['depends'])
48 deps = itertools.chain.from_iterable(deps)
49 deps = list(deps)
51 test_suites = test['suite'] or ['default']
52 for s in test_suites:
53 # The suite name in the introspection info is "PROJECT:SUITE"
54 s = s.split(':')[1]
55 if s == 'slow':
56 continue
57 if s.endswith('-slow'):
58 s = s[:-5]
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()))
65 print()
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))')
71 print(f'endif')
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'
81 print()
82 print(f'.{prefix}-{name}.deps = {deps}')
83 print(f'ifneq ($(filter {prefix}-build {targets}, $(MAKECMDGOALS)),)')
84 print(f'.{prefix}.build-suites += {name}')
85 print(f'endif')
86 print(f'ifneq ($(filter {targets}, $(MAKECMDGOALS)),)')
87 print(f'.{prefix}.mtest-suites += ' + ' '.join(suite.names(name)))
88 print(f'endif')
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')