75 lines · python
1"""2Test sending SIGINT to the embedded Python REPL.3"""4 5import os6 7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test.lldbpexpect import PExpectTest11 12 13class TestCase(PExpectTest):14 def start_python_repl(self):15 """Starts up the embedded Python REPL."""16 self.launch()17 # Start the embedded Python REPL via the 'script' command.18 self.child.send("script -l python --\n")19 # Wait for the Python REPL prompt.20 self.child.expect(">>>")21 22 # PExpect uses many timeouts internally and doesn't play well23 # under ASAN on a loaded machine..24 @skipIfAsan25 @skipIfWindows26 @skipIf(oslist=["linux"], archs=["arm$", "aarch64"])27 def test_while_evaluating_code(self):28 """Tests SIGINT handling while Python code is being evaluated."""29 self.start_python_repl()30 31 # Start a long-running command that we try to abort with SIGINT.32 # Note that we dont actually wait 10000s in this code as pexpect or33 # lit will kill the test way before that.34 self.child.send("import time; print('running' + 'now'); time.sleep(10000);\n")35 36 # Make sure the command is actually being evaluated at the moment by37 # looking at the string that the command is printing.38 # Don't check for a needle that also occurs in the program itself to39 # prevent that echoing will make this check pass unintentionally.40 self.child.expect("runningnow")41 42 # Send SIGINT to the LLDB process.43 self.child.sendintr()44 45 # This should get transformed to a KeyboardInterrupt which is the same46 # behaviour as the standalone Python REPL. It should also interrupt47 # the evaluation of our sleep statement.48 self.child.expect("KeyboardInterrupt")49 # Send EOF to quit the Python REPL.50 self.child.sendeof()51 52 self.quit()53 54 # PExpect uses many timeouts internally and doesn't play well55 # under ASAN on a loaded machine..56 @skipIfAsan57 # FIXME: On Linux the Python code that reads from stdin seems to block until58 # it has finished reading a line before handling any queued signals.59 @skipIf(hostoslist=["linux"])60 @skipIfWindows61 def test_while_waiting_on_input(self):62 """Tests SIGINT handling while the REPL is waiting on input from63 stdin."""64 self.start_python_repl()65 66 # Send SIGINT to the LLDB process.67 self.child.sendintr()68 # This should get transformed to a KeyboardInterrupt which is the same69 # behaviour as the standalone Python REPL.70 self.child.expect("KeyboardInterrupt")71 # Send EOF to quit the Python REPL.72 self.child.sendeof()73 74 self.quit()75