18
18
import os , subprocess , shutil , sys , signal
19
19
from io import StringIO
20
20
from ast import literal_eval
21
+ from enum import Enum
21
22
import tempfile
22
23
import mesontest
23
24
from mesonbuild import environment
33
34
34
35
from mesonbuild .coredata import backendlist
35
36
37
+ class BuildStep (Enum ):
38
+ configure = 1
39
+ build = 2
40
+ test = 3
41
+ install = 4
42
+ clean = 5
43
+
36
44
class TestResult :
37
- def __init__ (self , msg , stdo , stde , mlog , conftime = 0 , buildtime = 0 , testtime = 0 ):
45
+ def __init__ (self , msg , step , stdo , stde , mlog , conftime = 0 , buildtime = 0 , testtime = 0 ):
38
46
self .msg = msg
47
+ self .step = step
39
48
self .stdo = stdo
40
49
self .stde = stde
41
50
self .mlog = mlog
@@ -74,6 +83,7 @@ def __exit__(self, _type, value, traceback):
74
83
failing_logs = []
75
84
print_debug = 'MESON_PRINT_TEST_OUTPUT' in os .environ
76
85
do_debug = not {'MESON_PRINT_TEST_OUTPUT' , 'TRAVIS' , 'APPVEYOR' }.isdisjoint (os .environ )
86
+ no_meson_log_msg = 'No meson-log.txt found.'
77
87
78
88
meson_command = os .path .join (os .getcwd (), 'meson' )
79
89
if not os .path .exists (meson_command ):
@@ -270,14 +280,14 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
270
280
with open (logfile , errors = 'ignore' ) as f :
271
281
mesonlog = f .read ()
272
282
except Exception :
273
- mesonlog = 'No meson-log.txt found.'
283
+ mesonlog = no_meson_log_msg
274
284
gen_time = time .time () - gen_start
275
285
if should_fail == 'meson' :
276
286
if returncode != 0 :
277
- return TestResult ('' , stdo , stde , mesonlog , gen_time )
278
- return TestResult ('Test that should have failed succeeded' , stdo , stde , mesonlog , gen_time )
287
+ return TestResult ('' , BuildStep . configure , stdo , stde , mesonlog , gen_time )
288
+ return TestResult ('Test that should have failed succeeded' , BuildStep . configure , stdo , stde , mesonlog , gen_time )
279
289
if returncode != 0 :
280
- return TestResult ('Generating the build system failed.' , stdo , stde , mesonlog , gen_time )
290
+ return TestResult ('Generating the build system failed.' , BuildStep . configure , stdo , stde , mesonlog , gen_time )
281
291
# Build with subprocess
282
292
comp = get_compile_commands_for_dir (compile_commands , test_build_dir )
283
293
build_start = time .time ()
@@ -287,10 +297,10 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
287
297
stde += e
288
298
if should_fail == 'build' :
289
299
if pc .returncode != 0 :
290
- return TestResult ('' , stdo , stde , mesonlog , gen_time )
291
- return TestResult ('Test that should have failed to build succeeded' , stdo , stde , mesonlog , gen_time )
300
+ return TestResult ('' , BuildStep . build , stdo , stde , mesonlog , gen_time )
301
+ return TestResult ('Test that should have failed to build succeeded' , BuildStep . build , stdo , stde , mesonlog , gen_time )
292
302
if pc .returncode != 0 :
293
- return TestResult ('Compiling source code failed.' , stdo , stde , mesonlog , gen_time , build_time )
303
+ return TestResult ('Compiling source code failed.' , BuildStep . build , stdo , stde , mesonlog , gen_time , build_time )
294
304
# Touch the meson.build file to force a regenerate so we can test that
295
305
# regeneration works. We need to sleep for 0.2s because Ninja tracks mtimes
296
306
# at a low resolution: https://github.com/ninja-build/ninja/issues/371
@@ -304,29 +314,29 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
304
314
stde += tstde
305
315
if should_fail == 'test' :
306
316
if returncode != 0 :
307
- return TestResult ('' , stdo , stde , mesonlog , gen_time )
308
- return TestResult ('Test that should have failed to run unit tests succeeded' , stdo , stde , mesonlog , gen_time )
317
+ return TestResult ('' , BuildStep . test , stdo , stde , mesonlog , gen_time )
318
+ return TestResult ('Test that should have failed to run unit tests succeeded' , BuildStep . test , stdo , stde , mesonlog , gen_time )
309
319
if returncode != 0 :
310
- return TestResult ('Running unit tests failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
320
+ return TestResult ('Running unit tests failed.' , BuildStep . test , stdo , stde , mesonlog , gen_time , build_time , test_time )
311
321
if len (install_commands ) == 0 :
312
- return TestResult ('' , '' , '' , gen_time , build_time , test_time )
322
+ return TestResult ('' , BuildStep . install , '' , '' , mesonlog , gen_time , build_time , test_time )
313
323
env = os .environ .copy ()
314
324
env ['DESTDIR' ] = install_dir
315
325
# Install with subprocess
316
326
pi , o , e = Popen_safe (install_commands , cwd = test_build_dir , env = env )
317
327
stdo += o
318
328
stde += e
319
329
if pi .returncode != 0 :
320
- return TestResult ('Running install failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
330
+ return TestResult ('Running install failed.' , BuildStep . install , stdo , stde , mesonlog , gen_time , build_time , test_time )
321
331
if len (clean_commands ) != 0 :
322
332
env = os .environ .copy ()
323
333
# Clean with subprocess
324
334
pi , o , e = Popen_safe (clean_commands , cwd = test_build_dir , env = env )
325
335
stdo += o
326
336
stde += e
327
337
if pi .returncode != 0 :
328
- return TestResult ('Running clean failed.' , stdo , stde , mesonlog , gen_time , build_time , test_time )
329
- return TestResult (validate_install (testdir , install_dir ), stdo , stde , mesonlog , gen_time , build_time , test_time )
338
+ return TestResult ('Running clean failed.' , BuildStep . clean , stdo , stde , mesonlog , gen_time , build_time , test_time )
339
+ return TestResult (validate_install (testdir , install_dir ), BuildStep . clean , stdo , stde , mesonlog , gen_time , build_time , test_time )
330
340
331
341
def gather_tests (testdir ):
332
342
tests = [t .replace ('\\ ' , '/' ).split ('/' , 2 )[2 ] for t in glob (os .path .join (testdir , '*' ))]
@@ -441,10 +451,16 @@ def run_tests(all_tests, log_name_base, extra_args):
441
451
else :
442
452
without_install = "" if len (install_commands ) > 0 else " (without install)"
443
453
if result .msg != '' :
444
- print ('Failed test%s: %s' % (without_install , t ))
454
+ print ('Failed test{} during {}: {!r}' . format (without_install , result . step . name , t ))
445
455
print ('Reason:' , result .msg )
446
456
failing_tests += 1
447
- failing_logs .append (result .stdo )
457
+ if result .step == BuildStep .configure and result .mlog != no_meson_log_msg :
458
+ # For configure failures, instead of printing stdout,
459
+ # print the meson log if available since it's a superset
460
+ # of stdout and often has very useful information.
461
+ failing_logs .append (result .mlog )
462
+ else :
463
+ failing_logs .append (result .stdo )
448
464
failing_logs .append (result .stde )
449
465
else :
450
466
print ('Succeeded test%s: %s' % (without_install , t ))
0 commit comments