xref: /llvm-project/lldb/test/API/functionalities/gdb_remote_client/TestPlatformMacOSX.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1c22c7a61SJonas Devlieghereimport lldb
2c22c7a61SJonas Devliegherefrom lldbsuite.test.lldbtest import *
3c22c7a61SJonas Devliegherefrom lldbsuite.test.decorators import *
4c22c7a61SJonas Devliegherefrom lldbsuite.test.gdbclientutils import *
5c22c7a61SJonas Devliegherefrom lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
6c22c7a61SJonas Devlieghere
7c22c7a61SJonas Devlieghere
8c22c7a61SJonas Devlieghereclass TestPlatformMacOSX(GDBRemoteTestBase):
9c22c7a61SJonas Devlieghere    class MyResponder(MockGDBServerResponder):
10c22c7a61SJonas Devlieghere        def __init__(self, host):
11c22c7a61SJonas Devlieghere            self.host_ostype = host
12c22c7a61SJonas Devlieghere            MockGDBServerResponder.__init__(self)
13c22c7a61SJonas Devlieghere
14c22c7a61SJonas Devlieghere        def respond(self, packet):
15c22c7a61SJonas Devlieghere            if packet == "qProcessInfo":
16c22c7a61SJonas Devlieghere                return self.qProcessInfo()
17c22c7a61SJonas Devlieghere            return MockGDBServerResponder.respond(self, packet)
18c22c7a61SJonas Devlieghere
19c22c7a61SJonas Devlieghere        def qHostInfo(self):
20*2238dcc3SJonas Devlieghere            return (
21*2238dcc3SJonas Devlieghere                "cputype:16777223;cpusubtype:2;ostype:%s;vendor:apple;os_version:10.15.4;maccatalyst_version:13.4;endian:little;ptrsize:8;"
22*2238dcc3SJonas Devlieghere                % self.host_ostype
23*2238dcc3SJonas Devlieghere            )
24c22c7a61SJonas Devlieghere
25c22c7a61SJonas Devlieghere        def qProcessInfo(self):
26c22c7a61SJonas Devlieghere            return "pid:a860;parent-pid:d2a0;real-uid:1f5;real-gid:14;effective-uid:1f5;effective-gid:14;cputype:100000c;cpusubtype:2;ptrsize:8;ostype:ios;vendor:apple;endian:little;"
27c22c7a61SJonas Devlieghere
28c22c7a61SJonas Devlieghere        def vCont(self):
29c22c7a61SJonas Devlieghere            return "vCont;"
30c22c7a61SJonas Devlieghere
31c22c7a61SJonas Devlieghere    def platform_test(self, host, expected_triple, expected_platform):
32c22c7a61SJonas Devlieghere        self.server.responder = self.MyResponder(host)
33c22c7a61SJonas Devlieghere        if self.TraceOn():
34c22c7a61SJonas Devlieghere            self.runCmd("log enable gdb-remote packets")
35*2238dcc3SJonas Devlieghere            self.addTearDownHook(lambda: self.runCmd("log disable gdb-remote packets"))
36c22c7a61SJonas Devlieghere
37c22c7a61SJonas Devlieghere        target = self.dbg.CreateTargetWithFileAndArch(None, None)
38c22c7a61SJonas Devlieghere        process = self.connect(target)
39c22c7a61SJonas Devlieghere
40c22c7a61SJonas Devlieghere        triple = target.GetTriple()
41c22c7a61SJonas Devlieghere        self.assertEqual(triple, expected_triple)
42c22c7a61SJonas Devlieghere
43c22c7a61SJonas Devlieghere        platform = target.GetPlatform()
44c22c7a61SJonas Devlieghere        self.assertEqual(platform.GetName(), expected_platform)
45c22c7a61SJonas Devlieghere
46c22c7a61SJonas Devlieghere    @skipIfRemote
47c22c7a61SJonas Devlieghere    def test_ios(self):
48*2238dcc3SJonas Devlieghere        self.platform_test(
49*2238dcc3SJonas Devlieghere            host="ios",
50c22c7a61SJonas Devlieghere            expected_triple="arm64e-apple-ios-",
51*2238dcc3SJonas Devlieghere            expected_platform="remote-ios",
52*2238dcc3SJonas Devlieghere        )
53c22c7a61SJonas Devlieghere
54c22c7a61SJonas Devlieghere    @skipIfRemote
55c22c7a61SJonas Devlieghere    @skipUnlessDarwin
56c22c7a61SJonas Devlieghere    @skipUnlessArch("arm64")
57c22c7a61SJonas Devlieghere    def test_macos(self):
58*2238dcc3SJonas Devlieghere        self.platform_test(
59*2238dcc3SJonas Devlieghere            host="macosx", expected_triple="arm64e-apple-ios-", expected_platform="host"
60*2238dcc3SJonas Devlieghere        )
61