[Lldb-commits] [lldb] [lldb/Plugins] Introduce Scripted Platform Plugin (PR #99814)

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Wed Jul 24 23:45:35 PDT 2024


================
@@ -0,0 +1,108 @@
+"""
+Test python scripted platform in lldb
+"""
+
+import os, shutil
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+
+class ScriptedPlatformTestCase(TestBase):
+    NO_DEBUG_INFO_TESTCASE = True
+
+    @skipUnlessDarwin
+    def test_python_plugin_package(self):
+        """Test that the lldb python module has a `plugins.scripted_platform`
+        package."""
+        self.expect(
+            "script import lldb.plugins",
+            substrs=["ModuleNotFoundError"],
+            matching=False,
+        )
+
+        self.expect("script dir(lldb.plugins)", substrs=["scripted_platform"])
+
+        self.expect(
+            "script import lldb.plugins.scripted_platform",
+            substrs=["ModuleNotFoundError"],
+            matching=False,
+        )
+
+        self.expect(
+            "script dir(lldb.plugins.scripted_platform)", substrs=["ScriptedPlatform"]
+        )
+
+        self.expect(
+            "script from lldb.plugins.scripted_platform import ScriptedPlatform",
+            substrs=["ImportError"],
+            matching=False,
+        )
+
+        self.expect(
+            "script dir(ScriptedPlatform)",
+            substrs=[
+                "attach_to_process",
+                "kill_process",
+                "launch_process",
+                "list_processes",
+            ],
+        )
+
+    @skipUnlessDarwin
+    def test_list_processes(self):
+        """Test that we can load and select an lldb scripted platform using the
+        SBAPI, check its process ID, parent, name & triple.
+        """
+        os.environ["SKIP_SCRIPTED_PLATFORM_SELECT"] = "1"
+
+        def cleanup():
+            del os.environ["SKIP_SCRIPTED_PLATFORM_SELECT"]
+
+        self.addTearDownHook(cleanup)
----------------
medismailben wrote:

I did the same for `ScriptedProcess` and `ScriptedThreadPlan`. I use that bit of logic to iterate quickly to import and instantiate the scripting extension in lldb (in interactive mode), to test things by hand. By setting the env variable, I don't have to change anything and it runs just fine in the test.

If you really feel strongly about it, I can get rid of it.

https://github.com/llvm/llvm-project/pull/99814


More information about the lldb-commits mailing list