[lit] Move computation of deadline up into base class

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375171 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/lit/lit/run.py b/utils/lit/lit/run.py
index 7342661..3208db7 100644
--- a/utils/lit/lit/run.py
+++ b/utils/lit/lit/run.py
@@ -11,20 +11,20 @@
     def acquire(self): pass
     def release(self): pass
 
-def create_run(tests, lit_config, workers, progress_callback, max_time):
+def create_run(tests, lit_config, workers, progress_callback, timeout=None):
     # TODO(yln) assert workers > 0
     if workers == 1:
-        return SerialRun(tests, lit_config, progress_callback, max_time)
-    return ParallelRun(tests, lit_config, progress_callback, max_time, workers)
+        return SerialRun(tests, lit_config, progress_callback, timeout)
+    return ParallelRun(tests, lit_config, progress_callback, timeout, workers)
 
 class Run(object):
     """A concrete, configured testing run."""
 
-    def __init__(self, tests, lit_config, progress_callback, max_time):
+    def __init__(self, tests, lit_config, progress_callback, timeout):
         self.tests = tests
         self.lit_config = lit_config
         self.progress_callback = progress_callback
-        self.max_time = max_time
+        self.timeout = timeout
 
     def execute(self):
         """
@@ -35,7 +35,7 @@
 
         The progress_callback will be invoked for each completed test.
 
-        If max_time is non-None, it should be a time in seconds after which to
+        If timeout is non-None, it should be a time in seconds after which to
         stop executing tests.
 
         Returns the elapsed testing time.
@@ -50,8 +50,12 @@
         self.failure_count = 0
         self.hit_max_failures = False
 
+        one_year = 365 * 24 * 60 * 60  # days * hours * minutes * seconds
+        timeout = self.timeout or one_year
+
         start = time.time()
-        self._execute()
+        deadline = start + timeout
+        self._execute(deadline)
         end = time.time()
 
         # Mark any tests that weren't run as UNRESOLVED.
@@ -91,11 +95,11 @@
             self.hit_max_failures = True
 
 class SerialRun(Run):
-    def __init__(self, tests, lit_config, progress_callback, max_time):
-        super(SerialRun, self).__init__(tests, lit_config, progress_callback, max_time)
+    def __init__(self, tests, lit_config, progress_callback, timeout):
+        super(SerialRun, self).__init__(tests, lit_config, progress_callback, timeout)
 
-    def _execute(self):
-        # TODO(yln): ignores max_time
+    def _execute(self, deadline):
+        # TODO(yln): ignores deadline
         for test_index, test in enumerate(self.tests):
             lit.worker._execute_test(test, self.lit_config)
             self._consume_test_result((test_index, test))
@@ -103,15 +107,11 @@
                 break
 
 class ParallelRun(Run):
-    def __init__(self, tests, lit_config, progress_callback, max_time, workers):
-        super(ParallelRun, self).__init__(tests, lit_config, progress_callback, max_time)
+    def __init__(self, tests, lit_config, progress_callback, timeout, workers):
+        super(ParallelRun, self).__init__(tests, lit_config, progress_callback, timeout)
         self.workers = workers
 
-    def _execute(self):
-        one_year = 365 * 24 * 60 * 60  # days * hours * minutes * seconds
-        max_time = self.max_time or one_year
-        deadline = time.time() + max_time
-
+    def _execute(self, deadline):
         semaphores = {
             k: NopSemaphore() if v is None else
             multiprocessing.BoundedSemaphore(v) for k, v in