From 02ae385cac2d68a984723465743c30328051e347 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 21 Aug 2013 22:26:40 +0000 Subject: [PATCH] [lit] Allow formats to return lit.Test.Result instances directly. llvm-svn: 188948 --- llvm/utils/lit/lit/Test.py | 12 ++++++++---- llvm/utils/lit/lit/main.py | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/llvm/utils/lit/lit/Test.py b/llvm/utils/lit/lit/Test.py index d37854ece1d6..c1bacb3d86d1 100644 --- a/llvm/utils/lit/lit/Test.py +++ b/llvm/utils/lit/lit/Test.py @@ -23,7 +23,7 @@ UNSUPPORTED = ResultCode('UNSUPPORTED', False) class Result(object): """Wrapper for the results of executing an individual test.""" - def __init__(self, code, output, elapsed): + def __init__(self, code, output='', elapsed=None): # The result code. self.code = code # The test output. @@ -62,9 +62,13 @@ class Test: # The test result, once complete. self.result = None - def setResult(self, result, output, elapsed): - assert self.result is None, "Test result already set!" - self.result = Result(result, output, elapsed) + def setResult(self, result): + if self.result is not None: + raise ArgumentError("test result already set") + if not isinstance(result, Result): + raise ArgumentError("unexpected result type") + + self.result = result def getFullName(self): return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite) diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 9608803ef718..b84140f90f4a 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -118,8 +118,15 @@ class Tester(threading.Thread): result = None startTime = time.time() try: - result, output = test.config.test_format.execute(test, - self.litConfig) + 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") except KeyboardInterrupt: # This is a sad hack. Unfortunately subprocess goes # bonkers with ctrl-c and we start forking merrily. @@ -128,13 +135,13 @@ class Tester(threading.Thread): except: if self.litConfig.debug: raise - result = lit.Test.UNRESOLVED output = 'Exception during script execution:\n' output += traceback.format_exc() output += '\n' - elapsed = time.time() - startTime + result = lit.Test.Result(lit.Test.UNRESOLVED, output) + result.elapsed = time.time() - startTime - test.setResult(result, output, elapsed) + test.setResult(result) self.display.update(test) def runTests(numThreads, litConfig, provider, display): @@ -382,7 +389,7 @@ def main(builtinParameters = {}): # Update results for any tests which weren't run. for test in tests: if test.result is None: - test.setResult(lit.Test.UNRESOLVED, '', 0.0) + test.setResult(lit.Test.Result(lit.Test.UNRESOLVED, '', 0.0)) # List test results organized by kind. hasFailures = False