mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 00:21:03 +00:00
[lit] Factor out a separate Test.Result() object.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2,7 +2,9 @@ import os
|
|||||||
|
|
||||||
# Test results.
|
# Test results.
|
||||||
|
|
||||||
class TestResult:
|
class ResultCode(object):
|
||||||
|
"""Test result codes."""
|
||||||
|
|
||||||
def __init__(self, name, isFailure):
|
def __init__(self, name, isFailure):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.isFailure = isFailure
|
self.isFailure = isFailure
|
||||||
@@ -11,12 +13,23 @@ class TestResult:
|
|||||||
return '%s%r' % (self.__class__.__name__,
|
return '%s%r' % (self.__class__.__name__,
|
||||||
(self.name, self.isFailure))
|
(self.name, self.isFailure))
|
||||||
|
|
||||||
PASS = TestResult('PASS', False)
|
PASS = ResultCode('PASS', False)
|
||||||
XFAIL = TestResult('XFAIL', False)
|
XFAIL = ResultCode('XFAIL', False)
|
||||||
FAIL = TestResult('FAIL', True)
|
FAIL = ResultCode('FAIL', True)
|
||||||
XPASS = TestResult('XPASS', True)
|
XPASS = ResultCode('XPASS', True)
|
||||||
UNRESOLVED = TestResult('UNRESOLVED', True)
|
UNRESOLVED = ResultCode('UNRESOLVED', True)
|
||||||
UNSUPPORTED = TestResult('UNSUPPORTED', False)
|
UNSUPPORTED = ResultCode('UNSUPPORTED', False)
|
||||||
|
|
||||||
|
class Result(object):
|
||||||
|
"""Wrapper for the results of executing an individual test."""
|
||||||
|
|
||||||
|
def __init__(self, code, output, elapsed):
|
||||||
|
# The result code.
|
||||||
|
self.code = code
|
||||||
|
# The test output.
|
||||||
|
self.output = output
|
||||||
|
# The wall timing to execute the test, if timing.
|
||||||
|
self.elapsed = elapsed
|
||||||
|
|
||||||
# Test classes.
|
# Test classes.
|
||||||
|
|
||||||
@@ -46,18 +59,12 @@ class Test:
|
|||||||
self.suite = suite
|
self.suite = suite
|
||||||
self.path_in_suite = path_in_suite
|
self.path_in_suite = path_in_suite
|
||||||
self.config = config
|
self.config = config
|
||||||
# The test result code, once complete.
|
# The test result, once complete.
|
||||||
self.result = None
|
self.result = None
|
||||||
# Any additional output from the test, once complete.
|
|
||||||
self.output = None
|
|
||||||
# The wall time to execute this test, if timing and once complete.
|
|
||||||
self.elapsed = None
|
|
||||||
|
|
||||||
def setResult(self, result, output, elapsed):
|
def setResult(self, result, output, elapsed):
|
||||||
assert self.result is None, "Test result already set!"
|
assert self.result is None, "Test result already set!"
|
||||||
self.result = result
|
self.result = Result(result, output, elapsed)
|
||||||
self.output = output
|
|
||||||
self.elapsed = elapsed
|
|
||||||
|
|
||||||
def getFullName(self):
|
def getFullName(self):
|
||||||
return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite)
|
return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite)
|
||||||
|
@@ -27,7 +27,7 @@ class TestingProgressDisplay:
|
|||||||
|
|
||||||
def update(self, test):
|
def update(self, test):
|
||||||
# Avoid locking overhead in quiet mode
|
# Avoid locking overhead in quiet mode
|
||||||
if self.opts.quiet and not test.result.isFailure:
|
if self.opts.quiet and not test.result.code.isFailure:
|
||||||
self.completed += 1
|
self.completed += 1
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -52,19 +52,19 @@ class TestingProgressDisplay:
|
|||||||
self.progressBar.update(float(self.completed)/self.numTests,
|
self.progressBar.update(float(self.completed)/self.numTests,
|
||||||
test.getFullName())
|
test.getFullName())
|
||||||
|
|
||||||
if self.opts.succinct and not test.result.isFailure:
|
if self.opts.succinct and not test.result.code.isFailure:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.progressBar:
|
if self.progressBar:
|
||||||
self.progressBar.clear()
|
self.progressBar.clear()
|
||||||
|
|
||||||
print('%s: %s (%d of %d)' % (test.result.name, test.getFullName(),
|
print('%s: %s (%d of %d)' % (test.result.code.name, test.getFullName(),
|
||||||
self.completed, self.numTests))
|
self.completed, self.numTests))
|
||||||
|
|
||||||
if test.result.isFailure and self.opts.showOutput:
|
if test.result.code.isFailure and self.opts.showOutput:
|
||||||
print("%s TEST '%s' FAILED %s" % ('*'*20, test.getFullName(),
|
print("%s TEST '%s' FAILED %s" % ('*'*20, test.getFullName(),
|
||||||
'*'*20))
|
'*'*20))
|
||||||
print(test.output)
|
print(test.result.output)
|
||||||
print("*" * 20)
|
print("*" * 20)
|
||||||
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@@ -380,18 +380,18 @@ def main(builtinParameters = {}):
|
|||||||
print('Testing Time: %.2fs'%(time.time() - startTime))
|
print('Testing Time: %.2fs'%(time.time() - startTime))
|
||||||
|
|
||||||
# Update results for any tests which weren't run.
|
# Update results for any tests which weren't run.
|
||||||
for t in tests:
|
for test in tests:
|
||||||
if t.result is None:
|
if test.result is None:
|
||||||
t.setResult(lit.Test.UNRESOLVED, '', 0.0)
|
test.setResult(lit.Test.UNRESOLVED, '', 0.0)
|
||||||
|
|
||||||
# List test results organized by kind.
|
# List test results organized by kind.
|
||||||
hasFailures = False
|
hasFailures = False
|
||||||
byCode = {}
|
byCode = {}
|
||||||
for t in tests:
|
for test in tests:
|
||||||
if t.result not in byCode:
|
if test.result.code not in byCode:
|
||||||
byCode[t.result] = []
|
byCode[test.result.code] = []
|
||||||
byCode[t.result].append(t)
|
byCode[test.result.code].append(test)
|
||||||
if t.result.isFailure:
|
if test.result.code.isFailure:
|
||||||
hasFailures = True
|
hasFailures = True
|
||||||
|
|
||||||
# Print each test in any of the failing groups.
|
# Print each test in any of the failing groups.
|
||||||
@@ -403,16 +403,16 @@ def main(builtinParameters = {}):
|
|||||||
continue
|
continue
|
||||||
print('*'*20)
|
print('*'*20)
|
||||||
print('%s (%d):' % (title, len(elts)))
|
print('%s (%d):' % (title, len(elts)))
|
||||||
for t in elts:
|
for test in elts:
|
||||||
print(' %s' % t.getFullName())
|
print(' %s' % test.getFullName())
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
|
|
||||||
if opts.timeTests and tests:
|
if opts.timeTests and tests:
|
||||||
# Order by time.
|
# Order by time.
|
||||||
test_times = [(t.getFullName(), t.elapsed)
|
test_times = [(test.getFullName(), test.result.elapsed)
|
||||||
for t in tests]
|
for test in tests]
|
||||||
lit.util.printHistogram(test_times, title='Tests')
|
lit.util.printHistogram(test_times, title='Tests')
|
||||||
|
|
||||||
for name,code in (('Expected Passes ', lit.Test.PASS),
|
for name,code in (('Expected Passes ', lit.Test.PASS),
|
||||||
('Expected Failures ', lit.Test.XFAIL),
|
('Expected Failures ', lit.Test.XFAIL),
|
||||||
('Unsupported Tests ', lit.Test.UNSUPPORTED),
|
('Unsupported Tests ', lit.Test.UNSUPPORTED),
|
||||||
|
Reference in New Issue
Block a user