Skip to content

Commit a660dc5

Browse files
committed
[lit] Move computation of deadline up into base class
llvm-svn: 375130
1 parent aa05e0e commit a660dc5

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

llvm/utils/lit/lit/run.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ class NopSemaphore(object):
1111
def acquire(self): pass
1212
def release(self): pass
1313

14-
def create_run(tests, lit_config, workers, progress_callback, max_time):
14+
def create_run(tests, lit_config, workers, progress_callback, timeout=None):
1515
# TODO(yln) assert workers > 0
1616
if workers == 1:
17-
return SerialRun(tests, lit_config, progress_callback, max_time)
18-
return ParallelRun(tests, lit_config, progress_callback, max_time, workers)
17+
return SerialRun(tests, lit_config, progress_callback, timeout)
18+
return ParallelRun(tests, lit_config, progress_callback, timeout, workers)
1919

2020
class Run(object):
2121
"""A concrete, configured testing run."""
2222

23-
def __init__(self, tests, lit_config, progress_callback, max_time):
23+
def __init__(self, tests, lit_config, progress_callback, timeout):
2424
self.tests = tests
2525
self.lit_config = lit_config
2626
self.progress_callback = progress_callback
27-
self.max_time = max_time
27+
self.timeout = timeout
2828

2929
def execute(self):
3030
"""
@@ -35,7 +35,7 @@ def execute(self):
3535
3636
The progress_callback will be invoked for each completed test.
3737
38-
If max_time is non-None, it should be a time in seconds after which to
38+
If timeout is non-None, it should be a time in seconds after which to
3939
stop executing tests.
4040
4141
Returns the elapsed testing time.
@@ -51,7 +51,8 @@ def execute(self):
5151
self.hit_max_failures = False
5252

5353
start = time.time()
54-
self._execute()
54+
deadline = (start + self.timeout) if self.timeout else float('inf')
55+
self._execute(deadline)
5556
end = time.time()
5657

5758
# Mark any tests that weren't run as UNRESOLVED.
@@ -91,25 +92,23 @@ def _consume_test_result(self, pool_result):
9192
self.hit_max_failures = True
9293

9394
class SerialRun(Run):
94-
def __init__(self, tests, lit_config, progress_callback, max_time):
95-
super(SerialRun, self).__init__(tests, lit_config, progress_callback, max_time)
95+
def __init__(self, tests, lit_config, progress_callback, timeout):
96+
super(SerialRun, self).__init__(tests, lit_config, progress_callback, timeout)
9697

97-
def _execute(self):
98-
# TODO(yln): ignores max_time
98+
def _execute(self, deadline):
99+
# TODO(yln): ignores deadline
99100
for test_index, test in enumerate(self.tests):
100101
lit.worker._execute_test(test, self.lit_config)
101102
self._consume_test_result((test_index, test))
102103
if self.hit_max_failures:
103104
break
104105

105106
class ParallelRun(Run):
106-
def __init__(self, tests, lit_config, progress_callback, max_time, workers):
107-
super(ParallelRun, self).__init__(tests, lit_config, progress_callback, max_time)
107+
def __init__(self, tests, lit_config, progress_callback, timeout, workers):
108+
super(ParallelRun, self).__init__(tests, lit_config, progress_callback, timeout)
108109
self.workers = workers
109110

110-
def _execute(self):
111-
deadline = (time.time() + self.max_time) if self.max_time else float('inf')
112-
111+
def _execute(self, deadline):
113112
semaphores = {
114113
k: NopSemaphore() if v is None else
115114
multiprocessing.BoundedSemaphore(v) for k, v in

0 commit comments

Comments
 (0)