diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:26:05 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:26:05 +0000 |
commit | 14f1b3e8826ce43b978db93a62d1166055db5394 (patch) | |
tree | 0a00ad8d3498783fe0193f3b656bca17c4c8697d /packages/Python/lldbsuite/test/python_api/process | |
parent | 4ee8c119c71a06dcad1e0fecc8c675e480e59337 (diff) |
Notes
Diffstat (limited to 'packages/Python/lldbsuite/test/python_api/process')
-rw-r--r-- | packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py | 140 | ||||
-rw-r--r-- | packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py | 105 |
2 files changed, 153 insertions, 92 deletions
diff --git a/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py b/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py index d5f407155b29e..1009536b3709b 100644 --- a/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py +++ b/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py @@ -5,13 +5,14 @@ Test SBProcess APIs, including ReadMemory(), WriteMemory(), and others. from __future__ import print_function - -import os, time +import os +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test.lldbutil import get_stopped_thread, state_type_to_str + class ProcessAPITestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -20,7 +21,9 @@ class ProcessAPITestCase(TestBase): # 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'.") + self.line = line_number( + "main.cpp", + "// Set break point at this line and check variable 'my_char'.") @add_test_categories(['pyapi']) def test_read_memory(self): @@ -35,10 +38,13 @@ 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") + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint") frame = thread.GetFrameAtIndex(0) # Get the SBValue for the global variable 'my_char'. @@ -49,45 +55,55 @@ 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(): print("memory content:", content) - self.expect(content, "Result from SBProcess.ReadMemory() matches our expected output: 'x'", - exe=False, - startstr = b'x') + self.expect( + content, + "Result from SBProcess.ReadMemory() matches our expected output: 'x'", + exe=False, + 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(): print("cstring read is:", cstring) - self.expect(cstring, "Result from SBProcess.ReadCStringFromMemory() matches our expected output", - exe=False, - startstr = 'Does it work?') + self.expect( + cstring, + "Result from SBProcess.ReadCStringFromMemory() matches our expected output", + exe=False, + startstr='Does it work?') # Get the SBValue for the global variable 'my_cstring'. val = frame.FindValue("my_cstring", lldb.eValueTypeVariableGlobal) self.DebugSBValue(val) # Due to the typemap magic (see lldb.swig), we pass in 256 to read at most 256 bytes - # from the address, and expect to get a Python string as the result object! + # from the address, and expect to get a Python string as the result + # object! self.assertFalse(val.TypeIsPointerType()) - cstring = process.ReadCStringFromMemory(val.AddressOf().GetValueAsUnsigned(), 256, error) + cstring = process.ReadCStringFromMemory( + val.AddressOf().GetValueAsUnsigned(), 256, error) if not error.Success(): self.fail("SBProcess.ReadCStringFromMemory() failed") if self.TraceOn(): print("cstring read is:", cstring) - self.expect(cstring, "Result from SBProcess.ReadCStringFromMemory() matches our expected output", - exe=False, - startstr = 'lldb.SBProcess.ReadCStringFromMemory() works!') + self.expect( + cstring, + "Result from SBProcess.ReadCStringFromMemory() matches our expected output", + exe=False, + startstr='lldb.SBProcess.ReadCStringFromMemory() works!') # Get the SBValue for the global variable 'my_uint32'. val = frame.FindValue("my_uint32", lldb.eValueTypeVariableGlobal) @@ -96,14 +112,16 @@ class ProcessAPITestCase(TestBase): # Due to the typemap magic (see lldb.swig), we pass in 4 to read 4 bytes # 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) + my_uint32 = process.ReadUnsignedFromMemory( + val.AddressOf().GetValueAsUnsigned(), 4, error) if not error.Success(): self.fail("SBProcess.ReadCStringFromMemory() failed") if self.TraceOn(): print("uint32 read is:", my_uint32) if my_uint32 != 12345: - self.fail("Result from SBProcess.ReadUnsignedFromMemory() does not match our expected output") + self.fail( + "Result from SBProcess.ReadUnsignedFromMemory() does not match our expected output") @add_test_categories(['pyapi']) def test_write_memory(self): @@ -118,17 +136,21 @@ 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") + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint") frame = thread.GetFrameAtIndex(0) # Get the SBValue for the global variable 'my_char'. val = frame.FindValue("my_char", lldb.eValueTypeVariableGlobal) self.DebugSBValue(val) - # If the variable does not have a load address, there's no sense continuing. + # If the variable does not have a load address, there's no sense + # continuing. if not val.GetLocation().startswith("0x"): return @@ -136,7 +158,8 @@ class ProcessAPITestCase(TestBase): location = int(val.GetLocation(), 16) # The program logic makes the 'my_char' variable to have memory content as 'x'. - # But we want to use the WriteMemory() API to assign 'a' to the variable. + # But we want to use the WriteMemory() API to assign 'a' to the + # variable. # Now use WriteMemory() API to write 'a' into the global variable. error = lldb.SBError() @@ -153,9 +176,11 @@ class ProcessAPITestCase(TestBase): if self.TraceOn(): print("memory content:", content) - self.expect(content, "Result from SBProcess.ReadMemory() matches our expected output: 'a'", - exe=False, - startstr = b'a') + self.expect( + content, + "Result from SBProcess.ReadMemory() matches our expected output: 'a'", + exe=False, + startstr=b'a') @add_test_categories(['pyapi']) def test_access_my_int(self): @@ -170,17 +195,21 @@ 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") + self.assertTrue( + thread.IsValid(), + "There should be a thread stopped due to breakpoint") frame = thread.GetFrameAtIndex(0) # Get the SBValue for the global variable 'my_int'. val = frame.FindValue("my_int", lldb.eValueTypeVariableGlobal) self.DebugSBValue(val) - # If the variable does not have a load address, there's no sense continuing. + # If the variable does not have a load address, there's no sense + # continuing. if not val.GetLocation().startswith("0x"): return @@ -204,7 +233,8 @@ class ProcessAPITestCase(TestBase): return # The program logic makes the 'my_int' variable to have int type and value of 0. - # But we want to use the WriteMemory() API to assign 256 to the variable. + # But we want to use the WriteMemory() API to assign 256 to the + # variable. # Now use WriteMemory() API to write 256 into the global variable. error = lldb.SBError() @@ -212,25 +242,31 @@ class ProcessAPITestCase(TestBase): if not error.Success() or result != byteSize: self.fail("SBProcess.WriteMemory() failed") - # Make sure that the val we got originally updates itself to notice the change: - self.expect(val.GetValue(), - "SBProcess.ReadMemory() successfully writes (int)256 to the memory location for 'my_int'", - exe=False, - startstr = '256') + # Make sure that the val we got originally updates itself to notice the + # change: + self.expect( + val.GetValue(), + "SBProcess.ReadMemory() successfully writes (int)256 to the memory location for 'my_int'", + exe=False, + startstr='256') - # And for grins, get the SBValue for the global variable 'my_int' again, to make sure that also tracks the new value: + # And for grins, get the SBValue for the global variable 'my_int' + # again, to make sure that also tracks the new value: val = frame.FindValue("my_int", lldb.eValueTypeVariableGlobal) - self.expect(val.GetValue(), - "SBProcess.ReadMemory() successfully writes (int)256 to the memory location for 'my_int'", - exe=False, - startstr = '256') - - # Now read the memory content. The bytearray should have (byte)1 as the second element. + self.expect( + val.GetValue(), + "SBProcess.ReadMemory() successfully writes (int)256 to the memory location for 'my_int'", + exe=False, + startstr='256') + + # Now read the memory content. The bytearray should have (byte)1 as + # the second element. content = process.ReadMemory(location, byteSize, error) if not error.Success(): self.fail("SBProcess.ReadMemory() failed") - # The bytearray_to_int utility function expects a little endian bytearray. + # The bytearray_to_int utility function expects a little endian + # bytearray. if byteOrder == lldb.eByteOrderBig: content = bytearray(content, 'ascii') content.reverse() @@ -254,15 +290,19 @@ 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())) self.assertTrue(process.GetState() != lldb.eStateConnected) error = lldb.SBError() - success = process.RemoteLaunch(None, None, None, None, None, None, 0, False, error) - self.assertTrue(not success, "RemoteLaunch() should fail for process state != eStateConnected") + success = process.RemoteLaunch( + None, None, None, None, None, None, 0, False, error) + self.assertTrue( + not success, + "RemoteLaunch() should fail for process state != eStateConnected") @add_test_categories(['pyapi']) def test_get_num_supported_hardware_watchpoints(self): @@ -278,10 +318,10 @@ 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(); + error = lldb.SBError() num = process.GetNumSupportedHardwareWatchpoints(error) if self.TraceOn() and error.Success(): print("Number of supported hardware watchpoints: %d" % num) - diff --git a/packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py b/packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py index 1a194035f4ded..5314930ff99eb 100644 --- a/packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py +++ b/packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py @@ -3,13 +3,15 @@ from __future__ import print_function - -import os, sys, time +import os +import sys +import time import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil + class ProcessIOTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) @@ -19,16 +21,19 @@ class ProcessIOTestCase(TestBase): TestBase.setUp(self) # Get the full path to our executable to be debugged. self.exe = os.path.join(os.getcwd(), "process_io") - self.local_input_file = os.path.join(os.getcwd(), "input.txt") + self.local_input_file = os.path.join(os.getcwd(), "input.txt") self.local_output_file = os.path.join(os.getcwd(), "output.txt") - self.local_error_file = os.path.join(os.getcwd(), "error.txt") - - self.input_file = os.path.join(self.get_process_working_directory(), "input.txt") - self.output_file = os.path.join(self.get_process_working_directory(), "output.txt") - self.error_file = os.path.join(self.get_process_working_directory(), "error.txt") + self.local_error_file = os.path.join(os.getcwd(), "error.txt") + + self.input_file = os.path.join( + self.get_process_working_directory(), "input.txt") + self.output_file = os.path.join( + self.get_process_working_directory(), "output.txt") + self.error_file = os.path.join( + self.get_process_working_directory(), "error.txt") self.lines = ["Line 1", "Line 2", "Line 3"] - @skipIfWindows # stdio manipulation unsupported on Windows + @skipIfWindows # stdio manipulation unsupported on Windows @add_test_categories(['pyapi']) @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stdin_by_api(self): @@ -39,7 +44,7 @@ class ProcessIOTestCase(TestBase): output = self.process.GetSTDOUT(1000) self.check_process_output(output, output) - @skipIfWindows # stdio manipulation unsupported on Windows + @skipIfWindows # stdio manipulation unsupported on Windows @add_test_categories(['pyapi']) @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stdin_redirection(self): @@ -48,10 +53,10 @@ class ProcessIOTestCase(TestBase): self.create_target() self.redirect_stdin() self.run_process(False) - output = self.process.GetSTDOUT(1000) + output = self.process.GetSTDOUT(1000) self.check_process_output(output, output) - @skipIfWindows # stdio manipulation unsupported on Windows + @skipIfWindows # stdio manipulation unsupported on Windows @add_test_categories(['pyapi']) @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stdout_redirection(self): @@ -64,7 +69,7 @@ class ProcessIOTestCase(TestBase): error = self.process.GetSTDOUT(1000) self.check_process_output(output, error) - @skipIfWindows # stdio manipulation unsupported on Windows + @skipIfWindows # stdio manipulation unsupported on Windows @add_test_categories(['pyapi']) @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stderr_redirection(self): @@ -77,7 +82,7 @@ class ProcessIOTestCase(TestBase): error = self.read_error_file_and_delete() self.check_process_output(output, error) - @skipIfWindows # stdio manipulation unsupported on Windows + @skipIfWindows # stdio manipulation unsupported on Windows @add_test_categories(['pyapi']) @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stdout_stderr_redirection(self): @@ -98,29 +103,35 @@ class ProcessIOTestCase(TestBase): self.runCmd('platform get-file "{remote}" "{local}"'.format( remote=target_file, local=local_file)) - self.assertTrue(os.path.exists(local_file), 'Make sure "{local}" file exists'.format(local=local_file)) + self.assertTrue( + os.path.exists(local_file), + 'Make sure "{local}" file exists'.format( + local=local_file)) f = open(local_file, 'r') contents = f.read() f.close() - #TODO: add 'platform delete-file' file command - #if lldb.remote_platform: + # TODO: add 'platform delete-file' file command + # if lldb.remote_platform: # self.runCmd('platform delete-file "{remote}"'.format(remote=target_file)) os.unlink(local_file) return contents def read_output_file_and_delete(self): - return self.read_file_and_delete(self.output_file, self.local_output_file) + return self.read_file_and_delete( + self.output_file, self.local_output_file) def read_error_file_and_delete(self): - return self.read_file_and_delete(self.error_file, self.local_error_file) + return self.read_file_and_delete( + self.error_file, self.local_error_file) def create_target(self): '''Create the target and launch info that will be used by all tests''' - self.target = self.dbg.CreateTarget(self.exe) + self.target = self.dbg.CreateTarget(self.exe) self.launch_info = lldb.SBLaunchInfo([self.exe]) - self.launch_info.SetWorkingDirectory(self.get_process_working_directory()) - + self.launch_info.SetWorkingDirectory( + self.get_process_working_directory()) + def redirect_stdin(self): '''Redirect STDIN (file descriptor 0) to use our input.txt file @@ -140,43 +151,49 @@ class ProcessIOTestCase(TestBase): # clean slate for the next test case. def cleanup(): os.unlink(self.local_input_file) - #TODO: add 'platform delete-file' file command - #if lldb.remote_platform: + # TODO: add 'platform delete-file' file command + # if lldb.remote_platform: # self.runCmd('platform delete-file "{remote}"'.format(remote=self.input_file)) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) - self.launch_info.AddOpenFileAction(0, self.input_file, True, False); - + self.launch_info.AddOpenFileAction(0, self.input_file, True, False) + def redirect_stdout(self): '''Redirect STDOUT (file descriptor 1) to use our output.txt file''' - self.launch_info.AddOpenFileAction(1, self.output_file, False, True); - + self.launch_info.AddOpenFileAction(1, self.output_file, False, True) + def redirect_stderr(self): '''Redirect STDERR (file descriptor 2) to use our error.txt file''' - self.launch_info.AddOpenFileAction(2, self.error_file, False, True); - + self.launch_info.AddOpenFileAction(2, self.error_file, False, True) + def run_process(self, put_stdin): '''Run the process to completion and optionally put lines to STDIN via the API if "put_stdin" is True''' # Set the breakpoints - self.breakpoint = self.target.BreakpointCreateBySourceRegex('Set breakpoint here', lldb.SBFileSpec("main.c")) - self.assertTrue(self.breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) + self.breakpoint = self.target.BreakpointCreateBySourceRegex( + 'Set breakpoint here', lldb.SBFileSpec("main.c")) + self.assertTrue( + self.breakpoint.GetNumLocations() > 0, + VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. error = lldb.SBError() # This should launch the process and it should exit by the time we get back # because we have synchronous mode enabled - self.process = self.target.Launch (self.launch_info, error) + self.process = self.target.Launch(self.launch_info, error) - self.assertTrue(error.Success(), "Make sure process launched successfully") + self.assertTrue( + error.Success(), + "Make sure process launched successfully") self.assertTrue(self.process, PROCESS_IS_VALID) if self.TraceOn(): print("process launched.") # Frame #0 should be at our breakpoint. - threads = lldbutil.get_threads_stopped_at_breakpoint (self.process, self.breakpoint) - + threads = lldbutil.get_threads_stopped_at_breakpoint( + self.process, self.breakpoint) + self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] @@ -189,13 +206,13 @@ class ProcessIOTestCase(TestBase): if put_stdin: for line in self.lines: self.process.PutSTDIN(line + "\n") - + # Let process continue so it will exit self.process.Continue() state = self.process.GetState() self.assertTrue(state == lldb.eStateExited, PROCESS_IS_VALID) - - def check_process_output (self, output, error): + + def check_process_output(self, output, error): # Since we launched the process without specifying stdin/out/err, # a pseudo terminal is used for stdout/err, and we are satisfied # once "input line=>1" appears in stdout. @@ -203,10 +220,14 @@ class ProcessIOTestCase(TestBase): if self.TraceOn(): print("output = '%s'" % output) print("error = '%s'" % error) - + for line in self.lines: check_line = 'input line to stdout: %s' % (line) - self.assertTrue(check_line in output, "verify stdout line shows up in STDOUT") + self.assertTrue( + check_line in output, + "verify stdout line shows up in STDOUT") for line in self.lines: check_line = 'input line to stderr: %s' % (line) - self.assertTrue(check_line in error, "verify stderr line shows up in STDERR") + self.assertTrue( + check_line in error, + "verify stderr line shows up in STDERR") |