199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest target commands: target.auto-install-main-executable.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
568bb51acSPavel Labathimport socket
699451b44SJordan Rupprechtimport time
768bb51acSPavel Labathimport lldbgdbserverutils
899451b44SJordan Rupprecht
999451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
1099451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1199451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1299451b44SJordan Rupprecht
1399451b44SJordan Rupprecht
1468bb51acSPavel Labathclass TestAutoInstallMainExecutable(TestBase):
1568bb51acSPavel Labath    NO_DEBUG_INFO_TESTCASE = True
1699451b44SJordan Rupprecht
1768bb51acSPavel Labath    @skipIfRemote
18*58917054SStella Stamenova    @skipIfWindows # This test is flaky on Windows
1999451b44SJordan Rupprecht    def test_target_auto_install_main_executable(self):
2048e3da13SPavel Labath        if lldbgdbserverutils.get_lldb_server_exe() is None:
2148e3da13SPavel Labath          self.skipTest("lldb-server not found")
2299451b44SJordan Rupprecht        self.build()
2399451b44SJordan Rupprecht
2468bb51acSPavel Labath        hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
2568bb51acSPavel Labath        listen_url = "[%s]:0"%hostname
2699451b44SJordan Rupprecht
2768bb51acSPavel Labath        port_file = self.getBuildArtifact("port")
2899451b44SJordan Rupprecht        commandline_args = [
2999451b44SJordan Rupprecht            "platform",
3099451b44SJordan Rupprecht            "--listen",
3199451b44SJordan Rupprecht            listen_url,
3268bb51acSPavel Labath            "--socket-file",
3368bb51acSPavel Labath            port_file]
3499451b44SJordan Rupprecht        self.spawnSubprocess(
3568bb51acSPavel Labath            lldbgdbserverutils.get_lldb_server_exe(),
3668bb51acSPavel Labath            commandline_args)
3799451b44SJordan Rupprecht
3868bb51acSPavel Labath        socket_id = lldbutil.wait_for_file_on_target(self, port_file)
3999451b44SJordan Rupprecht
4068bb51acSPavel Labath        new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
41a31130f6STatyana Krasnukha        self.dbg.SetSelectedPlatform(new_platform)
4299451b44SJordan Rupprecht
4368bb51acSPavel Labath        connect_url = "connect://[%s]:%s" % (hostname, socket_id)
4468bb51acSPavel Labath        connect_opts = lldb.SBPlatformConnectOptions(connect_url)
4568bb51acSPavel Labath        self.assertSuccess(new_platform.ConnectRemote(connect_opts))
4668bb51acSPavel Labath
4768bb51acSPavel Labath        wd = self.getBuildArtifact("wd")
4868bb51acSPavel Labath        os.mkdir(wd)
4968bb51acSPavel Labath        new_platform.SetWorkingDirectory(wd)
5068bb51acSPavel Labath
5168bb51acSPavel Labath
5268bb51acSPavel Labath        # Manually install the modified binary.
5368bb51acSPavel Labath        src_device = lldb.SBFileSpec(self.getBuildArtifact("a.device.out"))
5468bb51acSPavel Labath        dest = lldb.SBFileSpec(os.path.join(wd, "a.out"))
5568bb51acSPavel Labath        self.assertSuccess(new_platform.Put(src_device, dest))
5699451b44SJordan Rupprecht
5799451b44SJordan Rupprecht        # Test the default setting.
5835674976SPavel Labath        self.expect("settings show target.auto-install-main-executable",
5935674976SPavel Labath                substrs=["target.auto-install-main-executable (boolean) = true"],
6035674976SPavel Labath                msg="Default settings for target.auto-install-main-executable failed.")
6199451b44SJordan Rupprecht
6299451b44SJordan Rupprecht        # Disable the auto install.
6335674976SPavel Labath        self.runCmd("settings set target.auto-install-main-executable false")
6435674976SPavel Labath        self.expect("settings show target.auto-install-main-executable",
6535674976SPavel Labath            substrs=["target.auto-install-main-executable (boolean) = false"])
6699451b44SJordan Rupprecht
6799451b44SJordan Rupprecht        # Create the target with the original file.
6835674976SPavel Labath        self.runCmd("target create --remote-file %s %s "%
6968bb51acSPavel Labath                                        (dest.fullpath,
7035674976SPavel Labath                                            self.getBuildArtifact("a.out")))
7199451b44SJordan Rupprecht
7248e3da13SPavel Labath        self.expect("process launch", substrs=["exited with status = 74"])
73