summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2015-03-16 19:54:22 +0000
committerGreg Clayton <gclayton@apple.com>2015-03-16 19:54:22 +0000
commit75a19344ad865390007c594836685f06488c0816 (patch)
tree36312d6660ca66159112007ff148dbf01f32bd60 /lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py
parent3eea196a4f898eddce2eed19847f749ae3e6b1d4 (diff)
downloadbcm5719-llvm-75a19344ad865390007c594836685f06488c0816.tar.gz
bcm5719-llvm-75a19344ad865390007c594836685f06488c0816.zip
Added an Python operating system plug-in test to verify that python can be used to add threads to an existing process.
The test does the following: 1 - runs a program to main without the OS plug-in and verifies no OS threads are in the process 2 - loads the OS plug-in and verifies the 3 OS plug-in threads are now in the current process 3 - verify the register contents of each thread that shows up 4 - unload the python OS plug-in and verify that the OS threads are gone. llvm-svn: 232401
Diffstat (limited to 'lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py')
-rw-r--r--lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py b/lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py
new file mode 100644
index 00000000000..48a82e6dc0c
--- /dev/null
+++ b/lldb/test/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py
@@ -0,0 +1,101 @@
+"""
+Test that the Python operating system plugin works correctly
+"""
+
+import os, time
+import re
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+class PluginPythonOSPlugin(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+ @dsym_test
+ def test_python_os_plugin_dsym(self):
+ """Test that the Python operating system plugin works correctly"""
+ self.buildDsym()
+ self.run_python_os_funcionality()
+
+ @dwarf_test
+ def test_python_os_plugin_dwarf(self):
+ """Test that the Python operating system plugin works correctly"""
+ self.buildDwarf()
+ self.run_python_os_funcionality()
+
+ def verify_os_thread_registers(self, thread):
+ frame = thread.GetFrameAtIndex(0)
+ registers = frame.GetRegisters().GetValueAtIndex(0)
+ reg_value = thread.GetThreadID() + 1
+ for reg in registers:
+ self.assertTrue(reg.GetValueAsUnsigned() == reg_value, "Verify the registers contains the correct value")
+ reg_value = reg_value + 1
+
+ def run_python_os_funcionality(self):
+ """Test that the Python operating system plugin works correctly"""
+
+ # Set debugger into synchronous mode
+ self.dbg.SetAsync(False)
+
+ # Create a target by the debugger.
+ cwd = os.getcwd()
+ exe = os.path.join(cwd, "a.out")
+ python_os_plugin_path = os.path.join(cwd, "operating_system.py")
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Set breakpoints inside and outside methods that take pointers to the containing struct.
+ lldbutil.run_break_set_by_source_regexp (self, "// Set breakpoint here")
+
+ # Register our shared libraries for remote targets so they get automatically uploaded
+ arguments = None
+ environment = None
+
+ # Now launch the process, and do not stop at entry point.
+ process = target.LaunchSimple (arguments, environment, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Make sure there are no OS plug-in created thread when we first stop at our breakpoint in main
+ thread = process.GetThreadByID(0x111111111);
+ self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 before we load the python OS plug-in");
+ thread = process.GetThreadByID(0x222222222);
+ self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 before we load the python OS plug-in");
+ thread = process.GetThreadByID(0x333333333);
+ self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 before we load the python OS plug-in");
+
+
+ # Now load the python OS plug-in which should update the thread list and we should have
+ # OS plug-in created threads with the IDs: 0x111111111, 0x222222222, 0x333333333
+ command = "settings set target.process.python-os-plugin-path '%s'" % python_os_plugin_path
+ self.dbg.HandleCommand(command)
+
+ # Verify our OS plug-in threads showed up
+ thread = process.GetThreadByID(0x111111111);
+ self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x111111111 after we load the python OS plug-in");
+ self.verify_os_thread_registers(thread)
+ thread = process.GetThreadByID(0x222222222);
+ self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x222222222 after we load the python OS plug-in");
+ self.verify_os_thread_registers(thread)
+ thread = process.GetThreadByID(0x333333333);
+ self.assertTrue (thread.IsValid(), "Make sure there is a thread 0x333333333 after we load the python OS plug-in");
+ self.verify_os_thread_registers(thread)
+
+ # Now clear the OS plug-in path to make the OS plug-in created threads dissappear
+ self.dbg.HandleCommand("settings clear target.process.python-os-plugin-path")
+
+ # Verify the threads are gone after unloading the python OS plug-in
+ thread = process.GetThreadByID(0x111111111);
+ self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x111111111 after we unload the python OS plug-in");
+ thread = process.GetThreadByID(0x222222222);
+ self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x222222222 after we unload the python OS plug-in");
+ thread = process.GetThreadByID(0x333333333);
+ self.assertFalse (thread.IsValid(), "Make sure there is no thread 0x333333333 after we unload the python OS plug-in");
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
OpenPOWER on IntegriCloud