summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/python_api
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/python_api')
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py11
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/default-constructor/sb_process_info.py22
-rw-r--r--lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py63
3 files changed, 96 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py b/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py
index 4739df00085..bea9f5962d6 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/TestDefaultConstructorForAPIObjects.py
@@ -255,6 +255,17 @@ class APIDefaultConstructorTestCase(TestBase):
@add_test_categories(['pyapi'])
@no_debug_info_test
+ def test_SBProcessInfo(self):
+ obj = lldb.SBProcessInfo()
+ if self.TraceOn():
+ print(obj)
+ self.assertFalse(obj)
+ # Do fuzz testing on the invalid obj, it should not crash lldb.
+ import sb_process_info
+ sb_process_info.fuzz_obj(obj)
+
+ @add_test_categories(['pyapi'])
+ @no_debug_info_test
def test_SBSection(self):
obj = lldb.SBSection()
if self.TraceOn():
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/sb_process_info.py b/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/sb_process_info.py
new file mode 100644
index 00000000000..020ad4e1066
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/python_api/default-constructor/sb_process_info.py
@@ -0,0 +1,22 @@
+"""
+Fuzz tests an object after the default construction to make sure it does not crash lldb.
+"""
+
+import sys
+import lldb
+
+
+def fuzz_obj(obj):
+ obj.IsValid()
+ obj.GetName()
+ obj.GetExecutableFile()
+ obj.GetProcessID()
+ obj.GetUserID()
+ obj.GetGroupID()
+ obj.UserIDIsValid()
+ obj.GroupIDIsValid()
+ obj.GetEffectiveUserID()
+ obj.GetEffectiveGroupID()
+ obj.EffectiveUserIDIsValid()
+ obj.EffectiveGroupIDIsValid()
+ obj.GetParentProcessID()
diff --git a/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py b/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
index 1009536b370..bffbf431587 100644
--- a/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
+++ b/lldb/packages/Python/lldbsuite/test/python_api/process/TestProcessAPI.py
@@ -325,3 +325,66 @@ class ProcessAPITestCase(TestBase):
num = process.GetNumSupportedHardwareWatchpoints(error)
if self.TraceOn() and error.Success():
print("Number of supported hardware watchpoints: %d" % num)
+
+ @add_test_categories(['pyapi'])
+ @no_debug_info_test
+ def test_get_process_info(self):
+ """Test SBProcess::GetProcessInfo() API with a locally launched process."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Launch the process and stop at the entry point.
+ launch_info = lldb.SBLaunchInfo(None)
+ launch_info.SetWorkingDirectory(self.get_process_working_directory())
+ launch_flags = launch_info.GetLaunchFlags()
+ launch_flags |= lldb.eLaunchFlagStopAtEntry
+ launch_info.SetLaunchFlags(launch_flags)
+ error = lldb.SBError()
+ process = target.Launch(launch_info, error)
+
+ if not error.Success():
+ self.fail("Failed to launch process")
+
+ # Verify all process info can be retrieved successfully
+ process_info = process.GetProcessInfo()
+ self.assertTrue(process_info.IsValid())
+ file_spec = process_info.GetExecutableFile()
+ self.assertTrue(file_spec.IsValid())
+ process_name = process_info.GetName()
+ self.assertIsNotNone(process_name, "Process has a name")
+ 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")
+
+ if self.getPlatform() != 'windows':
+ self.assertTrue(process_info.UserIDIsValid())
+ self.assertNotEqual(
+ process_info.GetUserID(), lldb.UINT32_MAX,
+ "Process user ID is valid")
+ self.assertTrue(process_info.GroupIDIsValid())
+ self.assertNotEqual(
+ process_info.GetGroupID(), lldb.UINT32_MAX,
+ "Process group ID is valid")
+ self.assertTrue(process_info.EffectiveUserIDIsValid())
+ self.assertNotEqual(
+ process_info.GetEffectiveUserID(), lldb.UINT32_MAX,
+ "Process effective user ID is valid")
+ self.assertTrue(process_info.EffectiveGroupIDIsValid())
+ self.assertNotEqual(
+ process_info.GetEffectiveGroupID(), lldb.UINT32_MAX,
+ "Process effective group ID is valid")
+ self.assertNotEqual(
+ process_info.GetParentProcessID(), lldb.LLDB_INVALID_PROCESS_ID,
+ "Parent process ID is valid"
+ )
+
+ # Verify that a dead process doesn't yield stale process info
+ process.Kill()
+ process_info = process.GetProcessInfo()
+ self.assertFalse(process_info.IsValid())
OpenPOWER on IntegriCloud