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