[lit] Move top-level execute code into Run object.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 29 Aug 2013 00:48:55 +0000 (00:48 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 29 Aug 2013 00:48:55 +0000 (00:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189551 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/LitTestCase.py
utils/lit/lit/discovery.py
utils/lit/lit/main.py
utils/lit/lit/run.py

index ba91fa08a0192ca42bc4ab009b4eb84341710a14..e04846c7bd6a49b7e6ad20f7cff5096142dba333 100644 (file)
@@ -11,10 +11,10 @@ class UnresolvedError(RuntimeError):
     pass
         
 class LitTestCase(unittest.TestCase):
-    def __init__(self, test, lit_config):
+    def __init__(self, test, run):
         unittest.TestCase.__init__(self)
         self._test = test
-        self._lit_config = lit_config
+        self._run = run
 
     def id(self):
         return self._test.getFullName()
@@ -23,17 +23,11 @@ class LitTestCase(unittest.TestCase):
         return self._test.getFullName()
 
     def runTest(self):
-        result = self._test.config.test_format.execute(
-            self._test, self._lit_config)
-
-        # Support deprecated result from execute() which returned the result
-        # code and additional output as a tuple.
-        if isinstance(result, tuple):
-            code, output = result
-            result = lit.Test.Result(code, output)
-        elif not isinstance(result, lit.Test.Result):
-            raise ValueError("unexpected result from test execution")
+        # Run the test.
+        self._run.execute_test(self._test)
 
+        # Adapt the result to unittest.
+        result = self._test.result
         if result.code is lit.Test.UNRESOLVED:
             raise UnresolvedError(result.output)
         elif result.code.isFailure:
index 26882fe8ce54e23c2b24583af8200f6b1627fa85..263e54694caf6f962b8224238332b3472ea47f39 100644 (file)
@@ -5,6 +5,7 @@ Test discovery functions.
 import os
 import sys
 
+import lit.run
 from lit.TestingConfig import TestingConfig
 from lit import LitConfig, Test
 
@@ -245,7 +246,9 @@ def load_test_suite(inputs):
                                     isWindows = (platform.system()=='Windows'),
                                     params = {})
 
-    tests = find_tests_for_inputs(litConfig, inputs)
+    # Perform test discovery.
+    run = lit.run.Run(litConfig, find_tests_for_inputs(litConfig, inputs))
 
     # Return a unittest test suite which just runs the tests in order.
-    return unittest.TestSuite([LitTestCase(test, litConfig) for test in tests])
+    return unittest.TestSuite([LitTestCase(test, run)
+                               for test in run.tests])
index 76259599acaf29454aa165e616c7486f39fa12b7..1480a7a74fd5e59b004a251375a7247d0a590ca1 100755 (executable)
@@ -102,9 +102,9 @@ class TestProvider:
         return item
 
 class Tester(threading.Thread):
-    def __init__(self, litConfig, provider, display):
+    def __init__(self, run_instance, provider, display):
         threading.Thread.__init__(self)
-        self.litConfig = litConfig
+        self.run_instance = run_instance
         self.provider = provider
         self.display = display
 
@@ -116,45 +116,25 @@ class Tester(threading.Thread):
             self.runTest(item)
 
     def runTest(self, test):
-        result = None
-        startTime = time.time()
         try:
-            result = test.config.test_format.execute(test, self.litConfig)
-
-            # Support deprecated result from execute() which returned the result
-            # code and additional output as a tuple.
-            if isinstance(result, tuple):
-                code, output = result
-                result = lit.Test.Result(code, output)
-            elif not isinstance(result, lit.Test.Result):
-                raise ValueError("unexpected result from test execution")
+            self.run_instance.execute_test(test)
         except KeyboardInterrupt:
             # This is a sad hack. Unfortunately subprocess goes
             # bonkers with ctrl-c and we start forking merrily.
             print('\nCtrl-C detected, goodbye.')
             os.kill(0,9)
-        except:
-            if self.litConfig.debug:
-                raise
-            output = 'Exception during script execution:\n'
-            output += traceback.format_exc()
-            output += '\n'
-            result = lit.Test.Result(lit.Test.UNRESOLVED, output)
-        result.elapsed = time.time() - startTime
-
-        test.setResult(result)
         self.display.update(test)
 
-def runTests(numThreads, litConfig, provider, display):
+def runTests(numThreads, run, provider, display):
     # If only using one testing thread, don't use threads at all; this lets us
     # profile, among other things.
     if numThreads == 1:
-        t = Tester(litConfig, provider, display)
+        t = Tester(run, provider, display)
         t.run()
         return
 
     # Otherwise spin up the testing threads and wait for them to finish.
-    testers = [Tester(litConfig, provider, display)
+    testers = [Tester(run, provider, display)
                for i in range(numThreads)]
     for t in testers:
         t.start()
@@ -383,7 +363,7 @@ def main(builtinParameters = {}):
         return True
       win32api.SetConsoleCtrlHandler(console_ctrl_handler, True)
 
-    runTests(opts.numThreads, litConfig, provider, display)
+    runTests(opts.numThreads, run, provider, display)
     display.finish()
 
     if not opts.quiet:
index 8a9f87b2014ed3b9402768359f69a0c845c252c2..44666679a60bb7dc427721dfd7ea58fc03b79993 100644 (file)
@@ -1,3 +1,8 @@
+import time
+import traceback
+
+import lit.Test
+
 class Run(object):
     """
     This class represents a concrete, configured testing run.
@@ -6,3 +11,29 @@ class Run(object):
     def __init__(self, lit_config, tests):
         self.lit_config = lit_config
         self.tests = tests
+
+    def execute_test(self, test):
+        result = None
+        startTime = time.time()
+        try:
+            result = test.config.test_format.execute(test, self.lit_config)
+
+            # Support deprecated result from execute() which returned the result
+            # code and additional output as a tuple.
+            if isinstance(result, tuple):
+                code, output = result
+                result = lit.Test.Result(code, output)
+            elif not isinstance(result, lit.Test.Result):
+                raise ValueError("unexpected result from test execution")
+        except KeyboardInterrupt:
+            raise
+        except:
+            if self.lit_config.debug:
+                raise
+            output = 'Exception during script execution:\n'
+            output += traceback.format_exc()
+            output += '\n'
+            result = lit.Test.Result(lit.Test.UNRESOLVED, output)
+        result.elapsed = time.time() - startTime
+
+        test.setResult(result)