[Lldb-commits] [lldb] e9b0994 - [lldb] Replace unittest2.expectedFailure with expectedFailure (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 17 10:05:55 PDT 2020


Author: Jonas Devlieghere
Date: 2020-08-17T10:05:49-07:00
New Revision: e9b099401262108301ecf27305b06749d1a58286

URL: https://github.com/llvm/llvm-project/commit/e9b099401262108301ecf27305b06749d1a58286
DIFF: https://github.com/llvm/llvm-project/commit/e9b099401262108301ecf27305b06749d1a58286.diff

LOG: [lldb] Replace unittest2.expectedFailure with expectedFailure (NFC)

Rename the existing expectedFailure to expectedFailureIfFn to better
describe its purpose and provide an overload for
unittest2.expectedFailure in decorators.py.

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/decorators.py
    lldb/test/API/commands/expression/test/TestExprs.py
    lldb/test/API/functionalities/avoids-fd-leak/TestFdLeak.py
    lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py
    lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py
    lldb/test/API/functionalities/thread/state/TestThreadStates.py
    lldb/test/API/lang/c/shared_lib/TestSharedLib.py
    lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py
    lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
    lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
    lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
    lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py
index ee2573fcd9e4..85f346d73283 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -85,7 +85,10 @@ def _match_decorator_property(expected, actual):
         return expected == actual
 
 
-def expectedFailure(expected_fn, bugnumber=None):
+def expectedFailure(func, bugnumber=None):
+    return unittest2.expectedFailure(func)
+
+def expectedFailureIfFn(expected_fn, bugnumber=None):
     def expectedFailure_impl(func):
         if isinstance(func, type) and issubclass(func, unittest2.TestCase):
             raise Exception(
@@ -93,11 +96,7 @@ def expectedFailure_impl(func):
 
         @wraps(func)
         def wrapper(*args, **kwargs):
-            self = args[0]
-            if funcutils.requires_self(expected_fn):
-                xfail_reason = expected_fn(self)
-            else:
-                xfail_reason = expected_fn()
+            xfail_reason = expected_fn(*args, **kwargs)
             if xfail_reason is not None:
                 xfail_func = unittest2.expectedFailure(func)
                 xfail_func(*args, **kwargs)
@@ -234,7 +233,7 @@ def fn(self):
     if mode == DecorateMode.Skip:
         return skipTestIfFn(fn, bugnumber)
     elif mode == DecorateMode.Xfail:
-        return expectedFailure(fn, bugnumber)
+        return expectedFailureIfFn(fn, bugnumber)
     else:
         return None
 
@@ -427,7 +426,7 @@ def expectedFailureAndroid(bugnumber=None, api_levels=None, archs=None):
         arch - A sequence of architecture names specifying the architectures
             for which a test is expected to fail. None means all architectures.
     """
-    return expectedFailure(
+    return expectedFailureIfFn(
         _skip_for_android(
             "xfailing on android",
             api_levels,

diff  --git a/lldb/test/API/commands/expression/test/TestExprs.py b/lldb/test/API/commands/expression/test/TestExprs.py
index df454cd9ee58..b56ebd896eeb 100644
--- a/lldb/test/API/commands/expression/test/TestExprs.py
+++ b/lldb/test/API/commands/expression/test/TestExprs.py
@@ -49,7 +49,7 @@ def build_and_run(self):
 
         self.runCmd("run", RUN_SUCCEEDED)
 
-    @unittest2.expectedFailure(
+    @expectedFailure(
         "llvm.org/pr17135 <rdar://problem/14874559> APFloat::toString does not identify the correct (i.e. least) precision.")
     def test_floating_point_expr_commands(self):
         self.build_and_run()

diff  --git a/lldb/test/API/functionalities/avoids-fd-leak/TestFdLeak.py b/lldb/test/API/functionalities/avoids-fd-leak/TestFdLeak.py
index a984254fff99..bb0a9f99b0db 100644
--- a/lldb/test/API/functionalities/avoids-fd-leak/TestFdLeak.py
+++ b/lldb/test/API/functionalities/avoids-fd-leak/TestFdLeak.py
@@ -24,7 +24,7 @@ class AvoidsFdLeakTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @expectedFailure(python_leaky_fd_version, "bugs.freebsd.org/197376")
+    @expectedFailureIfFn(python_leaky_fd_version, "bugs.freebsd.org/197376")
     @expectedFailureAll(
         oslist=['freebsd'],
         bugnumber="llvm.org/pr25624 still failing with Python 2.7.10")
@@ -36,7 +36,7 @@ class AvoidsFdLeakTestCase(TestBase):
     def test_fd_leak_basic(self):
         self.do_test([])
 
-    @expectedFailure(python_leaky_fd_version, "bugs.freebsd.org/197376")
+    @expectedFailureIfFn(python_leaky_fd_version, "bugs.freebsd.org/197376")
     @expectedFailureAll(
         oslist=['freebsd'],
         bugnumber="llvm.org/pr25624 still failing with Python 2.7.10")
@@ -68,7 +68,7 @@ def do_test(self, commands):
             process.GetExitStatus() == 0,
             "Process returned non-zero status. Were incorrect file descriptors passed?")
 
-    @expectedFailure(python_leaky_fd_version, "bugs.freebsd.org/197376")
+    @expectedFailureIfFn(python_leaky_fd_version, "bugs.freebsd.org/197376")
     @expectedFailureAll(
         oslist=['freebsd'],
         bugnumber="llvm.org/pr25624 still failing with Python 2.7.10")

diff  --git a/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py b/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py
index dfb946036aa2..f7787bbf68b1 100644
--- a/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py
+++ b/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/TestRequireHWBreakpoints.py
@@ -27,7 +27,7 @@ def test_breakpoint(self):
         breakpoint = target.BreakpointCreateByLocation("main.c", 1)
         self.assertTrue(breakpoint.IsHardware())
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_range(self):
         """Test stepping when hardware breakpoints are required."""
         self.build()
@@ -48,7 +48,7 @@ def test_step_range(self):
         self.assertTrue("Could not create hardware breakpoint for thread plan"
                         in error.GetCString())
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_out(self):
         """Test stepping out when hardware breakpoints are required."""
         self.build()
@@ -68,7 +68,7 @@ def test_step_out(self):
         self.assertTrue("Could not create hardware breakpoint for thread plan"
                         in error.GetCString())
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_over(self):
         """Test stepping over when hardware breakpoints are required."""
         self.build()
@@ -86,7 +86,7 @@ def test_step_over(self):
                 'error: Could not create hardware breakpoint for thread plan.'
             ])
 
-    @expectedFailure(supports_hw_breakpoints)
+    @expectedFailureIfFn(supports_hw_breakpoints)
     def test_step_until(self):
         """Test stepping until when hardware breakpoints are required."""
         self.build()

diff  --git a/lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py b/lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py
index 3a89947d3051..4a1118c2a292 100644
--- a/lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py
+++ b/lldb/test/API/functionalities/jitloader_gdb/TestJITLoaderGDB.py
@@ -16,7 +16,7 @@ class JITLoaderGDBTestCase(TestBase):
     @skipTestIfFn(
         lambda: "Skipped because the test crashes the test runner",
         bugnumber="llvm.org/pr24702")
-    @unittest2.expectedFailure("llvm.org/pr24702")
+    @expectedFailure("llvm.org/pr24702")
     def test_bogus_values(self):
         """Test that we handle inferior misusing the GDB JIT interface"""
         self.build()

diff  --git a/lldb/test/API/functionalities/thread/state/TestThreadStates.py b/lldb/test/API/functionalities/thread/state/TestThreadStates.py
index 60938088c9ac..baae9053dcf9 100644
--- a/lldb/test/API/functionalities/thread/state/TestThreadStates.py
+++ b/lldb/test/API/functionalities/thread/state/TestThreadStates.py
@@ -44,14 +44,14 @@ def test_state_after_continue(self):
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24660")
     @expectedFailureNetBSD
     # thread states not properly maintained
-    @unittest2.expectedFailure("llvm.org/pr16712")
+    @expectedFailure("llvm.org/pr16712")
     def test_state_after_expression(self):
         """Test thread state after expression."""
         self.build(dictionary=self.getBuildFlags(use_cpp11=False))
         self.thread_state_after_expression_test()
 
     # thread states not properly maintained
-    @unittest2.expectedFailure("llvm.org/pr15824 and <rdar://problem/28557237>")
+    @expectedFailure("llvm.org/pr15824 and <rdar://problem/28557237>")
     @expectedFailureAll(
         oslist=["windows"],
         bugnumber="llvm.org/pr24668: Breakpoints not resolved correctly")

diff  --git a/lldb/test/API/lang/c/shared_lib/TestSharedLib.py b/lldb/test/API/lang/c/shared_lib/TestSharedLib.py
index 789939b29e76..208e892c7bdc 100644
--- a/lldb/test/API/lang/c/shared_lib/TestSharedLib.py
+++ b/lldb/test/API/lang/c/shared_lib/TestSharedLib.py
@@ -44,7 +44,7 @@ def test_expr_no_preload(self):
         """Test that types work when defined in a shared library and forward-declared in the main executable, but with preloading disabled"""
         self.common_test_expr(False)
 
-    @unittest2.expectedFailure("llvm.org/PR36712")
+    @expectedFailure("llvm.org/PR36712")
     def test_frame_variable(self):
         """Test that types work when defined in a shared library and forward-declared in the main executable"""
         self.build()

diff  --git a/lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py b/lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py
index 8858f67cd181..5888351e1ece 100644
--- a/lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py
+++ b/lldb/test/API/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py
@@ -33,7 +33,7 @@ def test_expr(self):
                 "other_element = 3"])
 
     @expectedFailureAll(oslist=["windows"])
-    @unittest2.expectedFailure("llvm.org/PR36712")
+    @expectedFailure("llvm.org/PR36712")
     def test_frame_variable(self):
         """Test that types work when defined in a shared library and forward-declared in the main executable"""
         self.build()

diff  --git a/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py b/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
index 5526a14f530f..fa8e2ddbbed5 100644
--- a/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
+++ b/lldb/test/API/lang/cpp/namespace/TestNamespaceLookup.py
@@ -142,7 +142,7 @@ def test_scope_lookup_with_run_command(self):
         # Evaluate B::func() - should call B::func()
         self.expect("expr -- B::func()", startstr="(int) $15 = 4")
 
-    @unittest2.expectedFailure("lldb scope lookup of functions bugs")
+    @expectedFailure("lldb scope lookup of functions bugs")
     def test_function_scope_lookup_with_run_command(self):
         """Test scope lookup of functions in lldb."""
         self.build()
@@ -179,7 +179,7 @@ def test_function_scope_lookup_with_run_command(self):
         # before functions.
         self.expect("expr -- foo()", startstr="(int) $2 = 42")
 
-    @unittest2.expectedFailure("lldb file scope lookup bugs")
+    @expectedFailure("lldb file scope lookup bugs")
     @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
     def test_file_scope_lookup_with_run_command(self):
         """Test file scope lookup in lldb."""
@@ -246,7 +246,7 @@ def test_scope_after_using_directive_lookup_with_run_command(self):
         # Evaluate func2() - should call A::func2()
         self.expect("expr -- func2()", startstr="(int) $0 = 3")
 
-    @unittest2.expectedFailure(
+    @expectedFailure(
         "lldb scope lookup after using declaration bugs")
     # NOTE: this test may fail on older systems that don't emit import
     # emtries in DWARF - may need to add checks for compiler versions here.
@@ -268,7 +268,7 @@ def test_scope_after_using_declaration_lookup_with_run_command(self):
         # Evaluate func() - should call A::func()
         self.expect("expr -- func()", startstr="(int) $0 = 3")
 
-    @unittest2.expectedFailure("lldb scope lookup ambiguity after using bugs")
+    @expectedFailure("lldb scope lookup ambiguity after using bugs")
     def test_scope_ambiguity_after_using_lookup_with_run_command(self):
         """Test scope lookup ambiguity after using in lldb."""
         self.build()

diff  --git a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
index 4e02ebe89656..301f3bc10269 100644
--- a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -15,7 +15,7 @@ class CPPStaticMembersTestCase(TestBase):
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @unittest2.expectedFailure  # llvm.org/pr15401
+    @expectedFailure  # llvm.org/pr15401
     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
     def test_with_run_command(self):
         """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods"""

diff  --git a/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py b/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
index cc3922ccf9f4..4a16a8011c18 100644
--- a/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
+++ b/lldb/test/API/lang/objc/hidden-ivars/TestHiddenIvars.py
@@ -66,7 +66,7 @@ def test_frame_variable(self):
             self.build()
             self.frame_var(False)
 
-    @unittest2.expectedFailure("rdar://18683637")
+    @expectedFailure("rdar://18683637")
     @skipUnlessDarwin
     def test_frame_variable_across_modules(self):
         if self.getArchitecture() == 'i386':

diff  --git a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
index 154f8b629dcc..bd656fb01060 100644
--- a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -807,7 +807,7 @@ def Hc_then_Csignal_signals_correct_thread(self, segfault_signo):
             post_handle_thread_id = int(post_handle_thread_id, 16)
             self.assertEqual(post_handle_thread_id, print_thread_id)
 
-    @unittest2.expectedFailure()
+    @expectedFailure
     @debugserver_test
     @skipIfDarwinEmbedded # <rdar://problem/34539270> lldb-server tests not updated to work on ios etc yet
     def test_Hc_then_Csignal_signals_correct_thread_launch_debugserver(self):


        


More information about the lldb-commits mailing list