blob: bcc87ba062a474a215e6d1e4ac101d79c93c1ae1 [file] [log] [blame]
Enrico Granatacb2921d2011-08-24 17:45:40 +00001"""
2Test lldb Python commands.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class CmdPythonTestCase(TestBase):
11
Johnny Chenfc807f82011-10-14 17:37:38 +000012 mydir = os.path.join("functionalities", "command_script")
Enrico Granatacb2921d2011-08-24 17:45:40 +000013
14 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chenf1548d42012-04-06 00:56:05 +000015 @dsym_test
Enrico Granatacb2921d2011-08-24 17:45:40 +000016 def test_with_dsym (self):
17 self.buildDsym ()
18 self.pycmd_tests ()
19
Johnny Chenf1548d42012-04-06 00:56:05 +000020 @dwarf_test
Enrico Granatacb2921d2011-08-24 17:45:40 +000021 def test_with_dwarf (self):
22 self.buildDwarf ()
23 self.pycmd_tests ()
24
25 def pycmd_tests (self):
26 exe = os.path.join (os.getcwd(), "a.out")
27 self.expect("file " + exe,
28 patterns = [ "Current executable set to .*a.out" ])
29
30 self.runCmd("command source py_import")
31
Johnny Chen04a101d2011-10-12 17:50:41 +000032 # This is the function to remove the custom commands in order to have a
33 # clean slate for the next test case.
34 def cleanup():
35 self.runCmd('command script delete welcome', check=False)
36 self.runCmd('command script delete targetname', check=False)
37 self.runCmd('command script delete longwait', check=False)
Enrico Granata0a305db2011-11-07 22:57:04 +000038 self.runCmd('command script delete mysto', check=False)
39 self.runCmd('command script delete tell_sync', check=False)
40 self.runCmd('command script delete tell_async', check=False)
41 self.runCmd('command script delete tell_curr', check=False)
Johnny Chen1d9cb8a2011-12-14 20:40:27 +000042 self.runCmd('command script delete bug11569', check=False)
Johnny Chen04a101d2011-10-12 17:50:41 +000043
44 # Execute the cleanup function during test case tear down.
45 self.addTearDownHook(cleanup)
46
Johnny Chen3e15c4d2011-08-24 18:19:50 +000047 # We don't want to display the stdout if not in TraceOn() mode.
48 if not self.TraceOn():
49 self.HideStdout()
50
Enrico Granatacb2921d2011-08-24 17:45:40 +000051 self.expect('welcome Enrico',
52 substrs = ['Hello Enrico, welcome to LLDB']);
53
54 self.expect("help welcome",
55 substrs = ['Just a docstring for welcome_impl',
56 'A command that says hello to LLDB users'])
57
Enrico Granata08633ee2011-09-09 17:49:36 +000058 self.expect("help",
59 substrs = ['Run Python function welcome.welcome_impl',
60 'welcome'])
61
62 self.expect("help -a",
63 substrs = ['Run Python function welcome.welcome_impl',
64 'welcome'])
65
66 self.expect("help -u", matching=False,
67 substrs = ['Run Python function welcome.welcome_impl',
68 'welcome'])
69
Enrico Granatacb2921d2011-08-24 17:45:40 +000070 self.runCmd("command script delete welcome");
71
72 self.expect('welcome Enrico', matching=False, error=True,
73 substrs = ['Hello Enrico, welcome to LLDB']);
74
75 self.expect('targetname',
76 substrs = ['a.out'])
77
78 self.expect('targetname fail', error=True,
79 substrs = ['a test for error in command'])
80
81 self.expect('command script list',
82 substrs = ['targetname',
83 'Run Python function welcome.target_name_impl'])
84
85 self.expect("help targetname",
86 substrs = ['Run Python function welcome.target_name_imp',
Enrico Granata45034812012-04-25 00:13:06 +000087 'This command takes','\'raw\' input',
Enrico Granatacb2921d2011-08-24 17:45:40 +000088 'quote stuff'])
89
90 self.expect("longwait",
91 substrs = ['Done; if you saw the delays I am doing OK'])
92
Enrico Granata0a305db2011-11-07 22:57:04 +000093 self.runCmd("b main")
94 self.runCmd("run")
95 self.runCmd("mysto 3")
96 self.expect("frame variable array",
97 substrs = ['[0] = 79630','[1] = 388785018','[2] = 0'])
98 self.runCmd("mysto 3")
99 self.expect("frame variable array",
100 substrs = ['[0] = 79630','[4] = 388785018','[5] = 0'])
101
102# we cannot use the stepover command to check for async execution mode since LLDB
103# seems to get confused when events start to queue up
104 self.expect("tell_sync",
105 substrs = ['running sync'])
106 self.expect("tell_async",
107 substrs = ['running async'])
108 self.expect("tell_curr",
109 substrs = ['I am running','sync'])
110
111
Enrico Granatacb2921d2011-08-24 17:45:40 +0000112 self.runCmd("command script clear")
113
114 self.expect('command script list', matching=False,
115 substrs = ['targetname',
116 'longwait'])
117
Enrico Granata0a305db2011-11-07 22:57:04 +0000118 self.expect('command script add -f foobar frame', error=True,
119 substrs = ['cannot add command'])
120
Johnny Chen1d9cb8a2011-12-14 20:40:27 +0000121 # http://llvm.org/bugs/show_bug.cgi?id=11569
122 # LLDBSwigPythonCallCommand crashes when a command script returns an object
123 self.runCmd('command script add -f bug11569 bug11569')
124 # This should not crash.
125 self.runCmd('bug11569', check=False)
126
Enrico Granatacb2921d2011-08-24 17:45:40 +0000127if __name__ == '__main__':
128 import atexit
129 lldb.SBDebugger.Initialize()
130 atexit.register(lambda: lldb.SBDebugger.Terminate())
131 unittest2.main()
132