@@ -11,20 +11,19 @@ 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 , timeout = None ):
15
- # TODO(yln) assert workers > 0
14
+ def create_run (tests , lit_config , workers , progress_callback , max_time ):
16
15
if workers == 1 :
17
- return SerialRun (tests , lit_config , progress_callback , timeout )
18
- return ParallelRun (tests , lit_config , progress_callback , timeout , workers )
16
+ return SerialRun (tests , lit_config , progress_callback , max_time )
17
+ return ParallelRun (tests , lit_config , progress_callback , max_time , workers )
19
18
20
19
class Run (object ):
21
20
"""A concrete, configured testing run."""
22
21
23
- def __init__ (self , tests , lit_config , progress_callback , timeout ):
22
+ def __init__ (self , tests , lit_config , progress_callback , max_time ):
24
23
self .tests = tests
25
24
self .lit_config = lit_config
26
25
self .progress_callback = progress_callback
27
- self .timeout = timeout
26
+ self .max_time = max_time
28
27
29
28
def execute (self ):
30
29
"""
@@ -35,7 +34,7 @@ def execute(self):
35
34
36
35
The progress_callback will be invoked for each completed test.
37
36
38
- If timeout is non-None, it should be a time in seconds after which to
37
+ If max_time is non-None, it should be a time in seconds after which to
39
38
stop executing tests.
40
39
41
40
Returns the elapsed testing time.
@@ -51,8 +50,7 @@ def execute(self):
51
50
self .hit_max_failures = False
52
51
53
52
start = time .time ()
54
- deadline = (start + self .timeout ) if self .timeout else float ('inf' )
55
- self ._execute (deadline )
53
+ self ._execute ()
56
54
end = time .time ()
57
55
58
56
# Mark any tests that weren't run as UNRESOLVED.
@@ -92,23 +90,29 @@ def _consume_test_result(self, pool_result):
92
90
self .hit_max_failures = True
93
91
94
92
class SerialRun (Run ):
95
- def __init__ (self , tests , lit_config , progress_callback , timeout ):
96
- super (SerialRun , self ).__init__ (tests , lit_config , progress_callback , timeout )
93
+ def __init__ (self , tests , lit_config , progress_callback , max_time ):
94
+ super (SerialRun , self ).__init__ (tests , lit_config , progress_callback , max_time )
97
95
98
- def _execute (self , deadline ):
99
- # TODO(yln): ignores deadline
96
+ def _execute (self ):
97
+ # TODO(yln): ignores max_time
100
98
for test_index , test in enumerate (self .tests ):
101
99
lit .worker ._execute_test (test , self .lit_config )
102
100
self ._consume_test_result ((test_index , test ))
103
101
if self .hit_max_failures :
104
102
break
105
103
106
104
class ParallelRun (Run ):
107
- def __init__ (self , tests , lit_config , progress_callback , timeout , workers ):
108
- super (ParallelRun , self ).__init__ (tests , lit_config , progress_callback , timeout )
105
+ def __init__ (self , tests , lit_config , progress_callback , max_time , workers ):
106
+ super (ParallelRun , self ).__init__ (tests , lit_config , progress_callback , max_time )
109
107
self .workers = workers
110
108
111
- def _execute (self , deadline ):
109
+ def _execute (self ):
110
+ # We need to issue many wait calls, so compute the final deadline and
111
+ # subtract time.time() from that as we go along.
112
+ deadline = None
113
+ if self .max_time :
114
+ deadline = time .time () + self .max_time
115
+
112
116
semaphores = {
113
117
k : NopSemaphore () if v is None else
114
118
multiprocessing .BoundedSemaphore (v ) for k , v in
@@ -142,10 +146,15 @@ def console_ctrl_handler(type):
142
146
# Wait for all results to come in. The callback that runs in the
143
147
# parent process will update the display.
144
148
for a in async_results :
145
- timeout = deadline - time .time ()
146
- a .wait (timeout )
149
+ if deadline :
150
+ a .wait (deadline - time .time ())
151
+ else :
152
+ # Python condition variables cannot be interrupted unless
153
+ # they have a timeout. This can make lit unresponsive to
154
+ # KeyboardInterrupt, so do a busy wait with a timeout.
155
+ while not a .ready ():
156
+ a .wait (1 )
147
157
if not a .successful ():
148
- # TODO(yln): this also raises on a --max-time time
149
158
a .get () # Exceptions raised here come from the worker.
150
159
if self .hit_max_failures :
151
160
break
0 commit comments