aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2024-01-19 08:50:05 -0800
committerGitHub <noreply@github.com>2024-01-19 10:50:05 -0600
commitd0d072710468316edbd4130e50f1146c5a6aca89 (patch)
tree919117818cc103762b24a35297bc2fe796b54753 /lldb/packages/Python/lldbsuite/test
parentcebe4de66fb7effa9f8a521c2b9ed2c2b890e5b9 (diff)
downloadllvm-d0d072710468316edbd4130e50f1146c5a6aca89.zip
llvm-d0d072710468316edbd4130e50f1146c5a6aca89.tar.gz
llvm-d0d072710468316edbd4130e50f1146c5a6aca89.tar.bz2
[lldb][test] Apply @expectedFailureAll/@skipIf early for debug_info tests (#73067)
The @expectedFailureAll and @skipIf decorators will mark the test case as xfail/skip if _all_ conditions passed in match, including debug_info. * If debug_info is not one of the matching conditions, we can immediately evaluate the check and decide if it should be decorated. * If debug_info *is* present as a match condition, we need to defer whether or not to decorate until when the `LLDBTestCaseFactory` metaclass expands the test case into its potential variants. This is still early enough that the standard `unittest` framework will recognize the test as xfail/skip by the time the test actually runs. TestDecorators exhibits the edge cases more thoroughly. With the exception of `@expectedFailureIf` (added by this commit), all those test cases pass prior to this commit. This is a followup to 212a60ec37322f853e91e171b305479b1abff2f2.
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/decorators.py53
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbtest.py22
2 files changed, 72 insertions, 3 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index a4cee1f..0fb1469 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -113,6 +113,21 @@ def _compiler_supports(
return True
+def expectedFailureIf(condition, bugnumber=None):
+ def expectedFailure_impl(func):
+ if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+ raise Exception("Decorator can only be used to decorate a test method")
+
+ if condition:
+ return unittest2.expectedFailure(func)
+ return func
+
+ if callable(bugnumber):
+ return expectedFailure_impl(bugnumber)
+ else:
+ return expectedFailure_impl
+
+
def expectedFailureIfFn(expected_fn, bugnumber=None):
def expectedFailure_impl(func):
if isinstance(func, type) and issubclass(func, unittest2.TestCase):
@@ -174,6 +189,34 @@ def skipTestIfFn(expected_fn, bugnumber=None):
return skipTestIfFn_impl
+def _xfailForDebugInfo(expected_fn, bugnumber=None):
+ def expectedFailure_impl(func):
+ if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+ raise Exception("Decorator can only be used to decorate a test method")
+
+ func.__xfail_for_debug_info_cat_fn__ = expected_fn
+ return func
+
+ if callable(bugnumber):
+ return expectedFailure_impl(bugnumber)
+ else:
+ return expectedFailure_impl
+
+
+def _skipForDebugInfo(expected_fn, bugnumber=None):
+ def skipImpl(func):
+ if isinstance(func, type) and issubclass(func, unittest2.TestCase):
+ raise Exception("Decorator can only be used to decorate a test method")
+
+ func.__skip_for_debug_info_cat_fn__ = expected_fn
+ return func
+
+ if callable(bugnumber):
+ return skipImpl(bugnumber)
+ else:
+ return skipImpl
+
+
def _decorateTest(
mode,
bugnumber=None,
@@ -191,7 +234,7 @@ def _decorateTest(
dwarf_version=None,
setting=None,
):
- def fn(self):
+ def fn(actual_debug_info=None):
skip_for_os = _match_decorator_property(
lldbplatform.translate(oslist), lldbplatformutil.getPlatform()
)
@@ -204,7 +247,7 @@ def _decorateTest(
skip_for_arch = _match_decorator_property(
archs, lldbplatformutil.getArchitecture()
)
- skip_for_debug_info = _match_decorator_property(debug_info, self.getDebugInfo())
+ skip_for_debug_info = _match_decorator_property(debug_info, actual_debug_info)
skip_for_triple = _match_decorator_property(
triple, lldb.selected_platform.GetTriple()
)
@@ -279,9 +322,13 @@ def _decorateTest(
return reason_str
if mode == DecorateMode.Skip:
+ if debug_info:
+ return _skipForDebugInfo(fn, bugnumber)
return skipTestIfFn(fn, bugnumber)
elif mode == DecorateMode.Xfail:
- return expectedFailureIfFn(fn, bugnumber)
+ if debug_info:
+ return _xfailForDebugInfo(fn, bugnumber)
+ return expectedFailureIf(fn(), bugnumber)
else:
return None
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index dc4e322..3abc713 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1667,6 +1667,11 @@ class LLDBTestCaseFactory(type):
if original_testcase.NO_DEBUG_INFO_TESTCASE:
return original_testcase
+ # Default implementation for skip/xfail reason based on the debug category,
+ # where "None" means to run the test as usual.
+ def no_reason(_):
+ return None
+
newattrs = {}
for attrname, attrvalue in attrs.items():
if attrname.startswith("test") and not getattr(
@@ -1688,6 +1693,12 @@ class LLDBTestCaseFactory(type):
if can_replicate
]
+ xfail_for_debug_info_cat_fn = getattr(
+ attrvalue, "__xfail_for_debug_info_cat_fn__", no_reason
+ )
+ skip_for_debug_info_cat_fn = getattr(
+ attrvalue, "__skip_for_debug_info_cat_fn__", no_reason
+ )
for cat in categories:
@decorators.add_test_categories([cat])
@@ -1698,6 +1709,17 @@ class LLDBTestCaseFactory(type):
method_name = attrname + "_" + cat
test_method.__name__ = method_name
test_method.debug_info = cat
+
+ xfail_reason = xfail_for_debug_info_cat_fn(cat)
+ if xfail_reason:
+ test_method = unittest2.expectedFailure(xfail_reason)(
+ test_method
+ )
+
+ skip_reason = skip_for_debug_info_cat_fn(cat)
+ if skip_reason:
+ test_method = unittest2.skip(skip_reason)(test_method)
+
newattrs[method_name] = test_method
else: