diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2023-05-25 08:48:57 -0700 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2023-05-25 12:54:09 -0700 |
| commit | 2238dcc39358353cac21df75c3c3286ab20b8f53 (patch) | |
| tree | 1bb7ec8d7405ccd7fdb5a8a78d0cf5ef40bcc963 /lldb/test/API/python_api/thread/TestThreadAPI.py | |
| parent | daeee56798c51e8f007e8e8e6e677a420b14c9ef (diff) | |
[NFC][Py Reformat] Reformat python files in lldb
This is an ongoing series of commits that are reformatting our Python
code. Reformatting is done with `black` (23.1.0).
If you end up having problems merging this commit because you have made
changes to a python file, the best way to handle that is to run `git
checkout --ours <yourfile>` and then reformat it with black.
RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style
Differential revision: https://reviews.llvm.org/D151460
Diffstat (limited to 'lldb/test/API/python_api/thread/TestThreadAPI.py')
| -rw-r--r-- | lldb/test/API/python_api/thread/TestThreadAPI.py | 109 |
1 files changed, 56 insertions, 53 deletions
diff --git a/lldb/test/API/python_api/thread/TestThreadAPI.py b/lldb/test/API/python_api/thread/TestThreadAPI.py index b26d168c179b..0fe91c88c325 100644 --- a/lldb/test/API/python_api/thread/TestThreadAPI.py +++ b/lldb/test/API/python_api/thread/TestThreadAPI.py @@ -10,7 +10,6 @@ from lldbsuite.test.lldbutil import get_stopped_thread, get_caller_symbol class ThreadAPITestCase(TestBase): - def test_get_process(self): """Test Python SBThread.GetProcess() API.""" self.build() @@ -24,18 +23,18 @@ class ThreadAPITestCase(TestBase): def test_run_to_address(self): """Test Python SBThread.RunToAddress() API.""" # We build a different executable than the default build() does. - d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.run_to_address(self.exe_name) - @skipIfAsan # The output looks different under ASAN. - @expectedFailureAll(oslist=["linux"], archs=['arm'], bugnumber="llvm.org/pr45892") + @skipIfAsan # The output looks different under ASAN. + @expectedFailureAll(oslist=["linux"], archs=["arm"], bugnumber="llvm.org/pr45892") @expectedFailureAll(oslist=["windows"]) def test_step_out_of_malloc_into_function_b(self): """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b().""" # We build a different executable than the default build() does. - d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.step_out_of_malloc_into_function_b(self.exe_name) @@ -43,7 +42,7 @@ class ThreadAPITestCase(TestBase): def test_step_over_3_times(self): """Test Python SBThread.StepOver() API.""" # We build a different executable than the default build() does. - d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} + d = {"CXX_SOURCES": "main2.cpp", "EXE": self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) self.step_over_3_times(self.exe_name) @@ -58,13 +57,16 @@ class ThreadAPITestCase(TestBase): TestBase.setUp(self) # Find the line number within main.cpp to break inside main(). self.break_line = line_number( - "main.cpp", "// Set break point at this line and check variable 'my_char'.") + "main.cpp", "// Set break point at this line and check variable 'my_char'." + ) # Find the line numbers within main2.cpp for # step_out_of_malloc_into_function_b() and step_over_3_times(). self.step_out_of_malloc = line_number( - "main2.cpp", "// thread step-out of malloc into function b.") + "main2.cpp", "// thread step-out of malloc into function b." + ) self.after_3_step_overs = line_number( - "main2.cpp", "// we should reach here after 3 step-over's.") + "main2.cpp", "// we should reach here after 3 step-over's." + ) # We'll use the test method name as the exe_name for executable # compiled from main2.cpp. @@ -77,19 +79,17 @@ class ThreadAPITestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateByLocation( - "main.cpp", self.break_line) + breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) self.assertTrue(breakpoint, VALID_BREAKPOINT) self.runCmd("breakpoint list") # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + process = target.LaunchSimple(None, None, self.get_process_working_directory()) thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") + thread.IsValid(), "There should be a thread stopped due to breakpoint" + ) self.runCmd("process status") proc_of_thread = thread.GetProcess() @@ -103,33 +103,35 @@ class ThreadAPITestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateByLocation( - "main.cpp", self.break_line) + breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) self.assertTrue(breakpoint, VALID_BREAKPOINT) - #self.runCmd("breakpoint list") + # self.runCmd("breakpoint list") # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + process = target.LaunchSimple(None, None, self.get_process_working_directory()) thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") + thread.IsValid(), "There should be a thread stopped due to breakpoint" + ) # Get the stop reason. GetStopDescription expects that we pass in the size of the description # we expect plus an additional byte for the null terminator. # Test with a buffer that is exactly as large as the expected stop reason. - self.assertEqual("breakpoint 1.1", thread.GetStopDescription(len('breakpoint 1.1') + 1)) + self.assertEqual( + "breakpoint 1.1", thread.GetStopDescription(len("breakpoint 1.1") + 1) + ) # Test some smaller buffer sizes. - self.assertEqual("breakpoint", thread.GetStopDescription(len('breakpoint') + 1)) - self.assertEqual("break", thread.GetStopDescription(len('break') + 1)) - self.assertEqual("b", thread.GetStopDescription(len('b') + 1)) + self.assertEqual("breakpoint", thread.GetStopDescription(len("breakpoint") + 1)) + self.assertEqual("break", thread.GetStopDescription(len("break") + 1)) + self.assertEqual("b", thread.GetStopDescription(len("b") + 1)) # Test that we can pass in a much larger size and still get the right output. - self.assertEqual("breakpoint 1.1", thread.GetStopDescription(len('breakpoint 1.1') + 100)) + self.assertEqual( + "breakpoint 1.1", thread.GetStopDescription(len("breakpoint 1.1") + 100) + ) def step_out_of_malloc_into_function_b(self, exe_name): """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b().""" @@ -138,30 +140,29 @@ class ThreadAPITestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateByName('malloc') + breakpoint = target.BreakpointCreateByName("malloc") self.assertTrue(breakpoint, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + process = target.LaunchSimple(None, None, self.get_process_working_directory()) while True: thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") + thread.IsValid(), "There should be a thread stopped due to breakpoint" + ) caller_symbol = get_caller_symbol(thread) if not caller_symbol: - self.fail( - "Test failed: could not locate the caller symbol of malloc") + self.fail("Test failed: could not locate the caller symbol of malloc") # Our top frame may be an inlined function in malloc() (e.g., on # FreeBSD). Apply a simple heuristic of stepping out until we find # a non-malloc caller while caller_symbol.startswith("malloc"): thread.StepOut() - self.assertTrue(thread.IsValid(), - "Thread valid after stepping to outer malloc") + self.assertTrue( + thread.IsValid(), "Thread valid after stepping to outer malloc" + ) caller_symbol = get_caller_symbol(thread) if caller_symbol == "b(int)": @@ -175,8 +176,10 @@ class ThreadAPITestCase(TestBase): thread.StepOut() self.runCmd("thread backtrace") self.assertEqual( - thread.GetFrameAtIndex(0).GetLineEntry().GetLine(), self.step_out_of_malloc, - "step out of malloc into function b is successful") + thread.GetFrameAtIndex(0).GetLineEntry().GetLine(), + self.step_out_of_malloc, + "step out of malloc into function b is successful", + ) def step_over_3_times(self, exe_name): """Test Python SBThread.StepOver() API.""" @@ -186,13 +189,13 @@ class ThreadAPITestCase(TestBase): self.assertTrue(target, VALID_TARGET) breakpoint = target.BreakpointCreateByLocation( - 'main2.cpp', self.step_out_of_malloc) + "main2.cpp", self.step_out_of_malloc + ) self.assertTrue(breakpoint, VALID_BREAKPOINT) self.runCmd("breakpoint list") # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) @@ -201,7 +204,8 @@ class ThreadAPITestCase(TestBase): thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue( thread.IsValid(), - "There should be a thread stopped due to breakpoint condition") + "There should be a thread stopped due to breakpoint condition", + ) self.runCmd("thread backtrace") frame0 = thread.GetFrameAtIndex(0) lineEntry = frame0.GetLineEntry() @@ -232,13 +236,13 @@ class ThreadAPITestCase(TestBase): self.assertTrue(target, VALID_TARGET) breakpoint = target.BreakpointCreateByLocation( - 'main2.cpp', self.step_out_of_malloc) + "main2.cpp", self.step_out_of_malloc + ) self.assertTrue(breakpoint, VALID_BREAKPOINT) self.runCmd("breakpoint list") # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) @@ -247,7 +251,8 @@ class ThreadAPITestCase(TestBase): thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue( thread.IsValid(), - "There should be a thread stopped due to breakpoint condition") + "There should be a thread stopped due to breakpoint condition", + ) self.runCmd("thread backtrace") frame0 = thread.GetFrameAtIndex(0) lineEntry = frame0.GetLineEntry() @@ -273,7 +278,7 @@ class ThreadAPITestCase(TestBase): # corresponds to self.step_out_of_malloc line entry's start address. thread.RunToAddress(start_addr) self.runCmd("process status") - #self.runCmd("thread backtrace") + # self.runCmd("thread backtrace") def validate_negative_indexing(self): exe = self.getBuildArtifact("a.out") @@ -281,19 +286,17 @@ class ThreadAPITestCase(TestBase): target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) - breakpoint = target.BreakpointCreateByLocation( - "main.cpp", self.break_line) + breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) self.assertTrue(breakpoint, VALID_BREAKPOINT) self.runCmd("breakpoint list") # Launch the process, and do not stop at the entry point. - process = target.LaunchSimple( - None, None, self.get_process_working_directory()) + process = target.LaunchSimple(None, None, self.get_process_working_directory()) thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) self.assertTrue( - thread.IsValid(), - "There should be a thread stopped due to breakpoint") + thread.IsValid(), "There should be a thread stopped due to breakpoint" + ) self.runCmd("process status") pos_range = range(thread.num_frames) |
