[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
This commit is contained in:
Daniel Dunbar 2013-08-29 00:48:55 +00:00
parent 5b2efc28fd
commit 8c59003cc3
4 changed files with 49 additions and 41 deletions

View 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:

View 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])

View File

@ -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:

View 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)