TestCommandInterpreterAPI.py revision 805fec7ec90a09b94bc4515fcac9b2b03bae153b
1"""Test the SBCommandInterpreter APIs.""" 2 3import os 4import unittest2 5import lldb 6import pexpect 7from lldbtest import * 8 9class CommandInterpreterAPICase(TestBase): 10 11 mydir = os.path.join("python_api", "interpreter") 12 13 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 14 @python_api_test 15 def test_with_dsym_and_run_command(self): 16 """Test the SBCommandInterpreter APIs.""" 17 self.buildDsym() 18 self.command_interpreter_api() 19 20 @python_api_test 21 def test_with_dwarf_and_process_launch_api(self): 22 """Test the SBCommandInterpreter APIs.""" 23 self.buildDwarf() 24 self.command_interpreter_api() 25 26 def setUp(self): 27 # Call super's setUp(). 28 TestBase.setUp(self) 29 # Find the line number to break on inside main.cpp. 30 self.line = line_number('main.c', 'Hello world.') 31 32 def command_interpreter_api(self): 33 """Test the SBCommandInterpreter APIs.""" 34 exe = os.path.join(os.getcwd(), "a.out") 35 36 # Create a target by the debugger. 37 target = self.dbg.CreateTarget(exe) 38 self.assertTrue(target, VALID_TARGET) 39 40 # Retrieve the associated command interpreter from our debugger. 41 ci = self.dbg.GetCommandInterpreter() 42 self.assertTrue(ci, VALID_COMMAND_INTERPRETER) 43 44 # Exercise some APIs.... 45 46 self.assertTrue(ci.HasCommands()) 47 self.assertTrue(ci.HasAliases()) 48 self.assertTrue(ci.HasAliasOptions()) 49 self.assertTrue(ci.CommandExists("breakpoint")) 50 self.assertTrue(ci.CommandExists("target")) 51 self.assertTrue(ci.CommandExists("platform")) 52 self.assertTrue(ci.AliasExists("file")) 53 self.assertTrue(ci.AliasExists("run")) 54 self.assertTrue(ci.AliasExists("bt")) 55 56 res = lldb.SBCommandReturnObject() 57 ci.HandleCommand("breakpoint set -f main.c -l %d" % self.line, res) 58 self.assertTrue(res.Succeeded()) 59 ci.HandleCommand("process launch", res) 60 self.assertTrue(res.Succeeded()) 61 62 # Assigning to self.process so it gets cleaned up during test tear down. 63 self.process = ci.GetProcess() 64 self.assertTrue(self.process) 65 66 import lldbutil 67 if self.process.GetState() != lldb.eStateStopped: 68 self.fail("Process should be in the 'stopped' state, " 69 "instead the actual state is: '%s'" % 70 lldbutil.state_type_to_str(self.process.GetState())) 71 72 if self.TraceOn(): 73 lldbutil.print_stacktraces(self.process) 74 75 76if __name__ == '__main__': 77 import atexit 78 lldb.SBDebugger.Initialize() 79 atexit.register(lambda: lldb.SBDebugger.Terminate()) 80 unittest2.main() 81