[Lldb-commits] [lldb] 6335deb - [lldb/test] Use SBPlatform info for lldbplatformutil.getPlatform()

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 29 02:30:18 PST 2022


Author: Pavel Labath
Date: 2022-11-29T11:29:58+01:00
New Revision: 6335deb68b1dd417da4dff4f36fc344d8656e81a

URL: https://github.com/llvm/llvm-project/commit/6335deb68b1dd417da4dff4f36fc344d8656e81a
DIFF: https://github.com/llvm/llvm-project/commit/6335deb68b1dd417da4dff4f36fc344d8656e81a.diff

LOG: [lldb/test] Use SBPlatform info for lldbplatformutil.getPlatform()

Previously, we just used the platform name. This worked mostly OK, but
it required adding special handling for any unusual (and potentially
downstream) platform plugins, as evidenced by the hardcoding of the
qemu-user platform.

The current implementation was added in
D121605/21c5bb0a636c23ec75b13681c0a6fdb03ecd9c0d, which this essentially
reverts and goes back to the previous method of retrieving the platform
name from the platform triple (the "OS" field).

The motivation for D121605 was the ability to retrieve the process
without constructing an SBDebugger object (which would be necessary in a
world where SBPlatforms are managed by SBDebuggers). However, this world
did not arrive (mainly due to other commitments on my part), and I now
think that if we do want to go in that direction, that we should just
create a dummy/empty SBDebugger object for holding the initial
SBPlatform.

One benefit of D121605 was the unification of getPlatform and
getHostPlatform code paths, and I preserve that benefit by unifying them
in the other direction -- using the host SBPlatform for getHostPlatform.

Differential Revision: https://reviews.llvm.org/D138430

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/dotest.py
    lldb/packages/Python/lldbsuite/test/lldbplatformutil.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 818e8f618afa7..db7a3450ffc4d 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -849,14 +849,14 @@ def checkDebugServerSupport():
     skip_msg = "Skipping %s tests, as they are not compatible with remote testing on this platform"
     if lldbplatformutil.platformIsDarwin():
         configuration.skip_categories.append("llgs")
-        if configuration.lldb_platform_name:
+        if lldb.remote_platform:
             # <rdar://problem/34539270>
             configuration.skip_categories.append("debugserver")
             if configuration.verbose:
                 print(skip_msg%"debugserver");
     else:
         configuration.skip_categories.append("debugserver")
-        if configuration.lldb_platform_name and lldbplatformutil.getPlatform() == "windows":
+        if lldb.remote_platform and lldbplatformutil.getPlatform() == "windows":
             configuration.skip_categories.append("llgs")
             if configuration.verbose:
                 print(skip_msg%"lldb-server");
@@ -891,14 +891,6 @@ def run_suite():
     lldb.SBDebugger.Initialize()
     lldb.SBDebugger.PrintStackTraceOnError()
 
-    checkLibcxxSupport()
-    checkLibstdcxxSupport()
-    checkWatchpointSupport()
-    checkDebugInfoSupport()
-    checkDebugServerSupport()
-    checkObjcSupport()
-    checkForkVForkSupport()
-
     # Use host platform by default.
     lldb.remote_platform = None
     lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()
@@ -957,8 +949,16 @@ def run_suite():
     # Note that it's not dotest's job to clean this directory.
     lldbutil.mkdir_p(configuration.test_build_dir)
 
+    checkLibcxxSupport()
+    checkLibstdcxxSupport()
+    checkWatchpointSupport()
+    checkDebugInfoSupport()
+    checkDebugServerSupport()
+    checkObjcSupport()
+    checkForkVForkSupport()
+
     skipped_categories_list = ", ".join(configuration.skip_categories)
-    print("Skipping the following test categories: {}".format(skipped_categories_list))
+    print("Skipping the following test categories: {}".format(configuration.skip_categories))
 
     for testdir in configuration.testdirs:
         for (dirpath, dirnames, filenames) in os.walk(testdir):

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 3f95e8054f789..56d402418d457 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -98,21 +98,23 @@ def finalize_build_dictionary(dictionary):
     return dictionary
 
 
+def _get_platform_os(p):
+    # Use the triple to determine the platform if set.
+    triple = p.GetTriple()
+    if triple:
+        platform = triple.split('-')[2]
+        if platform.startswith('freebsd'):
+            platform = 'freebsd'
+        elif platform.startswith('netbsd'):
+            platform = 'netbsd'
+        return platform
+
+    return ''
+
+
 def getHostPlatform():
     """Returns the host platform running the test suite."""
-    # Attempts to return a platform name matching a target Triple platform.
-    if sys.platform.startswith('linux'):
-        return 'linux'
-    elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
-        return 'windows'
-    elif sys.platform.startswith('darwin'):
-        return 'macosx'
-    elif sys.platform.startswith('freebsd'):
-        return 'freebsd'
-    elif sys.platform.startswith('netbsd'):
-        return 'netbsd'
-    else:
-        return sys.platform
+    return _get_platform_os(lldb.SBPlatform("host"))
 
 
 def getDarwinOSTriples():
@@ -130,16 +132,7 @@ def getPlatform():
             platform = 'ios'
         return platform
 
-    platform = configuration.lldb_platform_name
-    if platform is None:
-        platform = "host"
-    if platform == "qemu-user":
-        platform = "host"
-    if platform == "host":
-        return getHostPlatform()
-    if platform.startswith("remote-"):
-        return platform[7:]
-    return platform
+    return _get_platform_os(lldb.selected_platform)
 
 
 def platformIsDarwin():


        


More information about the lldb-commits mailing list