Skip to content

Commit c854ae1

Browse files
committed
run_project_tests.py: Also do ninja clean on tests
This will catch things like #1220
1 parent 7d71e9f commit c854ae1

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

run_project_tests.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from mesonbuild import mesonlib
2525
from mesonbuild import mlog
2626
from mesonbuild import mesonmain
27-
from mesonbuild.mesonlib import stringlistify
27+
from mesonbuild.mesonlib import stringlistify, Popen_safe
2828
import argparse
2929
import xml.etree.ElementTree as ET
3030
import time
@@ -93,26 +93,20 @@ def stop_handler(signal, frame):
9393
backend_flags = None
9494
compile_commands = None
9595
test_commands = None
96-
install_commands = None
96+
install_commands = []
97+
clean_commands = []
9798

9899
def setup_commands(backend):
99-
global backend_flags, compile_commands, test_commands, install_commands
100+
global backend_flags, compile_commands, test_commands, install_commands, clean_commands
100101
msbuild_exe = shutil.which('msbuild')
101-
if backend == 'vs2010' or (backend is None and msbuild_exe is not None):
102-
backend_flags = ['--backend=vs2010']
102+
if (backend and backend.startswith('vs')) or (backend is None and msbuild_exe is not None):
103+
backend_flags = ['--backend=' + backend]
103104
compile_commands = ['msbuild']
104105
test_commands = ['msbuild', 'RUN_TESTS.vcxproj']
105-
install_commands = []
106-
elif backend == 'vs2015':
107-
backend_flags = ['--backend=vs2015']
108-
compile_commands = ['msbuild']
109-
test_commands = ['msbuild', 'RUN_TESTS.vcxproj']
110-
install_commands = []
111106
elif backend == 'xcode' or (backend is None and mesonlib.is_osx()):
112107
backend_flags = ['--backend=xcode']
113108
compile_commands = ['xcodebuild']
114109
test_commands = ['xcodebuild', '-target', 'RUN_TESTS']
115-
install_commands = []
116110
else:
117111
backend_flags = []
118112
ninja_command = environment.detect_ninja()
@@ -125,6 +119,7 @@ def setup_commands(backend):
125119
compile_commands += ['-w', 'dupbuild=err']
126120
test_commands = [ninja_command, 'test', 'benchmark']
127121
install_commands = [ninja_command, 'install']
122+
clean_commands = [ninja_command, 'clean']
128123

129124
def get_relative_files_list_from_dir(fromdir):
130125
paths = []
@@ -233,17 +228,18 @@ def parse_test_args(testdir):
233228
pass
234229
return args
235230

236-
def run_test(skipped, testdir, extra_args, flags, compile_commands, install_commands, should_fail):
231+
def run_test(skipped, testdir, extra_args, flags, compile_commands, should_fail):
237232
if skipped:
238233
return None
239234
with AutoDeletedDir(tempfile.mkdtemp(prefix='b ', dir='.')) as build_dir:
240235
with AutoDeletedDir(tempfile.mkdtemp(prefix='i ', dir=os.getcwd())) as install_dir:
241236
try:
242-
return _run_test(testdir, build_dir, install_dir, extra_args, flags, compile_commands, install_commands, should_fail)
237+
return _run_test(testdir, build_dir, install_dir, extra_args, flags, compile_commands, should_fail)
243238
finally:
244239
mlog.shutdown() # Close the log file because otherwise Windows wets itself.
245240

246-
def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_commands, install_commands, should_fail):
241+
def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_commands, should_fail):
242+
global install_commands, clean_commands
247243
test_args = parse_test_args(testdir)
248244
gen_start = time.time()
249245
gen_command = [meson_command, '--prefix', '/usr', '--libdir', 'lib', testdir, test_build_dir]\
@@ -268,12 +264,10 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
268264
else:
269265
comp = compile_commands
270266
build_start = time.time()
271-
pc = subprocess.Popen(comp, cwd=test_build_dir,
272-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
273-
(o, e) = pc.communicate()
267+
pc, o, e = Popen_safe(comp, cwd=test_build_dir)
274268
build_time = time.time() - build_start
275-
stdo += o.decode(sys.stdout.encoding)
276-
stde += e.decode(sys.stdout.encoding)
269+
stdo += o
270+
stde += e
277271
if should_fail == 'build':
278272
if pc.returncode != 0:
279273
return TestResult('', stdo, stde, mesonlog, gen_time)
@@ -294,19 +288,24 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
294288
return TestResult('Test that should have failed to run unit tests succeeded', stdo, stde, mesonlog, gen_time)
295289
if returncode != 0:
296290
return TestResult('Running unit tests failed.', stdo, stde, mesonlog, gen_time, build_time, test_time)
291+
# Do installation
297292
if len(install_commands) == 0:
298293
return TestResult('', '', '', gen_time, build_time, test_time)
299-
else:
294+
env = os.environ.copy()
295+
env['DESTDIR'] = install_dir
296+
pi, o, e = Popen_safe(install_commands, cwd=test_build_dir, env=env)
297+
stdo += o
298+
stde += e
299+
if pi.returncode != 0:
300+
return TestResult('Running install failed.', stdo, stde, mesonlog, gen_time, build_time, test_time)
301+
if len(clean_commands) != 0:
300302
env = os.environ.copy()
301-
env['DESTDIR'] = install_dir
302-
pi = subprocess.Popen(install_commands, cwd=test_build_dir, env=env,
303-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
304-
(o, e) = pi.communicate()
305-
stdo += o.decode(sys.stdout.encoding)
306-
stde += e.decode(sys.stdout.encoding)
303+
pi, o, e = Popen_safe(clean_commands, cwd=test_build_dir, env=env)
304+
stdo += o
305+
stde += e
307306
if pi.returncode != 0:
308-
return TestResult('Running install failed.', stdo, stde, mesonlog, gen_time, build_time, test_time)
309-
return TestResult(validate_install(testdir, install_dir), stdo, stde, mesonlog, gen_time, build_time, test_time)
307+
return TestResult('Running clean failed.', stdo, stde, mesonlog, gen_time, build_time, test_time)
308+
return TestResult(validate_install(testdir, install_dir), stdo, stde, mesonlog, gen_time, build_time, test_time)
310309

311310
def gather_tests(testdir):
312311
tests = [t.replace('\\', '/').split('/', 2)[2] for t in glob(os.path.join(testdir, '*'))]
@@ -372,7 +371,7 @@ def detect_tests_to_run():
372371
return all_tests
373372

374373
def run_tests(extra_args):
375-
global passing_tests, failing_tests, stop, executor, futures
374+
global install_commands, passing_tests, failing_tests, stop, executor, futures
376375
all_tests = detect_tests_to_run()
377376
logfile = open('meson-test-run.txt', 'w', encoding="utf_8")
378377
junit_root = ET.Element('testsuites')
@@ -404,7 +403,7 @@ def run_tests(extra_args):
404403
should_fail = False
405404
if name.startswith('failing'):
406405
should_fail = name.split('failing-')[1]
407-
result = executor.submit(run_test, skipped, t, extra_args, unity_flags + backend_flags, compile_commands, install_commands, should_fail)
406+
result = executor.submit(run_test, skipped, t, extra_args, unity_flags + backend_flags, compile_commands, should_fail)
408407
futures.append((testname, t, result))
409408
for (testname, t, result) in futures:
410409
result = result.result()

0 commit comments

Comments
 (0)