1import lldb
2from lldbsuite.test.lldbtest import *
3from lldbsuite.test.decorators import *
4from lldbsuite.test.gdbclientutils import *
5from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
6
7class TestIOSSimulator(GDBRemoteTestBase):
8
9    mydir = TestBase.compute_mydir(__file__)
10
11    """
12    Test that an ios simulator process is recognized as such.
13    """
14
15    class MyResponder(MockGDBServerResponder):
16        def __init__(self, host, process):
17            self.host_ostype = host
18            self.process_ostype = process
19            MockGDBServerResponder.__init__(self)
20
21        def respond(self, packet):
22            if packet == "qProcessInfo":
23                return self.qProcessInfo()
24            return MockGDBServerResponder.respond(self, packet)
25
26        def qHostInfo(self):
27            return "cputype:16777223;cpusubtype:8;ostype:%s;vendor:apple;os_version:10.15.4;maccatalyst_version:13.4;endian:little;ptrsize:8;"%self.host_ostype
28        def qProcessInfo(self):
29            return "pid:a860;parent-pid:d2a0;real-uid:1f5;real-gid:14;effective-uid:1f5;effective-gid:14;cputype:1000007;cpusubtype:8;ptrsize:8;ostype:%s;vendor:apple;endian:little;"%self.process_ostype
30        def vCont(self):
31            return "vCont;"
32
33    def platform_test(self, host, process, expected_triple):
34        self.server.responder = self.MyResponder(host, process)
35        if self.TraceOn():
36            self.runCmd("log enable gdb-remote packets")
37            self.addTearDownHook(lambda: self.runCmd("log disable gdb-remote packets"))
38
39        target = self.dbg.CreateTargetWithFileAndArch(None, None)
40        process = self.connect(target)
41        triple = target.GetTriple()
42        self.assertEqual(triple, expected_triple)
43
44    @skipIfRemote
45    def test_macos(self):
46        self.platform_test(host="macosx", process="macosx",
47                           expected_triple="x86_64h-apple-macosx-")
48
49    @skipIfRemote
50    def test_ios_sim(self):
51        self.platform_test(host="macosx", process="iossimulator",
52                           expected_triple="x86_64h-apple-ios-simulator")
53
54    @skipIfRemote
55    def test_catalyst(self):
56        self.platform_test(host="macosx", process="maccatalyst",
57                           expected_triple="x86_64h-apple-ios-macabi")
58
59    @skipIfRemote
60    def test_tvos_sim(self):
61        self.platform_test(host="macosx", process="tvossimulator",
62                           expected_triple="x86_64h-apple-tvos-simulator")
63
64    @skipIfRemote
65    def test_tvos_sim(self):
66        self.platform_test(host="macosx", process="watchossimulator",
67                           expected_triple="x86_64h-apple-watchos-simulator")
68