@@ -30,7 +30,13 @@ class CPPUnitTests(object):
30
30
TEST_PROC_NO_OUTPUT_TIMEOUT = 300
31
31
32
32
def run_one_test (
33
- self , prog , env , symbols_path = None , interactive = False , timeout_factor = 1
33
+ self ,
34
+ prog ,
35
+ env ,
36
+ symbols_path = None ,
37
+ utility_path = None ,
38
+ interactive = False ,
39
+ timeout_factor = 1 ,
34
40
):
35
41
"""
36
42
Run a single C++ unit test program.
@@ -44,59 +50,65 @@ def run_one_test(
44
50
45
51
Return True if the program exits with a zero status, False otherwise.
46
52
"""
53
+ CPPUnitTests .run_one_test .timed_out = False
54
+ output = []
55
+
56
+ def timeout_handler (proc ):
57
+ CPPUnitTests .run_one_test .timed_out = True
58
+ message = "timed out after %d seconds" % CPPUnitTests .TEST_PROC_TIMEOUT
59
+ self .log .test_end (
60
+ basename , status = "TIMEOUT" , expected = "PASS" , message = message
61
+ )
62
+ mozcrash .kill_and_get_minidump (proc .pid , tempdir , utility_path )
63
+
64
+ def output_timeout_handler (proc ):
65
+ CPPUnitTests .run_one_test .timed_out = True
66
+ message = (
67
+ "timed out after %d seconds without output"
68
+ % CPPUnitTests .TEST_PROC_NO_OUTPUT_TIMEOUT
69
+ )
70
+ self .log .test_end (
71
+ basename , status = "TIMEOUT" , expected = "PASS" , message = message
72
+ )
73
+ mozcrash .kill_and_get_minidump (proc .pid , tempdir , utility_path )
74
+
75
+ def output_line_handler (_ , line ):
76
+ fixed_line = self .fix_stack (line ) if self .fix_stack else line
77
+ if interactive :
78
+ print (fixed_line )
79
+ else :
80
+ output .append (fixed_line )
81
+
47
82
basename = os .path .basename (prog )
48
83
self .log .test_start (basename )
49
84
with mozfile .TemporaryDirectory () as tempdir :
50
- if interactive :
51
- # For tests run locally, via mach, print output directly
52
- proc = mozprocess .ProcessHandler (
53
- [prog ],
54
- cwd = tempdir ,
55
- env = env ,
56
- storeOutput = False ,
57
- universal_newlines = True ,
58
- )
59
- else :
60
- proc = mozprocess .ProcessHandler (
61
- [prog ],
62
- cwd = tempdir ,
63
- env = env ,
64
- storeOutput = True ,
65
- processOutputLine = lambda _ : None ,
66
- universal_newlines = True ,
67
- )
68
- # TODO: After bug 811320 is fixed, don't let .run() kill the process,
69
- # instead use a timeout in .wait() and then kill to get a stack.
70
85
test_timeout = CPPUnitTests .TEST_PROC_TIMEOUT * timeout_factor
71
- proc .run (
86
+ proc = mozprocess .run_and_wait (
87
+ [prog ],
88
+ cwd = tempdir ,
89
+ env = env ,
90
+ output_line_handler = output_line_handler ,
72
91
timeout = test_timeout ,
73
- outputTimeout = CPPUnitTests .TEST_PROC_NO_OUTPUT_TIMEOUT ,
92
+ timeout_handler = timeout_handler ,
93
+ output_timeout = CPPUnitTests .TEST_PROC_NO_OUTPUT_TIMEOUT ,
94
+ output_timeout_handler = output_timeout_handler ,
74
95
)
75
- proc .wait ()
76
- if proc .output :
77
- if self .fix_stack :
78
- procOutput = [self .fix_stack (l ) for l in proc .output ]
79
- else :
80
- procOutput = proc .output
81
-
82
- output = "\n %s" % "\n " .join (procOutput )
96
+
97
+ if output :
98
+ output = "\n %s" % "\n " .join (output )
83
99
self .log .process_output (proc .pid , output , command = [prog ])
84
- if proc .timedOut :
85
- message = "timed out after %d seconds" % CPPUnitTests .TEST_PROC_TIMEOUT
86
- self .log .test_end (
87
- basename , status = "TIMEOUT" , expected = "PASS" , message = message
88
- )
100
+ if CPPUnitTests .run_one_test .timed_out :
89
101
return False
90
102
if mozcrash .check_for_crashes (tempdir , symbols_path , test_name = basename ):
91
103
self .log .test_end (basename , status = "CRASH" , expected = "PASS" )
92
104
return False
93
- result = proc .proc . returncode == 0
105
+ result = proc .returncode == 0
94
106
if not result :
95
107
self .log .test_end (
96
108
basename ,
97
109
status = "FAIL" ,
98
110
expected = "PASS" ,
99
- message = ("test failed with return code %d" % proc .proc . returncode ),
111
+ message = ("test failed with return code %d" % proc .returncode ),
100
112
)
101
113
else :
102
114
self .log .test_end (basename , status = "PASS" , expected = "PASS" )
@@ -201,7 +213,7 @@ def run_tests(
201
213
test_path = prog [0 ]
202
214
timeout_factor = prog [1 ]
203
215
single_result = self .run_one_test (
204
- test_path , env , symbols_path , interactive , timeout_factor
216
+ test_path , env , symbols_path , utility_path , interactive , timeout_factor
205
217
)
206
218
if single_result :
207
219
pass_count += 1
0 commit comments