brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · a73322c Raw
57 lines · python
1"""2Test that if you exec lldb with the stdio file handles3closed, it is able to exit without hanging.4"""5 6 7import lldb8import os9import sys10import socket11 12if os.name != "nt":13    import fcntl14 15import lldbsuite.test.lldbutil as lldbutil16from lldbsuite.test.lldbtest import *17from lldbsuite.test.decorators import *18 19class TestDriverWithClosedSTDIO(TestBase):20    # If your test case doesn't stress debug info, then21    # set this to true.  That way it won't be run once for22    # each debug info format.23    NO_DEBUG_INFO_TESTCASE = True24 25    # Windows doesn't have the fcntl module, so we can't run this26    # test there.27    @skipIf(hostoslist=["windows"])28    def test_run_lldb_and_wait(self):29        """This test forks, closes the stdio channels and exec's lldb.30        Then it waits for it to exit and asserts it did that successfully"""31        pid = os.fork()32        if pid == 0:33            fcntl.fcntl(sys.stdin, fcntl.F_SETFD, fcntl.FD_CLOEXEC)34            fcntl.fcntl(sys.stdout, fcntl.F_SETFD, fcntl.FD_CLOEXEC)35            fcntl.fcntl(sys.stderr, fcntl.F_SETFD, fcntl.FD_CLOEXEC)36            lldb = lldbtest_config.lldbExec37            print(f"About to run: {lldb}")38            os.execlp(39                lldb,40                lldb,41                "-x",42                "-o",43                "script print(lldb.debugger.GetNumTargets())",44                "--batch",45            )46        else:47            if pid == -1:48                print("Couldn't fork a process.")49                return50            ret_pid, status = os.waitpid(pid, 0)51            # We're really just checking that lldb doesn't stall.52            # At the time this test was written, if you close stdin53            # in an asserts build, lldb aborts.  So handle both54            # of those cases.  The failure will just be that the55            # waitpid doesn't return, and the test times out.56            self.assertFalse(os.WIFSTOPPED(status), "We either exited or crashed.")57