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):
1599451b44SJordan Rupprecht    mydir = TestBase.compute_mydir(__file__)
1668bb51acSPavel Labath    NO_DEBUG_INFO_TESTCASE = True
1799451b44SJordan Rupprecht
1868bb51acSPavel Labath    @skipIfRemote
1968bb51acSPavel Labath    @expectedFailureAll(oslist=["windows"]) # process modules not loaded
2099451b44SJordan Rupprecht    def test_target_auto_install_main_executable(self):
21*48e3da13SPavel Labath        if lldbgdbserverutils.get_lldb_server_exe() is None:
22*48e3da13SPavel Labath          self.skipTest("lldb-server not found")
2399451b44SJordan Rupprecht        self.build()
2499451b44SJordan Rupprecht
2568bb51acSPavel Labath        hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
2668bb51acSPavel Labath        listen_url = "[%s]:0"%hostname
2799451b44SJordan Rupprecht
2868bb51acSPavel Labath        port_file = self.getBuildArtifact("port")
2999451b44SJordan Rupprecht        commandline_args = [
3099451b44SJordan Rupprecht            "platform",
3199451b44SJordan Rupprecht            "--listen",
3299451b44SJordan Rupprecht            listen_url,
3368bb51acSPavel Labath            "--socket-file",
3468bb51acSPavel Labath            port_file]
3599451b44SJordan Rupprecht        self.spawnSubprocess(
3668bb51acSPavel Labath            lldbgdbserverutils.get_lldb_server_exe(),
3768bb51acSPavel Labath            commandline_args)
3899451b44SJordan Rupprecht
3968bb51acSPavel Labath        socket_id = lldbutil.wait_for_file_on_target(self, port_file)
4099451b44SJordan Rupprecht
4168bb51acSPavel Labath        new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
42a31130f6STatyana Krasnukha        self.dbg.SetSelectedPlatform(new_platform)
4399451b44SJordan Rupprecht
4468bb51acSPavel Labath        connect_url = "connect://[%s]:%s" % (hostname, socket_id)
4568bb51acSPavel Labath        connect_opts = lldb.SBPlatformConnectOptions(connect_url)
4668bb51acSPavel Labath        self.assertSuccess(new_platform.ConnectRemote(connect_opts))
4768bb51acSPavel Labath
4868bb51acSPavel Labath        wd = self.getBuildArtifact("wd")
4968bb51acSPavel Labath        os.mkdir(wd)
5068bb51acSPavel Labath        new_platform.SetWorkingDirectory(wd)
5168bb51acSPavel Labath
5268bb51acSPavel Labath
5368bb51acSPavel Labath        # Manually install the modified binary.
5468bb51acSPavel Labath        src_device = lldb.SBFileSpec(self.getBuildArtifact("a.device.out"))
5568bb51acSPavel Labath        dest = lldb.SBFileSpec(os.path.join(wd, "a.out"))
5668bb51acSPavel Labath        self.assertSuccess(new_platform.Put(src_device, dest))
5799451b44SJordan Rupprecht
5899451b44SJordan Rupprecht        # Test the default setting.
5935674976SPavel Labath        self.expect("settings show target.auto-install-main-executable",
6035674976SPavel Labath                substrs=["target.auto-install-main-executable (boolean) = true"],
6135674976SPavel Labath                msg="Default settings for target.auto-install-main-executable failed.")
6299451b44SJordan Rupprecht
6399451b44SJordan Rupprecht        # Disable the auto install.
6435674976SPavel Labath        self.runCmd("settings set target.auto-install-main-executable false")
6535674976SPavel Labath        self.expect("settings show target.auto-install-main-executable",
6635674976SPavel Labath            substrs=["target.auto-install-main-executable (boolean) = false"])
6799451b44SJordan Rupprecht
6899451b44SJordan Rupprecht        # Create the target with the original file.
6935674976SPavel Labath        self.runCmd("target create --remote-file %s %s "%
7068bb51acSPavel Labath                                        (dest.fullpath,
7135674976SPavel Labath                                            self.getBuildArtifact("a.out")))
7299451b44SJordan Rupprecht
73*48e3da13SPavel Labath        self.expect("process launch", substrs=["exited with status = 74"])
74