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