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/process/TestProcessAPI.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/process/TestProcessAPI.py')
| -rw-r--r-- | lldb/test/API/python_api/process/TestProcessAPI.py | 168 |
1 files changed, 97 insertions, 71 deletions
diff --git a/lldb/test/API/python_api/process/TestProcessAPI.py b/lldb/test/API/python_api/process/TestProcessAPI.py index edb507057283..df41397eb32b 100644 --- a/lldb/test/API/python_api/process/TestProcessAPI.py +++ b/lldb/test/API/python_api/process/TestProcessAPI.py @@ -10,27 +10,25 @@ from lldbsuite.test.lldbutil import get_stopped_thread, state_type_to_str class ProcessAPITestCase(TestBase): - def setUp(self): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break inside main(). self.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'." + ) def test_scripted_implementation(self): self.build() exe = self.getBuildArtifact("a.out") - (target, process, _, _) = \ - lldbutil.run_to_source_breakpoint(self, "Set break point", - lldb.SBFileSpec("main.cpp")) + (target, process, _, _) = lldbutil.run_to_source_breakpoint( + self, "Set break point", lldb.SBFileSpec("main.cpp") + ) self.assertTrue(process, PROCESS_IS_VALID) self.assertEqual(process.GetScriptedImplementation(), None) - def test_read_memory(self): """Test Python SBProcess.ReadMemory() API.""" self.build() @@ -43,13 +41,12 @@ class ProcessAPITestCase(TestBase): 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()) 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" + ) frame = thread.GetFrameAtIndex(0) # Get the SBValue for the global variable 'my_char'. @@ -60,8 +57,7 @@ class ProcessAPITestCase(TestBase): # expect to get a Python string as the result object! error = lldb.SBError() self.assertFalse(val.TypeIsPointerType()) - content = process.ReadMemory( - val.AddressOf().GetValueAsUnsigned(), 1, error) + content = process.ReadMemory(val.AddressOf().GetValueAsUnsigned(), 1, error) if not error.Success(): self.fail("SBProcess.ReadMemory() failed") if self.TraceOn(): @@ -71,13 +67,13 @@ class ProcessAPITestCase(TestBase): content, "Result from SBProcess.ReadMemory() matches our expected output: 'x'", exe=False, - startstr=b'x') + startstr=b"x", + ) # Read (char *)my_char_ptr. val = frame.FindValue("my_char_ptr", lldb.eValueTypeVariableGlobal) self.DebugSBValue(val) - cstring = process.ReadCStringFromMemory( - val.GetValueAsUnsigned(), 256, error) + cstring = process.ReadCStringFromMemory(val.GetValueAsUnsigned(), 256, error) if not error.Success(): self.fail("SBProcess.ReadCStringFromMemory() failed") if self.TraceOn(): @@ -87,7 +83,8 @@ class ProcessAPITestCase(TestBase): cstring, "Result from SBProcess.ReadCStringFromMemory() matches our expected output", exe=False, - startstr='Does it work?') + startstr="Does it work?", + ) # Get the SBValue for the global variable 'my_cstring'. val = frame.FindValue("my_cstring", lldb.eValueTypeVariableGlobal) @@ -98,7 +95,8 @@ class ProcessAPITestCase(TestBase): # object! self.assertFalse(val.TypeIsPointerType()) cstring = process.ReadCStringFromMemory( - val.AddressOf().GetValueAsUnsigned(), 256, error) + val.AddressOf().GetValueAsUnsigned(), 256, error + ) if not error.Success(): self.fail("SBProcess.ReadCStringFromMemory() failed") if self.TraceOn(): @@ -108,7 +106,8 @@ class ProcessAPITestCase(TestBase): cstring, "Result from SBProcess.ReadCStringFromMemory() matches our expected output", exe=False, - startstr='lldb.SBProcess.ReadCStringFromMemory() works!') + startstr="lldb.SBProcess.ReadCStringFromMemory() works!", + ) # Get the SBValue for the global variable 'my_uint32'. val = frame.FindValue("my_uint32", lldb.eValueTypeVariableGlobal) @@ -118,7 +117,8 @@ class ProcessAPITestCase(TestBase): # from the address, and expect to get an int as the result! self.assertFalse(val.TypeIsPointerType()) my_uint32 = process.ReadUnsignedFromMemory( - val.AddressOf().GetValueAsUnsigned(), 4, error) + val.AddressOf().GetValueAsUnsigned(), 4, error + ) if not error.Success(): self.fail("SBProcess.ReadCStringFromMemory() failed") if self.TraceOn(): @@ -126,7 +126,8 @@ class ProcessAPITestCase(TestBase): if my_uint32 != 12345: self.fail( - "Result from SBProcess.ReadUnsignedFromMemory() does not match our expected output") + "Result from SBProcess.ReadUnsignedFromMemory() does not match our expected output" + ) def test_write_memory(self): """Test Python SBProcess.WriteMemory() API.""" @@ -140,13 +141,12 @@ class ProcessAPITestCase(TestBase): 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()) 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" + ) frame = thread.GetFrameAtIndex(0) # Get the SBValue for the global variable 'my_char'. @@ -167,7 +167,7 @@ class ProcessAPITestCase(TestBase): # Now use WriteMemory() API to write 'a' into the global variable. error = lldb.SBError() - result = process.WriteMemory(location, 'a', error) + result = process.WriteMemory(location, "a", error) if not error.Success() or result != 1: self.fail("SBProcess.WriteMemory() failed") @@ -184,7 +184,8 @@ class ProcessAPITestCase(TestBase): content, "Result from SBProcess.ReadMemory() matches our expected output: 'a'", exe=False, - startstr=b'a') + startstr=b"a", + ) # Get the SBValue for the global variable 'my_cstring'. val = frame.FindValue("my_cstring", lldb.eValueTypeVariableGlobal) @@ -205,13 +206,13 @@ class ProcessAPITestCase(TestBase): self.fail("SBProcess.WriteMemoryAsCString() failed") cstring = process.ReadCStringFromMemory( - val.AddressOf().GetValueAsUnsigned(), 256, error) + val.AddressOf().GetValueAsUnsigned(), 256, error + ) if not error.Success(): self.fail("SBProcess.ReadCStringFromMemory() failed") self.assertEqual(cstring, message) - def test_access_my_int(self): """Test access 'my_int' using Python SBProcess.GetByteOrder() and other APIs.""" self.build() @@ -224,13 +225,12 @@ class ProcessAPITestCase(TestBase): 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()) 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" + ) frame = thread.GetFrameAtIndex(0) # Get the SBValue for the global variable 'my_int'. @@ -277,7 +277,8 @@ class ProcessAPITestCase(TestBase): val.GetValue(), "SBProcess.ReadMemory() successfully writes (int)256 to the memory location for 'my_int'", exe=False, - startstr='256') + startstr="256", + ) # And for grins, get the SBValue for the global variable 'my_int' # again, to make sure that also tracks the new value: @@ -286,7 +287,8 @@ class ProcessAPITestCase(TestBase): val.GetValue(), "SBProcess.ReadMemory() successfully writes (int)256 to the memory location for 'my_int'", exe=False, - startstr='256') + startstr="256", + ) # Now read the memory content. The bytearray should have (byte)1 as # the second element. @@ -297,7 +299,7 @@ class ProcessAPITestCase(TestBase): # The bytearray_to_int utility function expects a little endian # bytearray. if byteOrder == lldb.eByteOrderBig: - content = bytearray(content, 'ascii') + content = bytearray(content, "ascii") content.reverse() new_value = bytearray_to_int(content, byteSize) @@ -318,8 +320,7 @@ class ProcessAPITestCase(TestBase): self.assertTrue(target, VALID_TARGET) # 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()) if self.TraceOn(): print("process state:", state_type_to_str(process.GetState())) @@ -327,10 +328,12 @@ class ProcessAPITestCase(TestBase): error = lldb.SBError() success = process.RemoteLaunch( - None, None, None, None, None, None, 0, False, error) + None, None, None, None, None, None, 0, False, error + ) self.assertTrue( not success, - "RemoteLaunch() should fail for process state != eStateConnected") + "RemoteLaunch() should fail for process state != eStateConnected", + ) def test_get_num_supported_hardware_watchpoints(self): """Test SBProcess.GetNumSupportedHardwareWatchpoints() API with a process.""" @@ -345,8 +348,7 @@ class ProcessAPITestCase(TestBase): 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()) error = lldb.SBError() num = process.GetNumSupportedHardwareWatchpoints(error) @@ -386,8 +388,10 @@ class ProcessAPITestCase(TestBase): self.assertGreater(len(process_name), 0, "Process name isn't blank") self.assertEqual(file_spec.GetFilename(), "a.out") self.assertNotEqual( - process_info.GetProcessID(), lldb.LLDB_INVALID_PROCESS_ID, - "Process ID is valid") + process_info.GetProcessID(), + lldb.LLDB_INVALID_PROCESS_ID, + "Process ID is valid", + ) triple = process_info.GetTriple() self.assertIsNotNone(triple, "Process has a triple") @@ -395,47 +399,63 @@ class ProcessAPITestCase(TestBase): # whatever info was retrieved is consistent and nothing blows up. if process_info.UserIDIsValid(): self.assertNotEqual( - process_info.GetUserID(), lldb.UINT32_MAX, - "Process user ID is valid") + process_info.GetUserID(), lldb.UINT32_MAX, "Process user ID is valid" + ) else: self.assertEqual( - process_info.GetUserID(), lldb.UINT32_MAX, - "Process user ID is invalid") + process_info.GetUserID(), lldb.UINT32_MAX, "Process user ID is invalid" + ) if process_info.GroupIDIsValid(): self.assertNotEqual( - process_info.GetGroupID(), lldb.UINT32_MAX, - "Process group ID is valid") + process_info.GetGroupID(), lldb.UINT32_MAX, "Process group ID is valid" + ) else: self.assertEqual( - process_info.GetGroupID(), lldb.UINT32_MAX, - "Process group ID is invalid") + process_info.GetGroupID(), + lldb.UINT32_MAX, + "Process group ID is invalid", + ) if process_info.EffectiveUserIDIsValid(): self.assertNotEqual( - process_info.GetEffectiveUserID(), lldb.UINT32_MAX, - "Process effective user ID is valid") + process_info.GetEffectiveUserID(), + lldb.UINT32_MAX, + "Process effective user ID is valid", + ) else: self.assertEqual( - process_info.GetEffectiveUserID(), lldb.UINT32_MAX, - "Process effective user ID is invalid") + process_info.GetEffectiveUserID(), + lldb.UINT32_MAX, + "Process effective user ID is invalid", + ) if process_info.EffectiveGroupIDIsValid(): self.assertNotEqual( - process_info.GetEffectiveGroupID(), lldb.UINT32_MAX, - "Process effective group ID is valid") + process_info.GetEffectiveGroupID(), + lldb.UINT32_MAX, + "Process effective group ID is valid", + ) else: self.assertEqual( - process_info.GetEffectiveGroupID(), lldb.UINT32_MAX, - "Process effective group ID is invalid") + process_info.GetEffectiveGroupID(), + lldb.UINT32_MAX, + "Process effective group ID is invalid", + ) process_info.GetParentProcessID() def test_allocate_deallocate_memory(self): """Test Python SBProcess.AllocateMemory() and SBProcess.DeallocateMemory() APIs.""" self.build() - (target, process, main_thread, main_breakpoint) = lldbutil.run_to_source_breakpoint( - self, "// Set break point at this line", lldb.SBFileSpec("main.cpp")) + ( + target, + process, + main_thread, + main_breakpoint, + ) = lldbutil.run_to_source_breakpoint( + self, "// Set break point at this line", lldb.SBFileSpec("main.cpp") + ) # Allocate a block of memory in the target process error = lldb.SBError() @@ -446,7 +466,7 @@ class ProcessAPITestCase(TestBase): # Now use WriteMemory() API to write 'a' into the allocated # memory. Note that the debugger can do this even though the # block is not set writable. - result = process.WriteMemory(addr, 'a', error) + result = process.WriteMemory(addr, "a", error) if not error.Success() or result != 1: self.fail("SBProcess.WriteMemory() failed") @@ -463,23 +483,29 @@ class ProcessAPITestCase(TestBase): content, "Result from SBProcess.ReadMemory() matches our expected output: 'a'", exe=False, - startstr=b'a') + startstr=b"a", + ) # Verify that the process itself can read the allocated memory frame = main_thread.GetFrameAtIndex(0) val = frame.EvaluateExpression( - "test_read(reinterpret_cast<char *>({:#x}))".format(addr)) - self.expect(val.GetValue(), - "Result of test_read() matches expected output 'a'", - exe=False, - startstr="'a'") + "test_read(reinterpret_cast<char *>({:#x}))".format(addr) + ) + self.expect( + val.GetValue(), + "Result of test_read() matches expected output 'a'", + exe=False, + startstr="'a'", + ) # Verify that the process cannot write into the block val = frame.EvaluateExpression( - "test_write(reinterpret_cast<char *>({:#x}), 'b')".format(addr)) + "test_write(reinterpret_cast<char *>({:#x}), 'b')".format(addr) + ) if val.GetError().Success(): self.fail( - "test_write() to allocated memory without write permission unexpectedly succeeded") + "test_write() to allocated memory without write permission unexpectedly succeeded" + ) # Deallocate the memory error = process.DeallocateMemory(addr) |
