Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb Python commands. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class CmdPythonTestCase(TestBase): |
| 11 | |
Johnny Chen | fc807f8 | 2011-10-14 17:37:38 +0000 | [diff] [blame] | 12 | mydir = os.path.join("functionalities", "command_script") |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 13 | |
| 14 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 15 | @dsym_test |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 16 | def test_with_dsym (self): |
| 17 | self.buildDsym () |
| 18 | self.pycmd_tests () |
| 19 | |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 20 | @dwarf_test |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 21 | 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 Chen | 04a101d | 2011-10-12 17:50:41 +0000 | [diff] [blame] | 32 | # 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 Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 38 | 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 Chen | 1d9cb8a | 2011-12-14 20:40:27 +0000 | [diff] [blame] | 42 | self.runCmd('command script delete bug11569', check=False) |
Johnny Chen | 04a101d | 2011-10-12 17:50:41 +0000 | [diff] [blame] | 43 | |
| 44 | # Execute the cleanup function during test case tear down. |
| 45 | self.addTearDownHook(cleanup) |
| 46 | |
Johnny Chen | 3e15c4d | 2011-08-24 18:19:50 +0000 | [diff] [blame] | 47 | # We don't want to display the stdout if not in TraceOn() mode. |
| 48 | if not self.TraceOn(): |
| 49 | self.HideStdout() |
| 50 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 51 | 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 Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 58 | 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 Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 70 | 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 Granata | 4503481 | 2012-04-25 00:13:06 +0000 | [diff] [blame] | 87 | 'This command takes','\'raw\' input', |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 88 | 'quote stuff']) |
| 89 | |
| 90 | self.expect("longwait", |
| 91 | substrs = ['Done; if you saw the delays I am doing OK']) |
| 92 | |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 93 | 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 Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 112 | self.runCmd("command script clear") |
| 113 | |
| 114 | self.expect('command script list', matching=False, |
| 115 | substrs = ['targetname', |
| 116 | 'longwait']) |
| 117 | |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 118 | self.expect('command script add -f foobar frame', error=True, |
| 119 | substrs = ['cannot add command']) |
| 120 | |
Johnny Chen | 1d9cb8a | 2011-12-14 20:40:27 +0000 | [diff] [blame] | 121 | # 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 Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 127 | if __name__ == '__main__': |
| 128 | import atexit |
| 129 | lldb.SBDebugger.Initialize() |
| 130 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 131 | unittest2.main() |
| 132 | |