Skip to content

Commit 0fc5786

Browse files
authored
[lldb][test] Remove expectedFailureIfFn (#81703)
Switching to modern `unittest` in 5b38615 needs xfail annotations to be known prior to test running. In contrast, skipping can happen at any time, even during test execution. Thus, `expectedFailureIfFn` inherently doesn't work. Either we eagerly evaluate the function and use `expectedFailureIf` instead, or we use a skip annotation to lazily evaluate the function and potentially skip the test right before it starts. - For `expectedFailureAndroid`, the intent seems to be that certain tests _should_ work on android, but don't. Thus, xfail is appropriate, to ensure the test is re-enabled once those bugs are ever fixed. - For the other uses in individual tests, those generally seem to be cases where the test environment doesn't support the setup required by the test, and so it isn't meaningful to run the test at all. For those, a drop-in replacement to `skipTestIfFn` works.
1 parent 8d32654 commit 0fc5786

File tree

4 files changed

+16
-43
lines changed

4 files changed

+16
-43
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,6 @@ def expectedFailure_impl(func):
128128
return expectedFailure_impl
129129

130130

131-
def expectedFailureIfFn(expected_fn, bugnumber=None):
132-
def expectedFailure_impl(func):
133-
if isinstance(func, type) and issubclass(func, unittest.TestCase):
134-
raise Exception("Decorator can only be used to decorate a test method")
135-
136-
@wraps(func)
137-
def wrapper(*args, **kwargs):
138-
xfail_reason = expected_fn(*args, **kwargs)
139-
if xfail_reason is not None:
140-
xfail_func = unittest.expectedFailure(func)
141-
xfail_func(*args, **kwargs)
142-
else:
143-
func(*args, **kwargs)
144-
145-
return wrapper
146-
147-
# Some decorators can be called both with no arguments (e.g. @expectedFailureWindows)
148-
# or with arguments (e.g. @expectedFailureWindows(compilers=['gcc'])). When called
149-
# the first way, the first argument will be the actual function because decorators are
150-
# weird like that. So this is basically a check that says "which syntax was the original
151-
# function decorated with?"
152-
if callable(bugnumber):
153-
return expectedFailure_impl(bugnumber)
154-
else:
155-
return expectedFailure_impl
156-
157-
158131
def skipTestIfFn(expected_fn, bugnumber=None):
159132
def skipTestIfFn_impl(func):
160133
if isinstance(func, type) and issubclass(func, unittest.TestCase):
@@ -417,8 +390,8 @@ def skipIf(
417390
)
418391

419392

420-
def _skip_for_android(reason, api_levels, archs):
421-
def impl(obj):
393+
def _skip_fn_for_android(reason, api_levels, archs):
394+
def impl():
422395
result = lldbplatformutil.match_android_device(
423396
lldbplatformutil.getArchitecture(),
424397
valid_archs=archs,
@@ -549,8 +522,8 @@ def expectedFailureAndroid(bugnumber=None, api_levels=None, archs=None):
549522
arch - A sequence of architecture names specifying the architectures
550523
for which a test is expected to fail. None means all architectures.
551524
"""
552-
return expectedFailureIfFn(
553-
_skip_for_android("xfailing on android", api_levels, archs), bugnumber
525+
return expectedFailureIf(
526+
_skip_fn_for_android("xfailing on android", api_levels, archs)(), bugnumber
554527
)
555528

556529

@@ -612,7 +585,7 @@ def expectedFlakeyNetBSD(bugnumber=None, compilers=None):
612585

613586
def expectedFlakeyAndroid(bugnumber=None, api_levels=None, archs=None):
614587
return expectedFlakey(
615-
_skip_for_android("flakey on android", api_levels, archs), bugnumber
588+
_skip_fn_for_android("flakey on android", api_levels, archs), bugnumber
616589
)
617590

618591

@@ -846,7 +819,7 @@ def skipIfTargetAndroid(bugnumber=None, api_levels=None, archs=None):
846819
for which a test is skipped. None means all architectures.
847820
"""
848821
return skipTestIfFn(
849-
_skip_for_android("skipping for android", api_levels, archs), bugnumber
822+
_skip_fn_for_android("skipping for android", api_levels, archs), bugnumber
850823
)
851824

852825

lldb/test/API/commands/platform/sdk/TestPlatformSDK.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def port_not_available(self):
3939

4040
@no_debug_info_test
4141
@skipUnlessDarwin
42-
@expectedFailureIfFn(no_debugserver)
43-
@expectedFailureIfFn(port_not_available)
42+
@skipTestIfFn(no_debugserver)
43+
@skipTestIfFn(port_not_available)
4444
@skipIfRemote
4545
def test_macos_sdk(self):
4646
self.build()

lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_breakpoint(self):
2626
breakpoint = target.BreakpointCreateByLocation("main.c", 1)
2727
self.assertTrue(breakpoint.IsHardware())
2828

29-
@expectedFailureIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
29+
@skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
3030
def test_step_range(self):
3131
"""Test stepping when hardware breakpoints are required."""
3232
self.build()
@@ -49,7 +49,7 @@ def test_step_range(self):
4949
"Could not create hardware breakpoint for thread plan" in error.GetCString()
5050
)
5151

52-
@expectedFailureIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
52+
@skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
5353
def test_step_out(self):
5454
"""Test stepping out when hardware breakpoints are required."""
5555
self.build()
@@ -71,7 +71,7 @@ def test_step_out(self):
7171
"Could not create hardware breakpoint for thread plan" in error.GetCString()
7272
)
7373

74-
@expectedFailureIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
74+
@skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
7575
def test_step_over(self):
7676
"""Test stepping over when hardware breakpoints are required."""
7777
self.build()
@@ -91,7 +91,7 @@ def test_step_over(self):
9191

9292
# Was reported to sometimes pass on certain hardware.
9393
@skipIf(oslist=["linux"], archs=["arm"])
94-
@expectedFailureIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
94+
@skipTestIfFn(HardwareBreakpointTestBase.supports_hw_breakpoints)
9595
def test_step_until(self):
9696
"""Test stepping until when hardware breakpoints are required."""
9797
self.build()

lldb/test/API/functionalities/launch_stop_at_entry/TestStopAtEntry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def test_stop_default_platform_async(self):
4949

5050
@skipUnlessDarwin
5151
@skipIfRemote
52-
@expectedFailureIfFn(no_debugserver)
53-
@expectedFailureIfFn(port_not_available)
52+
@skipTestIfFn(no_debugserver)
53+
@skipTestIfFn(port_not_available)
5454
def test_stop_remote_platform_sync(self):
5555
self.do_test_stop_at_entry(True, True)
5656

5757
@skipUnlessDarwin
5858
@skipIfRemote
59-
@expectedFailureIfFn(no_debugserver)
60-
@expectedFailureIfFn(port_not_available)
59+
@skipTestIfFn(no_debugserver)
60+
@skipTestIfFn(port_not_available)
6161
def test_stop_remote_platform_async(self):
6262
self.do_test_stop_at_entry(False, True)
6363

0 commit comments

Comments
 (0)