[llvm] r375130 - [lit] Move computation of deadline up into base class

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 09:01:21 PDT 2019


Author: yln
Date: Thu Oct 17 09:01:21 2019
New Revision: 375130

URL: http://llvm.org/viewvc/llvm-project?rev=375130&view=rev
Log:
[lit] Move computation of deadline up into base class

Modified:
    llvm/trunk/utils/lit/lit/run.py

Modified: llvm/trunk/utils/lit/lit/run.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/run.py?rev=375130&r1=375129&r2=375130&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/run.py (original)
+++ llvm/trunk/utils/lit/lit/run.py Thu Oct 17 09:01:21 2019
@@ -11,20 +11,20 @@ class NopSemaphore(object):
     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 @@ class Run(object):
 
         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.
@@ -51,7 +51,8 @@ class Run(object):
         self.hit_max_failures = False
 
         start = time.time()
-        self._execute()
+        deadline = (start + self.timeout) if self.timeout else float('inf')
+        self._execute(deadline)
         end = time.time()
 
         # Mark any tests that weren't run as UNRESOLVED.
@@ -91,11 +92,11 @@ class Run(object):
             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,13 +104,11 @@ class SerialRun(Run):
                 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):
-        deadline = (time.time() + self.max_time) if self.max_time else float('inf')
-
+    def _execute(self, deadline):
         semaphores = {
             k: NopSemaphore() if v is None else
             multiprocessing.BoundedSemaphore(v) for k, v in




More information about the llvm-commits mailing list