xref: /llvm-project/lldb/test/API/functionalities/tty/TestTerminal.py (revision 5b386158aacac4b41126983a5379d36ed413d0ea)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest lldb command aliases.
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
5*5b386158SJordan Rupprechtimport unittest
699451b44SJordan Rupprechtimport os
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprecht
1399451b44SJordan Rupprechtclass LaunchInTerminalTestCase(TestBase):
1499451b44SJordan Rupprecht    # Darwin is the only platform that I know of that supports optionally launching
1599451b44SJordan Rupprecht    # a program in a separate terminal window. It would be great if other platforms
1699451b44SJordan Rupprecht    # added support for this.
1799451b44SJordan Rupprecht    @skipUnlessDarwin
1899451b44SJordan Rupprecht    # If the test is being run under sudo, the spawned terminal won't retain that elevated
1999451b44SJordan Rupprecht    # privilege so it can't open the socket to talk back to the test case
20*5b386158SJordan Rupprecht    @unittest.skipIf(
212238dcc3SJonas Devlieghere        hasattr(os, "geteuid") and os.geteuid() == 0, "test cannot be run as root"
222238dcc3SJonas Devlieghere    )
2399451b44SJordan Rupprecht    # Do we need to disable this test if the testsuite is being run on a remote system?
2499451b44SJordan Rupprecht    # This env var is only defined when the shell is running in a local mac
2599451b44SJordan Rupprecht    # terminal window
26*5b386158SJordan Rupprecht    @unittest.skipUnless(
272238dcc3SJonas Devlieghere        "TERM_PROGRAM" in os.environ, "test must be run on local system"
282238dcc3SJonas Devlieghere    )
2999451b44SJordan Rupprecht    @no_debug_info_test
3099451b44SJordan Rupprecht    def test_launch_in_terminal(self):
3199451b44SJordan Rupprecht        self.build()
3299451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
3399451b44SJordan Rupprecht
3499451b44SJordan Rupprecht        target = self.dbg.CreateTarget(exe)
3599451b44SJordan Rupprecht        launch_info = lldb.SBLaunchInfo(["-lAF", "/tmp/"])
3699451b44SJordan Rupprecht        launch_info.SetLaunchFlags(
372238dcc3SJonas Devlieghere            lldb.eLaunchFlagLaunchInTTY | lldb.eLaunchFlagCloseTTYOnExit
382238dcc3SJonas Devlieghere        )
3999451b44SJordan Rupprecht        error = lldb.SBError()
4099451b44SJordan Rupprecht        process = target.Launch(launch_info, error)
4199451b44SJordan Rupprecht        print("Error was: %s." % (error.GetCString()))
4299451b44SJordan Rupprecht        self.assertTrue(
4399451b44SJordan Rupprecht            error.Success(),
442238dcc3SJonas Devlieghere            "Make sure launch happened successfully in a terminal window",
452238dcc3SJonas Devlieghere        )
4699451b44SJordan Rupprecht        # Running in synchronous mode our process should have run and already
4799451b44SJordan Rupprecht        # exited by the time target.Launch() returns
481b8c7352SJonas Devlieghere        self.assertState(process.GetState(), lldb.eStateExited)
49