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
16 self
.slow_tests
= list()
17 self
.executables
= set()
22 # $1 = test command, $2 = test name
23 .test-human-tap = $1 < /dev/null | ./scripts/tap-driver.pl --test-name="$2" $(if $(V),,--show-failures-only)
24 .test-human-exitcode = $1 < /dev/null
25 .test-tap-tap = $1 < /dev/null | sed "s/^[a-z][a-z]* [0-9]*/& $2/" || true
26 .test-tap-exitcode = printf "%s\\n" 1..1 "`$1 < /dev/null > /dev/null || echo "not "`ok 1 $2"
27 .test.print = echo $(if $(V),'$1','Running test $2') >&3
28 .test.env = MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))}
30 # $1 = test name, $2 = test target (human or tap)
31 .test.run = $(call .test.print,$(.test.cmd.$1),$(.test.name.$1)) && $(call .test-$2-$(.test.driver.$1),$(.test.cmd.$1),$(.test.name.$1))
34 @exec 3>&1; rc=0; $(foreach TEST, $1, $(call .test.run,$(TEST),human) || rc=$$?;) \\
37 define .test.human_no_k
38 $(foreach TEST, $1, @exec 3>&1; $(call .test.run,$(TEST),human)
42 $(if $(findstring k, $(MAKEFLAGS)), $(.test.human_k), $(.test.human_no_k))
45 @exec 3>&1; { $(foreach TEST, $1, $(call .test.run,$(TEST),tap); ) } \\
46 | ./scripts/tap-merge.pl | tee "$@" \\
47 | ./scripts/tap-driver.pl $(if $(V),, --show-failures-only)
51 suites
= defaultdict(Suite
)
53 for test
in json
.load(sys
.stdin
):
54 env
= ' '.join(('%s=%s' % (shlex
.quote(k
), shlex
.quote(v
))
55 for k
, v
in test
['env'].items()))
56 executable
= test
['cmd'][0]
58 executable
= os
.path
.relpath(executable
)
61 if test
['workdir'] is not None:
63 test
['cmd'][0] = os
.path
.relpath(executable
, test
['workdir'])
65 test
['cmd'][0] = executable
67 test
['cmd'][0] = executable
68 cmd
= '$(.test.env) %s %s' % (env
, ' '.join((shlex
.quote(x
) for x
in test
['cmd'])))
69 if test
['workdir'] is not None:
70 cmd
= '(cd %s && %s)' % (shlex
.quote(test
['workdir']), cmd
)
71 driver
= test
['protocol'] if 'protocol' in test
else 'exitcode'
74 print('.test.name.%d := %s' % (i
, test
['name']))
75 print('.test.driver.%d := %s' % (i
, driver
))
76 print('.test.cmd.%d := %s' % (i
, cmd
))
78 test_suites
= test
['suite'] or ['default']
79 is_slow
= any(s
.endswith('-slow') for s
in test_suites
)
81 # The suite name in the introspection info is "PROJECT:SUITE"
83 if s
.endswith('-slow'):
86 suites
[s
].slow_tests
.append(i
)
88 suites
[s
].tests
.append(i
)
89 suites
[s
].executables
.add(executable
)
91 print('.PHONY: check check-report.tap')
93 print('check-report.tap:')
94 print('\t@cat $^ | scripts/tap-merge.pl >$@')
95 for name
, suite
in suites
.items():
96 executables
= ' '.join(suite
.executables
)
97 slow_test_numbers
= ' '.join((str(x
) for x
in suite
.slow_tests
))
98 test_numbers
= ' '.join((str(x
) for x
in suite
.tests
))
99 print('.test.suite-quick.%s := %s' % (name
, test_numbers
))
100 print('.test.suite-slow.%s := $(.test.suite-quick.%s) %s' % (name
, name
, slow_test_numbers
))
101 print('check-build: %s' % executables
)
102 print('.PHONY: check-%s' % name
)
103 print('.PHONY: check-report-%s.tap' % name
)
104 print('check: check-%s' % name
)
105 print('check-%s: all %s' % (name
, executables
))
106 print('\t$(call .test.human, $(.test.suite-$(SPEED).%s))' % (name
, ))
107 print('check-report.tap: check-report-%s.tap' % name
)
108 print('check-report-%s.tap: %s' % (name
, executables
))
109 print('\t$(call .test.tap, $(.test.suite-$(SPEED).%s))' % (name
, ))