@@ -11,17 +11,21 @@ class NopSemaphore(object):
11
11
def acquire (self ): pass
12
12
def release (self ): pass
13
13
14
+ def create_run (tests , lit_config , workers , progress_callback , max_time ):
15
+ if workers == 1 :
16
+ return SerialRun (tests , lit_config , progress_callback , max_time )
17
+ return ParallelRun (tests , lit_config , progress_callback , max_time , workers )
18
+
14
19
class Run (object ):
15
20
"""A concrete, configured testing run."""
16
21
17
- def __init__ (self , tests , lit_config , progress_callback , max_time , workers ):
22
+ def __init__ (self , tests , lit_config , progress_callback , max_time ):
18
23
self .tests = tests
19
24
self .lit_config = lit_config
20
25
self .progress_callback = progress_callback
21
26
self .max_time = max_time
22
- self .workers = workers
23
27
24
- def execute_tests (self ):
28
+ def execute (self ):
25
29
"""
26
30
Execute the tests in the run using up to the specified number of
27
31
parallel tasks, and inform the caller of each individual result. The
@@ -46,12 +50,7 @@ def execute_tests(self):
46
50
self .hit_max_failures = False
47
51
48
52
start = time .time ()
49
-
50
- if self .workers == 1 :
51
- self ._execute_in_serial ()
52
- else :
53
- self ._execute_in_parallel ()
54
-
53
+ self ._execute ()
55
54
end = time .time ()
56
55
57
56
# Mark any tests that weren't run as UNRESOLVED.
@@ -61,15 +60,53 @@ def execute_tests(self):
61
60
62
61
return end - start
63
62
64
- def _execute_in_serial (self ):
63
+ def _consume_test_result (self , pool_result ):
64
+ """Test completion callback for lit.worker.run_one_test
65
+
66
+ Updates the test result status in the parent process. Each task in the
67
+ pool returns the test index and the result, and we use the index to look
68
+ up the original test object. Also updates the progress bar as tasks
69
+ complete.
70
+ """
71
+ # Don't add any more test results after we've hit the maximum failure
72
+ # count. Otherwise we're racing with the main thread, which is going
73
+ # to terminate the process pool soon.
74
+ if self .hit_max_failures :
75
+ return
76
+
77
+ (test_index , test_with_result ) = pool_result
78
+ # Update the parent process copy of the test. This includes the result,
79
+ # XFAILS, REQUIRES, and UNSUPPORTED statuses.
80
+ assert self .tests [test_index ].file_path == test_with_result .file_path , \
81
+ "parent and child disagree on test path"
82
+ self .tests [test_index ] = test_with_result
83
+ self .progress_callback (test_with_result )
84
+
85
+ # If we've finished all the tests or too many tests have failed, notify
86
+ # the main thread that we've stopped testing.
87
+ self .failure_count += (test_with_result .result .code == lit .Test .FAIL )
88
+ if self .lit_config .maxFailures and \
89
+ self .failure_count == self .lit_config .maxFailures :
90
+ self .hit_max_failures = True
91
+
92
+ class SerialRun (Run ):
93
+ def __init__ (self , tests , lit_config , progress_callback , max_time ):
94
+ super (SerialRun , self ).__init__ (tests , lit_config , progress_callback , max_time )
95
+
96
+ def _execute (self ):
65
97
# TODO(yln): ignores max_time
66
98
for test_index , test in enumerate (self .tests ):
67
99
lit .worker ._execute_test (test , self .lit_config )
68
100
self ._consume_test_result ((test_index , test ))
69
101
if self .hit_max_failures :
70
102
break
71
103
72
- def _execute_in_parallel (self ):
104
+ class ParallelRun (Run ):
105
+ def __init__ (self , tests , lit_config , progress_callback , max_time , workers ):
106
+ super (ParallelRun , self ).__init__ (tests , lit_config , progress_callback , max_time )
107
+ self .workers = workers
108
+
109
+ def _execute (self ):
73
110
# We need to issue many wait calls, so compute the final deadline and
74
111
# subtract time.time() from that as we go along.
75
112
deadline = None
@@ -128,32 +165,3 @@ def console_ctrl_handler(type):
128
165
raise
129
166
finally :
130
167
pool .join ()
131
-
132
- def _consume_test_result (self , pool_result ):
133
- """Test completion callback for lit.worker.run_one_test
134
-
135
- Updates the test result status in the parent process. Each task in the
136
- pool returns the test index and the result, and we use the index to look
137
- up the original test object. Also updates the progress bar as tasks
138
- complete.
139
- """
140
- # Don't add any more test results after we've hit the maximum failure
141
- # count. Otherwise we're racing with the main thread, which is going
142
- # to terminate the process pool soon.
143
- if self .hit_max_failures :
144
- return
145
-
146
- (test_index , test_with_result ) = pool_result
147
- # Update the parent process copy of the test. This includes the result,
148
- # XFAILS, REQUIRES, and UNSUPPORTED statuses.
149
- assert self .tests [test_index ].file_path == test_with_result .file_path , \
150
- "parent and child disagree on test path"
151
- self .tests [test_index ] = test_with_result
152
- self .progress_callback (test_with_result )
153
-
154
- # If we've finished all the tests or too many tests have failed, notify
155
- # the main thread that we've stopped testing.
156
- self .failure_count += (test_with_result .result .code == lit .Test .FAIL )
157
- if self .lit_config .maxFailures and \
158
- self .failure_count == self .lit_config .maxFailures :
159
- self .hit_max_failures = True
0 commit comments