1"""Test the RunCommandInterpreter API.""" 2 3import os 4import lldb 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7 8class CommandRunInterpreterLegacyAPICase(TestBase): 9 10 NO_DEBUG_INFO_TESTCASE = True 11 mydir = TestBase.compute_mydir(__file__) 12 13 @skipIfReproducer # lldb::FileSP used in typemap cannot be instrumented. 14 def setUp(self): 15 TestBase.setUp(self) 16 17 self.stdin_path = self.getBuildArtifact("stdin.txt") 18 19 with open(self.stdin_path, 'w') as input_handle: 20 input_handle.write("nonexistingcommand\nquit") 21 22 # Python will close the file descriptor if all references 23 # to the filehandle object lapse, so we need to keep one 24 # around. 25 self.filehandle = open(self.stdin_path, 'r') 26 self.dbg.SetInputFileHandle(self.filehandle, False) 27 28 # No need to track the output 29 self.devnull = open(os.devnull, 'w') 30 self.dbg.SetOutputFileHandle(self.devnull, False) 31 self.dbg.SetErrorFileHandle (self.devnull, False) 32 33 @add_test_categories(['pyapi']) 34 def test_run_session_with_error_and_quit_legacy(self): 35 """Run non-existing and quit command returns appropriate values""" 36 37 n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( 38 True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, 39 False) 40 41 self.assertGreater(n_errors, 0) 42 self.assertTrue(quit_requested) 43 self.assertFalse(has_crashed) 44 45 46class CommandRunInterpreterAPICase(TestBase): 47 48 NO_DEBUG_INFO_TESTCASE = True 49 mydir = TestBase.compute_mydir(__file__) 50 51 @skipIfReproducer # lldb::FileSP used in typemap cannot be instrumented. 52 def setUp(self): 53 TestBase.setUp(self) 54 55 self.stdin_path = self.getBuildArtifact("stdin.txt") 56 57 with open(self.stdin_path, 'w') as input_handle: 58 input_handle.write("nonexistingcommand\nquit") 59 60 self.dbg.SetInputFile(open(self.stdin_path, 'r')) 61 62 # No need to track the output 63 devnull = open(os.devnull, 'w') 64 self.dbg.SetOutputFile(devnull) 65 self.dbg.SetErrorFile(devnull) 66 67 @add_test_categories(['pyapi']) 68 def test_run_session_with_error_and_quit(self): 69 """Run non-existing and quit command returns appropriate values""" 70 71 n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( 72 True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, 73 False) 74 75 self.assertGreater(n_errors, 0) 76 self.assertTrue(quit_requested) 77 self.assertFalse(has_crashed) 78