From 8c59003cc382e4b2fb15b267aa2d356e869a89cc Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 29 Aug 2013 00:48:55 +0000 Subject: [PATCH] [lit] Move top-level execute code into Run object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189551 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lit/lit/LitTestCase.py | 18 ++++++------------ utils/lit/lit/discovery.py | 7 +++++-- utils/lit/lit/main.py | 34 +++++++--------------------------- utils/lit/lit/run.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/utils/lit/lit/LitTestCase.py b/utils/lit/lit/LitTestCase.py index ba91fa08a01..e04846c7bd6 100644 --- a/utils/lit/lit/LitTestCase.py +++ b/utils/lit/lit/LitTestCase.py @@ -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: diff --git a/utils/lit/lit/discovery.py b/utils/lit/lit/discovery.py index 26882fe8ce5..263e54694ca 100644 --- a/utils/lit/lit/discovery.py +++ b/utils/lit/lit/discovery.py @@ -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]) diff --git a/utils/lit/lit/main.py b/utils/lit/lit/main.py index 76259599aca..1480a7a74fd 100755 --- a/utils/lit/lit/main.py +++ b/utils/lit/lit/main.py @@ -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: diff --git a/utils/lit/lit/run.py b/utils/lit/lit/run.py index 8a9f87b2014..44666679a60 100644 --- a/utils/lit/lit/run.py +++ b/utils/lit/lit/run.py @@ -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)