1"""
2Test lldb 'process connect' command.
3"""
4
5import os
6import unittest2
7import lldb
8import pexpect
9from lldbtest import *
10
11class ConnectRemoteTestCase(TestBase):
12
13    mydir = os.path.join("functionalities", "connect_remote")
14
15    def test_connect_remote(self):
16        """Test "process connect connect:://localhost:12345"."""
17
18        # First, we'll start a fake debugserver (a simple echo server).
19        fakeserver = pexpect.spawn('./EchoServer.py')
20
21        # Turn on logging for what the child sends back.
22        if self.TraceOn():
23            fakeserver.logfile_read = sys.stdout
24
25        # Schedule the fake debugserver to be shutting down during teardown.
26        def shutdown_fakeserver():
27            fakeserver.close()
28        self.addTearDownHook(shutdown_fakeserver)
29
30        # Wait until we receive the server ready message before continuing.
31        fakeserver.expect_exact('Listening on localhost:12345')
32
33        # Connect to the fake server....
34        if sys.platform.startswith('freebsd') or sys.platform.startswith("linux"):
35            self.runCmd("process connect -p gdb-remote connect://localhost:12345")
36        else:
37            self.runCmd("process connect connect://localhost:12345")
38
39
40if __name__ == '__main__':
41    import atexit
42    lldb.SBDebugger.Initialize()
43    atexit.register(lambda: lldb.SBDebugger.Terminate())
44    unittest2.main()
45