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 12 def setUp(self): 13 TestBase.setUp(self) 14 15 self.stdin_path = self.getBuildArtifact("stdin.txt") 16 17 with open(self.stdin_path, 'w') as input_handle: 18 input_handle.write("nonexistingcommand\nquit") 19 20 # Python will close the file descriptor if all references 21 # to the filehandle object lapse, so we need to keep one 22 # around. 23 self.filehandle = open(self.stdin_path, 'r') 24 self.dbg.SetInputFileHandle(self.filehandle, False) 25 26 # No need to track the output 27 self.devnull = open(os.devnull, 'w') 28 self.dbg.SetOutputFileHandle(self.devnull, False) 29 self.dbg.SetErrorFileHandle (self.devnull, False) 30 31 def test_run_session_with_error_and_quit_legacy(self): 32 """Run non-existing and quit command returns appropriate values""" 33 34 n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( 35 True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, 36 False) 37 38 self.assertGreater(n_errors, 0) 39 self.assertTrue(quit_requested) 40 self.assertFalse(has_crashed) 41 42 43class CommandRunInterpreterAPICase(TestBase): 44 45 NO_DEBUG_INFO_TESTCASE = True 46 47 def setUp(self): 48 TestBase.setUp(self) 49 50 self.stdin_path = self.getBuildArtifact("stdin.txt") 51 52 with open(self.stdin_path, 'w') as input_handle: 53 input_handle.write("nonexistingcommand\nquit") 54 55 self.dbg.SetInputFile(open(self.stdin_path, 'r')) 56 57 # No need to track the output 58 devnull = open(os.devnull, 'w') 59 self.dbg.SetOutputFile(devnull) 60 self.dbg.SetErrorFile(devnull) 61 62 def test_run_session_with_error_and_quit(self): 63 """Run non-existing and quit command returns appropriate values""" 64 65 n_errors, quit_requested, has_crashed = self.dbg.RunCommandInterpreter( 66 True, False, lldb.SBCommandInterpreterRunOptions(), 0, False, 67 False) 68 69 self.assertGreater(n_errors, 0) 70 self.assertTrue(quit_requested) 71 self.assertFalse(has_crashed) 72 73class SBCommandInterpreterRunOptionsCase(TestBase): 74 75 NO_DEBUG_INFO_TESTCASE = True 76 77 def test_command_interpreter_run_options(self): 78 """Test SBCommandInterpreterRunOptions default values, getters & setters """ 79 80 opts = lldb.SBCommandInterpreterRunOptions() 81 82 # Check getters with default values 83 self.assertEqual(opts.GetStopOnContinue(), False) 84 self.assertEqual(opts.GetStopOnError(), False) 85 self.assertEqual(opts.GetStopOnCrash(), False) 86 self.assertEqual(opts.GetEchoCommands(), True) 87 self.assertEqual(opts.GetPrintResults(), True) 88 self.assertEqual(opts.GetPrintErrors(), True) 89 self.assertEqual(opts.GetAddToHistory(), True) 90 91 # Invert values 92 opts.SetStopOnContinue(not opts.GetStopOnContinue()) 93 opts.SetStopOnError(not opts.GetStopOnError()) 94 opts.SetStopOnCrash(not opts.GetStopOnCrash()) 95 opts.SetEchoCommands(not opts.GetEchoCommands()) 96 opts.SetPrintResults(not opts.GetPrintResults()) 97 opts.SetPrintErrors(not opts.GetPrintErrors()) 98 opts.SetAddToHistory(not opts.GetAddToHistory()) 99 100 # Check the value changed 101 self.assertEqual(opts.GetStopOnContinue(), True) 102 self.assertEqual(opts.GetStopOnError(), True) 103 self.assertEqual(opts.GetStopOnCrash(), True) 104 self.assertEqual(opts.GetEchoCommands(), False) 105 self.assertEqual(opts.GetPrintResults(), False) 106 self.assertEqual(opts.GetPrintErrors(), False) 107 self.assertEqual(opts.GetAddToHistory(), False) 108