2015-12-08 09:15:44 +08:00
|
|
|
"""
|
|
|
|
The LLVM Compiler Infrastructure
|
|
|
|
|
|
|
|
This file is distributed under the University of Illinois Open Source
|
|
|
|
License. See LICENSE.TXT for details.
|
|
|
|
|
|
|
|
Provides the LLDBTestResult class, which holds information about progress
|
|
|
|
and results of a single test run.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
# System modules
|
|
|
|
import inspect
|
2016-05-14 08:42:30 +08:00
|
|
|
import os
|
2015-12-08 09:15:44 +08:00
|
|
|
|
|
|
|
# Third-party modules
|
|
|
|
import unittest2
|
|
|
|
|
|
|
|
# LLDB Modules
|
|
|
|
from . import configuration
|
2016-04-21 00:27:27 +08:00
|
|
|
from lldbsuite.test_event.event_builder import EventBuilder
|
2016-05-14 08:42:30 +08:00
|
|
|
from lldbsuite.test_event import build_exception
|
2015-12-08 09:15:44 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
class LLDBTestResult(unittest2.TextTestResult):
|
|
|
|
"""
|
|
|
|
Enforce a singleton pattern to allow introspection of test progress.
|
|
|
|
|
|
|
|
Overwrite addError(), addFailure(), and addExpectedFailure() methods
|
|
|
|
to enable each test instance to track its failure/error status. It
|
|
|
|
is used in the LLDB test framework to emit detailed trace messages
|
|
|
|
to a log file for easier human inspection of test failures/errors.
|
|
|
|
"""
|
|
|
|
__singleton__ = None
|
|
|
|
__ignore_singleton__ = False
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def getTerminalSize():
|
|
|
|
import os
|
|
|
|
env = os.environ
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
def ioctl_GWINSZ(fd):
|
|
|
|
try:
|
2016-09-07 04:57:50 +08:00
|
|
|
import fcntl
|
|
|
|
import termios
|
|
|
|
import struct
|
|
|
|
import os
|
2015-12-08 09:15:44 +08:00
|
|
|
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ,
|
2016-09-07 04:57:50 +08:00
|
|
|
'1234'))
|
2015-12-08 09:15:44 +08:00
|
|
|
except:
|
|
|
|
return
|
|
|
|
return cr
|
|
|
|
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
|
|
|
|
if not cr:
|
|
|
|
try:
|
|
|
|
fd = os.open(os.ctermid(), os.O_RDONLY)
|
|
|
|
cr = ioctl_GWINSZ(fd)
|
|
|
|
os.close(fd)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if not cr:
|
|
|
|
cr = (env.get('LINES', 25), env.get('COLUMNS', 80))
|
|
|
|
return int(cr[1]), int(cr[0])
|
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
if not LLDBTestResult.__ignore_singleton__ and LLDBTestResult.__singleton__:
|
|
|
|
raise Exception("LLDBTestResult instantiated more than once")
|
|
|
|
super(LLDBTestResult, self).__init__(*args)
|
|
|
|
LLDBTestResult.__singleton__ = self
|
|
|
|
# Now put this singleton into the lldb module namespace.
|
|
|
|
configuration.test_result = self
|
|
|
|
# Computes the format string for displaying the counter.
|
|
|
|
counterWidth = len(str(configuration.suite.countTestCases()))
|
|
|
|
self.fmt = "%" + str(counterWidth) + "d: "
|
|
|
|
self.indentation = ' ' * (counterWidth + 2)
|
|
|
|
# This counts from 1 .. suite.countTestCases().
|
|
|
|
self.counter = 0
|
|
|
|
(width, height) = LLDBTestResult.getTerminalSize()
|
|
|
|
self.results_formatter = configuration.results_formatter_object
|
|
|
|
|
|
|
|
def _config_string(self, test):
|
|
|
|
compiler = getattr(test, "getCompiler", None)
|
|
|
|
arch = getattr(test, "getArchitecture", None)
|
2016-09-07 04:57:50 +08:00
|
|
|
return "%s-%s" % (compiler() if compiler else "",
|
|
|
|
arch() if arch else "")
|
2015-12-08 09:15:44 +08:00
|
|
|
|
|
|
|
def _exc_info_to_string(self, err, test):
|
|
|
|
"""Overrides superclass TestResult's method in order to append
|
|
|
|
our test config info string to the exception info string."""
|
|
|
|
if hasattr(test, "getArchitecture") and hasattr(test, "getCompiler"):
|
2016-09-07 04:57:50 +08:00
|
|
|
return '%sConfig=%s-%s' % (super(LLDBTestResult,
|
|
|
|
self)._exc_info_to_string(err,
|
|
|
|
test),
|
|
|
|
test.getArchitecture(),
|
|
|
|
test.getCompiler())
|
2015-12-08 09:15:44 +08:00
|
|
|
else:
|
|
|
|
return super(LLDBTestResult, self)._exc_info_to_string(err, test)
|
|
|
|
|
|
|
|
def getDescription(self, test):
|
|
|
|
doc_first_line = test.shortDescription()
|
|
|
|
if self.descriptions and doc_first_line:
|
|
|
|
return '\n'.join((str(test), self.indentation + doc_first_line))
|
|
|
|
else:
|
|
|
|
return str(test)
|
|
|
|
|
Make test categories composable
Summary:
Previously the add_test_categories would simply overwrite the current set of categories for a
method. This change makes the decorator truly "add" categories, by extending the current set of
categories instead of replacing it.
To do this, I have:
- replaced the getCategories() property on a method (which was itself a method), with a simple
list property "categories". This makes add_test_categories easier to implement, and test
categories isn't something which should change between calls anyway.
- rewritten the getCategoriesForTest function to merge method categories with the categories of
the test case. Previously, it would just use the method categories if they were present. I have
also greatly simplified this method. Originally, it would use a lot of introspection to enable
it being called on various types of objects. Based on my tests, it was only ever being called
on a test case. The new function uses much less introspection then the preivous one, so we
should easily catch any stray uses, if there are any, as they will generate exceptions now.
Reviewers: zturner, tfiala, tberghammer
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D15451
llvm-svn: 255493
2015-12-14 21:17:18 +08:00
|
|
|
def getCategoriesForTest(self, test):
|
|
|
|
"""
|
|
|
|
Gets all the categories for the currently running test method in test case
|
|
|
|
"""
|
|
|
|
test_categories = []
|
|
|
|
test_method = getattr(test, test._testMethodName)
|
2016-09-07 04:57:50 +08:00
|
|
|
if test_method is not None and hasattr(test_method, "categories"):
|
Make test categories composable
Summary:
Previously the add_test_categories would simply overwrite the current set of categories for a
method. This change makes the decorator truly "add" categories, by extending the current set of
categories instead of replacing it.
To do this, I have:
- replaced the getCategories() property on a method (which was itself a method), with a simple
list property "categories". This makes add_test_categories easier to implement, and test
categories isn't something which should change between calls anyway.
- rewritten the getCategoriesForTest function to merge method categories with the categories of
the test case. Previously, it would just use the method categories if they were present. I have
also greatly simplified this method. Originally, it would use a lot of introspection to enable
it being called on various types of objects. Based on my tests, it was only ever being called
on a test case. The new function uses much less introspection then the preivous one, so we
should easily catch any stray uses, if there are any, as they will generate exceptions now.
Reviewers: zturner, tfiala, tberghammer
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D15451
llvm-svn: 255493
2015-12-14 21:17:18 +08:00
|
|
|
test_categories.extend(test_method.categories)
|
|
|
|
|
|
|
|
test_categories.extend(test.getCategories())
|
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
return test_categories
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
def hardMarkAsSkipped(self, test):
|
2015-12-08 09:15:44 +08:00
|
|
|
getattr(test, test._testMethodName).__func__.__unittest_skip__ = True
|
2016-09-07 04:57:50 +08:00
|
|
|
getattr(
|
|
|
|
test,
|
|
|
|
test._testMethodName).__func__.__unittest_skip_why__ = "test case does not fall in any category of interest for this run"
|
2015-12-08 09:15:44 +08:00
|
|
|
|
2016-09-24 05:32:47 +08:00
|
|
|
def checkExclusion(self, exclusion_list, name):
|
|
|
|
if exclusion_list:
|
|
|
|
import re
|
|
|
|
for item in exclusion_list:
|
|
|
|
if re.search(item, name):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
def startTest(self, test):
|
2016-09-07 04:57:50 +08:00
|
|
|
if configuration.shouldSkipBecauseOfCategories(
|
|
|
|
self.getCategoriesForTest(test)):
|
2015-12-08 09:15:44 +08:00
|
|
|
self.hardMarkAsSkipped(test)
|
2016-09-24 05:32:47 +08:00
|
|
|
if self.checkExclusion(
|
2016-10-05 02:48:00 +08:00
|
|
|
configuration.skip_tests, test.id()):
|
2016-09-24 05:32:47 +08:00
|
|
|
self.hardMarkAsSkipped(test)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
configuration.setCrashInfoHook(
|
|
|
|
"%s at %s" %
|
|
|
|
(str(test), inspect.getfile(
|
|
|
|
test.__class__)))
|
2015-12-08 09:15:44 +08:00
|
|
|
self.counter += 1
|
2016-09-07 04:57:50 +08:00
|
|
|
# if self.counter == 4:
|
2015-12-08 09:15:44 +08:00
|
|
|
# import crashinfo
|
|
|
|
# crashinfo.testCrashReporterDescription(None)
|
|
|
|
test.test_number = self.counter
|
|
|
|
if self.showAll:
|
|
|
|
self.stream.write(self.fmt % self.counter)
|
|
|
|
super(LLDBTestResult, self).startTest(test)
|
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_start(test))
|
|
|
|
|
|
|
|
def addSuccess(self, test):
|
2016-09-24 05:32:47 +08:00
|
|
|
if self.checkExclusion(
|
2016-10-05 02:48:00 +08:00
|
|
|
configuration.xfail_tests, test.id()):
|
2016-09-24 05:32:47 +08:00
|
|
|
self.addUnexpectedSuccess(test, None)
|
|
|
|
return
|
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
super(LLDBTestResult, self).addSuccess(test)
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"PASS: LLDB (%s) :: %s\n" %
|
|
|
|
(self._config_string(test), str(test)))
|
2015-12-08 09:15:44 +08:00
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_success(test))
|
|
|
|
|
2016-05-14 08:42:30 +08:00
|
|
|
def _isBuildError(self, err_tuple):
|
|
|
|
exception = err_tuple[1]
|
|
|
|
return isinstance(exception, build_exception.BuildError)
|
|
|
|
|
|
|
|
def _getTestPath(self, test):
|
|
|
|
if test is None:
|
|
|
|
return ""
|
|
|
|
elif hasattr(test, "test_filename"):
|
|
|
|
return test.test_filename
|
|
|
|
else:
|
|
|
|
return inspect.getsourcefile(test.__class__)
|
|
|
|
|
|
|
|
def _saveBuildErrorTuple(self, test, err):
|
|
|
|
# Adjust the error description so it prints the build command and build error
|
|
|
|
# rather than an uninformative Python backtrace.
|
|
|
|
build_error = err[1]
|
|
|
|
error_description = "{}\nTest Directory:\n{}".format(
|
|
|
|
str(build_error),
|
|
|
|
os.path.dirname(self._getTestPath(test)))
|
|
|
|
self.errors.append((test, error_description))
|
|
|
|
self._mirrorOutput = True
|
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
def addError(self, test, err):
|
|
|
|
configuration.sdir_has_content = True
|
2016-05-14 08:42:30 +08:00
|
|
|
if self._isBuildError(err):
|
|
|
|
self._saveBuildErrorTuple(test, err)
|
|
|
|
else:
|
|
|
|
super(LLDBTestResult, self).addError(test, err)
|
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
method = getattr(test, "markError", None)
|
|
|
|
if method:
|
|
|
|
method()
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"FAIL: LLDB (%s) :: %s\n" %
|
|
|
|
(self._config_string(test), str(test)))
|
2015-12-08 09:15:44 +08:00
|
|
|
if self.results_formatter:
|
2016-05-14 08:42:30 +08:00
|
|
|
# Handle build errors as a separate event type
|
|
|
|
if self._isBuildError(err):
|
|
|
|
error_event = EventBuilder.event_for_build_error(test, err)
|
|
|
|
else:
|
|
|
|
error_event = EventBuilder.event_for_error(test, err)
|
|
|
|
self.results_formatter.handle_event(error_event)
|
2015-12-08 09:15:44 +08:00
|
|
|
|
|
|
|
def addCleanupError(self, test, err):
|
|
|
|
configuration.sdir_has_content = True
|
|
|
|
super(LLDBTestResult, self).addCleanupError(test, err)
|
|
|
|
method = getattr(test, "markCleanupError", None)
|
|
|
|
if method:
|
|
|
|
method()
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"CLEANUP ERROR: LLDB (%s) :: %s\n" %
|
|
|
|
(self._config_string(test), str(test)))
|
2015-12-08 09:15:44 +08:00
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_cleanup_error(
|
|
|
|
test, err))
|
|
|
|
|
|
|
|
def addFailure(self, test, err):
|
2016-09-24 05:32:47 +08:00
|
|
|
if self.checkExclusion(
|
2016-10-05 02:48:00 +08:00
|
|
|
configuration.xfail_tests, test.id()):
|
2016-09-24 05:32:47 +08:00
|
|
|
self.addExpectedFailure(test, err, None)
|
|
|
|
return
|
|
|
|
|
2015-12-08 09:15:44 +08:00
|
|
|
configuration.sdir_has_content = True
|
|
|
|
super(LLDBTestResult, self).addFailure(test, err)
|
|
|
|
method = getattr(test, "markFailure", None)
|
|
|
|
if method:
|
|
|
|
method()
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"FAIL: LLDB (%s) :: %s\n" %
|
|
|
|
(self._config_string(test), str(test)))
|
2015-12-08 09:15:44 +08:00
|
|
|
if configuration.useCategories:
|
|
|
|
test_categories = self.getCategoriesForTest(test)
|
|
|
|
for category in test_categories:
|
|
|
|
if category in configuration.failuresPerCategory:
|
2016-09-07 04:57:50 +08:00
|
|
|
configuration.failuresPerCategory[
|
|
|
|
category] = configuration.failuresPerCategory[category] + 1
|
2015-12-08 09:15:44 +08:00
|
|
|
else:
|
|
|
|
configuration.failuresPerCategory[category] = 1
|
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_failure(test, err))
|
|
|
|
|
|
|
|
def addExpectedFailure(self, test, err, bugnumber):
|
|
|
|
configuration.sdir_has_content = True
|
|
|
|
super(LLDBTestResult, self).addExpectedFailure(test, err, bugnumber)
|
|
|
|
method = getattr(test, "markExpectedFailure", None)
|
|
|
|
if method:
|
|
|
|
method(err, bugnumber)
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"XFAIL: LLDB (%s) :: %s\n" %
|
|
|
|
(self._config_string(test), str(test)))
|
2015-12-08 09:15:44 +08:00
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_expected_failure(
|
2016-09-07 04:57:50 +08:00
|
|
|
test, err, bugnumber))
|
2015-12-08 09:15:44 +08:00
|
|
|
|
|
|
|
def addSkip(self, test, reason):
|
|
|
|
configuration.sdir_has_content = True
|
|
|
|
super(LLDBTestResult, self).addSkip(test, reason)
|
|
|
|
method = getattr(test, "markSkippedTest", None)
|
|
|
|
if method:
|
|
|
|
method()
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"UNSUPPORTED: LLDB (%s) :: %s (%s) \n" %
|
|
|
|
(self._config_string(test), str(test), reason))
|
2015-12-08 09:15:44 +08:00
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_skip(test, reason))
|
|
|
|
|
|
|
|
def addUnexpectedSuccess(self, test, bugnumber):
|
|
|
|
configuration.sdir_has_content = True
|
|
|
|
super(LLDBTestResult, self).addUnexpectedSuccess(test, bugnumber)
|
|
|
|
method = getattr(test, "markUnexpectedSuccess", None)
|
|
|
|
if method:
|
|
|
|
method(bugnumber)
|
|
|
|
if configuration.parsable:
|
2016-09-07 04:57:50 +08:00
|
|
|
self.stream.write(
|
|
|
|
"XPASS: LLDB (%s) :: %s\n" %
|
|
|
|
(self._config_string(test), str(test)))
|
2015-12-08 09:15:44 +08:00
|
|
|
if self.results_formatter:
|
|
|
|
self.results_formatter.handle_event(
|
|
|
|
EventBuilder.event_for_unexpected_success(
|
|
|
|
test, bugnumber))
|