Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1 | """ |
| 2 | LLDB module which provides the abstract base class of lldb test case. |
| 3 | |
| 4 | The concrete subclass can override lldbtest.TesBase in order to inherit the |
| 5 | common behavior for unitest.TestCase.setUp/tearDown implemented in this file. |
| 6 | |
| 7 | The subclass should override the attribute mydir in order for the python runtime |
| 8 | to locate the individual test cases when running as part of a large test suite |
| 9 | or when running each test case as a separate python invocation. |
| 10 | |
| 11 | ./dotest.py provides a test driver which sets up the environment to run the |
| 12 | entire test suite. Users who want to run a test case on its own can specify the |
| 13 | LLDB_TEST and PYTHONPATH environment variables, for example: |
| 14 | |
| 15 | $ export LLDB_TEST=$PWD |
| 16 | $ export PYTHONPATH=/Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:$LLDB_TEST |
| 17 | $ echo $LLDB_TEST |
| 18 | /Volumes/data/lldb/svn/trunk/test |
| 19 | $ echo $PYTHONPATH |
| 20 | /Volumes/data/lldb/svn/trunk/build/Debug/LLDB.framework/Resources/Python:/Volumes/data/lldb/svn/trunk/test |
| 21 | $ python function_types/TestFunctionTypes.py |
| 22 | . |
| 23 | ---------------------------------------------------------------------- |
| 24 | Ran 1 test in 0.363s |
| 25 | |
| 26 | OK |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 27 | $ LLDB_COMMAND_TRACE=YES python array_types/TestArrayTypes.py |
| 28 | LLDB_COMMAND_TRACE=YES python array_types/TestArrayTypes.py |
| 29 | runCmd: file /Volumes/data/lldb/svn/trunk/test/array_types/a.out |
| 30 | output: Current executable set to '/Volumes/data/lldb/svn/trunk/test/array_types/a.out' (x86_64). |
| 31 | |
| 32 | runCmd: breakpoint set -f main.c -l 42 |
| 33 | output: Breakpoint created: 1: file ='main.c', line = 42, locations = 1 |
| 34 | |
| 35 | runCmd: run |
| 36 | output: Launching '/Volumes/data/lldb/svn/trunk/test/array_types/a.out' (x86_64) |
| 37 | |
| 38 | runCmd: thread list |
| 39 | output: Process 24987 state is Stopped |
| 40 | thread #1: tid = 0x2e03, pc = 0x0000000100000df4, where = a.out`main + 612 at /Volumes/data/lldb/svn/trunk/test/array_types/main.c:45, stop reason = breakpoint 1.1, queue = com.apple.main-thread |
| 41 | |
| 42 | runCmd: breakpoint list |
| 43 | output: Current breakpoints: |
| 44 | 1: file ='main.c', line = 42, locations = 1, resolved = 1 |
| 45 | 1.1: where = a.out`main + 612 at /Volumes/data/lldb/svn/trunk/test/array_types/main.c:45, address = 0x0000000100000df4, resolved, hit count = 1 |
| 46 | |
| 47 | |
| 48 | runCmd: variable list strings |
| 49 | output: (char *[4]) strings = { |
| 50 | (char *) strings[0] = 0x0000000100000f0c "Hello", |
| 51 | (char *) strings[1] = 0x0000000100000f12 "Hola", |
| 52 | (char *) strings[2] = 0x0000000100000f17 "Bonjour", |
| 53 | (char *) strings[3] = 0x0000000100000f1f "Guten Tag" |
| 54 | } |
| 55 | |
| 56 | runCmd: variable list char_16 |
| 57 | output: (char [16]) char_16 = { |
| 58 | (char) char_16[0] = 'H', |
| 59 | (char) char_16[1] = 'e', |
| 60 | (char) char_16[2] = 'l', |
| 61 | (char) char_16[3] = 'l', |
| 62 | (char) char_16[4] = 'o', |
| 63 | (char) char_16[5] = ' ', |
| 64 | (char) char_16[6] = 'W', |
| 65 | (char) char_16[7] = 'o', |
| 66 | (char) char_16[8] = 'r', |
| 67 | (char) char_16[9] = 'l', |
| 68 | (char) char_16[10] = 'd', |
| 69 | (char) char_16[11] = '\n', |
| 70 | (char) char_16[12] = '\0', |
| 71 | (char) char_16[13] = '\0', |
| 72 | (char) char_16[14] = '\0', |
| 73 | (char) char_16[15] = '\0' |
| 74 | } |
| 75 | |
| 76 | runCmd: variable list ushort_matrix |
| 77 | output: (unsigned short [2][3]) ushort_matrix = { |
| 78 | (unsigned short [3]) ushort_matrix[0] = { |
| 79 | (unsigned short) ushort_matrix[0][0] = 0x0001, |
| 80 | (unsigned short) ushort_matrix[0][1] = 0x0002, |
| 81 | (unsigned short) ushort_matrix[0][2] = 0x0003 |
| 82 | }, |
| 83 | (unsigned short [3]) ushort_matrix[1] = { |
| 84 | (unsigned short) ushort_matrix[1][0] = 0x000b, |
| 85 | (unsigned short) ushort_matrix[1][1] = 0x0016, |
| 86 | (unsigned short) ushort_matrix[1][2] = 0x0021 |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | runCmd: variable list long_6 |
| 91 | output: (long [6]) long_6 = { |
| 92 | (long) long_6[0] = 1, |
| 93 | (long) long_6[1] = 2, |
| 94 | (long) long_6[2] = 3, |
| 95 | (long) long_6[3] = 4, |
| 96 | (long) long_6[4] = 5, |
| 97 | (long) long_6[5] = 6 |
| 98 | } |
| 99 | |
| 100 | . |
| 101 | ---------------------------------------------------------------------- |
| 102 | Ran 1 test in 0.349s |
| 103 | |
| 104 | OK |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 105 | $ |
| 106 | """ |
| 107 | |
| 108 | import os |
Johnny Chen | 029acae | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 109 | import sys |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 110 | import time |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 111 | import unittest2 |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 112 | import lldb |
| 113 | |
Johnny Chen | 96f08d5 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 114 | # |
| 115 | # Some commonly used assert messages. |
| 116 | # |
| 117 | |
| 118 | CURRENT_EXECUTABLE_SET = "Current executable set successfully" |
| 119 | |
Johnny Chen | 029acae | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 120 | RUN_STOPPED = "Process is launched and then stopped successfully" |
Johnny Chen | 96f08d5 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 121 | |
Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 122 | RUN_COMPLETED = "Process exited successfully" |
Johnny Chen | 96f08d5 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 123 | |
Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 124 | BREAKPOINT_CREATED = "Breakpoint created successfully" |
| 125 | |
Johnny Chen | 9b92c6e | 2010-08-17 21:33:31 +0000 | [diff] [blame] | 126 | BREAKPOINT_PENDING_CREATED = "Pending breakpoint created successfully" |
| 127 | |
Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 128 | BREAKPOINT_HIT_ONCE = "Breakpoint resolved with hit cout = 1" |
Johnny Chen | 96f08d5 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 129 | |
| 130 | STOPPED_DUE_TO_BREAKPOINT = "Process state is stopped due to breakpoint" |
| 131 | |
| 132 | STOPPED_DUE_TO_STEP_IN = "Process state is stopped due to step in" |
| 133 | |
Johnny Chen | 4917e10 | 2010-08-24 22:07:56 +0000 | [diff] [blame] | 134 | DATA_TYPES_DISPLAYED_CORRECTLY = "Data type(s) displayed correctly" |
| 135 | |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 136 | VALID_BREAKPOINT = "Got a valid breakpoint" |
| 137 | |
| 138 | VALID_PROCESS = "Got a valid process" |
| 139 | |
| 140 | VALID_TARGET = "Got a valid target" |
| 141 | |
Johnny Chen | 22b95b2 | 2010-08-25 19:00:04 +0000 | [diff] [blame] | 142 | VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly" |
Johnny Chen | 96f08d5 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 143 | |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 144 | |
Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 145 | # |
| 146 | # And a generic "Command '%s' returns successfully" message generator. |
| 147 | # |
| 148 | def CMD_MSG(command): |
| 149 | return "Command '%s' returns successfully" % (command) |
| 150 | |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 151 | # |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 152 | # Returns the enum from the input string. |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 153 | # |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 154 | def StopReasonEnum(string): |
| 155 | if string == "Invalid": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 156 | return 0 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 157 | elif string == "None": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 158 | return 1 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 159 | elif string == "Trace": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 160 | return 2 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 161 | elif string == "Breakpoint": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 162 | return 3 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 163 | elif string == "Watchpoint": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 164 | return 4 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 165 | elif string == "Signal": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 166 | return 5 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 167 | elif string == "Exception": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 168 | return 6 |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 169 | elif string == "PlanComplete": |
Johnny Chen | b4d1fff | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 170 | return 7 |
| 171 | else: |
| 172 | raise Exception("Unknown stopReason string") |
Johnny Chen | d85dae5 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 173 | |
Johnny Chen | f4ce288 | 2010-08-26 21:49:29 +0000 | [diff] [blame] | 174 | # |
Johnny Chen | 6264bc6 | 2010-08-27 18:08:58 +0000 | [diff] [blame^] | 175 | # Returns the stopReason string given an enum. |
| 176 | # |
| 177 | def StopReasonString(enum): |
| 178 | if enum == 0: |
| 179 | return "Invalid" |
| 180 | elif enum == 1: |
| 181 | return "None" |
| 182 | elif enum == 2: |
| 183 | return "Trace" |
| 184 | elif enum == 3: |
| 185 | return "Breakpoint" |
| 186 | elif enum == 4: |
| 187 | return "Watchpoint" |
| 188 | elif enum == 5: |
| 189 | return "Signal" |
| 190 | elif enum == 6: |
| 191 | return "Exception" |
| 192 | elif enum == 7: |
| 193 | return "PlanComplete" |
| 194 | else: |
| 195 | raise Exception("Unknown stopReason enum") |
| 196 | |
| 197 | # |
Johnny Chen | f4ce288 | 2010-08-26 21:49:29 +0000 | [diff] [blame] | 198 | # Returns an env variable array from the os.environ map object. |
| 199 | # |
| 200 | def EnvArray(): |
| 201 | return map(lambda k,v: k+"="+v, os.environ.keys(), os.environ.values()) |
| 202 | |
Johnny Chen | 9c10c18 | 2010-08-27 00:15:48 +0000 | [diff] [blame] | 203 | |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 204 | class TestBase(unittest2.TestCase): |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 205 | """This LLDB abstract base class is meant to be subclassed.""" |
| 206 | |
| 207 | # The concrete subclass should override this attribute. |
Johnny Chen | f8c723b | 2010-07-03 20:41:42 +0000 | [diff] [blame] | 208 | mydir = None |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 209 | |
Johnny Chen | ffde4fc | 2010-08-16 21:28:10 +0000 | [diff] [blame] | 210 | # State pertaining to the inferior process, if any. |
| 211 | runStarted = False |
| 212 | |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 213 | # Maximum allowed attempts when launching the inferior process. |
| 214 | # Can be overridden by the LLDB_MAX_LAUNCH_COUNT environment variable. |
| 215 | maxLaunchCount = 3; |
| 216 | |
| 217 | # Time to wait before the next launching attempt in second(s). |
| 218 | # Can be overridden by the LLDB_TIME_WAIT environment variable. |
| 219 | timeWait = 1.0; |
| 220 | |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 221 | # os.environ["LLDB_COMMAND_TRACE"], if set to "YES", will turn on this flag. |
| 222 | traceAlways = False; |
| 223 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 224 | def setUp(self): |
Johnny Chen | 6ead27f | 2010-08-07 01:13:18 +0000 | [diff] [blame] | 225 | #import traceback |
Johnny Chen | 88f8304 | 2010-08-05 21:23:45 +0000 | [diff] [blame] | 226 | #traceback.print_stack() |
| 227 | |
Johnny Chen | f8c723b | 2010-07-03 20:41:42 +0000 | [diff] [blame] | 228 | # Fail fast if 'mydir' attribute is not overridden. |
| 229 | if not self.mydir or len(self.mydir) == 0: |
| 230 | raise Exception("Subclasses must override the 'mydir' attribute.") |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 231 | # Save old working directory. |
| 232 | self.oldcwd = os.getcwd() |
| 233 | |
| 234 | # Change current working directory if ${LLDB_TEST} is defined. |
| 235 | # See also dotest.py which sets up ${LLDB_TEST}. |
| 236 | if ("LLDB_TEST" in os.environ): |
| 237 | os.chdir(os.path.join(os.environ["LLDB_TEST"], self.mydir)); |
| 238 | |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 239 | if "LLDB_MAX_LAUNCH_COUNT" in os.environ: |
| 240 | self.maxLaunchCount = int(os.environ["LLDB_MAX_LAUNCH_COUNT"]) |
| 241 | |
| 242 | if "LLDB_TIME_WAIT" in os.environ: |
| 243 | self.timeWait = float(os.environ["LLDB_TIME_WAIT"]) |
| 244 | |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 245 | if ("LLDB_COMMAND_TRACE" in os.environ and |
| 246 | os.environ["LLDB_COMMAND_TRACE"] == "YES"): |
| 247 | self.traceAlways = True |
| 248 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 249 | # Create the debugger instance if necessary. |
| 250 | try: |
| 251 | self.dbg = lldb.DBG |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 252 | except AttributeError: |
| 253 | self.dbg = lldb.SBDebugger.Create() |
Johnny Chen | f8c723b | 2010-07-03 20:41:42 +0000 | [diff] [blame] | 254 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 255 | if not self.dbg.IsValid(): |
| 256 | raise Exception('Invalid debugger instance') |
| 257 | |
| 258 | # We want our debugger to be synchronous. |
| 259 | self.dbg.SetAsync(False) |
| 260 | |
| 261 | # Retrieve the associated command interpreter instance. |
| 262 | self.ci = self.dbg.GetCommandInterpreter() |
| 263 | if not self.ci: |
| 264 | raise Exception('Could not get the command interpreter') |
| 265 | |
| 266 | # And the result object. |
| 267 | self.res = lldb.SBCommandReturnObject() |
| 268 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 269 | def tearDown(self): |
Johnny Chen | ffde4fc | 2010-08-16 21:28:10 +0000 | [diff] [blame] | 270 | # Finish the inferior process, if it was "run" previously. |
| 271 | if self.runStarted: |
| 272 | self.ci.HandleCommand("continue", self.res) |
| 273 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 274 | del self.dbg |
| 275 | |
| 276 | # Restore old working directory. |
| 277 | os.chdir(self.oldcwd) |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 278 | |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 279 | def runCmd(self, cmd, msg=None, check=True, trace=False): |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 280 | """ |
| 281 | Ask the command interpreter to handle the command and then check its |
| 282 | return status. |
| 283 | """ |
| 284 | # Fail fast if 'cmd' is not meaningful. |
| 285 | if not cmd or len(cmd) == 0: |
| 286 | raise Exception("Bad 'cmd' parameter encountered") |
Johnny Chen | 4f995f0 | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 287 | |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 288 | trace = (True if self.traceAlways else trace) |
| 289 | |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 290 | self.runStarted = (cmd.startswith("run") or |
| 291 | cmd.startswith("process launch")) |
Johnny Chen | 4f995f0 | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 292 | |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 293 | for i in range(self.maxLaunchCount if self.runStarted else 1): |
| 294 | self.ci.HandleCommand(cmd, self.res) |
Johnny Chen | 4f995f0 | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 295 | |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 296 | if trace: |
| 297 | print >> sys.stderr, "runCmd:", cmd |
| 298 | if self.res.Succeeded(): |
| 299 | print >> sys.stderr, "output:", self.res.GetOutput() |
| 300 | else: |
| 301 | print >> sys.stderr, self.res.GetError() |
Johnny Chen | 4f995f0 | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 302 | |
Johnny Chen | 029acae | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 303 | if self.res.Succeeded(): |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 304 | break |
Johnny Chen | 029acae | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 305 | else: |
Johnny Chen | 6557248 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 306 | if self.runStarted: |
| 307 | # Process launch failed, wait some time before the next try. |
| 308 | time.sleep(self.timeWait) |
Johnny Chen | 4f995f0 | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 309 | |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 310 | if check: |
| 311 | self.assertTrue(self.res.Succeeded(), |
| 312 | msg if msg else CMD_MSG(cmd)) |
| 313 | |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 314 | def expect(self, cmd, msg=None, startstr=None, substrs=None, trace=False): |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 315 | """ |
| 316 | Similar to runCmd; with additional expect style output matching ability. |
| 317 | |
| 318 | Ask the command interpreter to handle the command and then check its |
| 319 | return status. The 'msg' parameter specifies an informational assert |
| 320 | message. We expect the output from running the command to start with |
| 321 | 'startstr' and matches the substrings contained in 'substrs'. |
| 322 | """ |
Johnny Chen | e8b02f3 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 323 | |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 324 | trace = (True if self.traceAlways else trace) |
| 325 | |
Johnny Chen | e8b02f3 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 326 | # First run the command. |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 327 | self.runCmd(cmd, trace = (True if trace else False)) |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 328 | |
Johnny Chen | e8b02f3 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 329 | # Then compare the output against expected strings. |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 330 | output = self.res.GetOutput() |
| 331 | matched = output.startswith(startstr) if startstr else True |
Johnny Chen | ead35c8 | 2010-08-20 18:25:15 +0000 | [diff] [blame] | 332 | |
Johnny Chen | 3f3fb13 | 2010-08-24 23:48:10 +0000 | [diff] [blame] | 333 | if startstr and trace: |
| 334 | print >> sys.stderr, "Expecting start string:", startstr |
| 335 | print >> sys.stderr, "Matched" if matched else "Not matched" |
| 336 | print >> sys.stderr |
Johnny Chen | ead35c8 | 2010-08-20 18:25:15 +0000 | [diff] [blame] | 337 | |
Johnny Chen | 22b95b2 | 2010-08-25 19:00:04 +0000 | [diff] [blame] | 338 | if substrs and matched: |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 339 | for str in substrs: |
| 340 | matched = output.find(str) > 0 |
Johnny Chen | 3f3fb13 | 2010-08-24 23:48:10 +0000 | [diff] [blame] | 341 | if trace: |
| 342 | print >> sys.stderr, "Expecting sub string:", str |
| 343 | print >> sys.stderr, "Matched" if matched else "Not matched" |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 344 | if not matched: |
| 345 | break |
Johnny Chen | 3f3fb13 | 2010-08-24 23:48:10 +0000 | [diff] [blame] | 346 | if trace: |
| 347 | print >> sys.stderr |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 348 | |
Johnny Chen | e8b02f3 | 2010-08-20 19:17:39 +0000 | [diff] [blame] | 349 | self.assertTrue(matched, msg if msg else CMD_MSG(cmd)) |
Johnny Chen | 8df95eb | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 350 | |
Johnny Chen | a8b3cdd | 2010-08-25 22:52:45 +0000 | [diff] [blame] | 351 | def invoke(self, obj, name, trace=False): |
Johnny Chen | d8473bc | 2010-08-25 22:56:10 +0000 | [diff] [blame] | 352 | """Use reflection to call a method dynamically with no argument.""" |
Johnny Chen | a8b3cdd | 2010-08-25 22:52:45 +0000 | [diff] [blame] | 353 | |
| 354 | trace = (True if self.traceAlways else trace) |
| 355 | |
| 356 | method = getattr(obj, name) |
| 357 | import inspect |
| 358 | self.assertTrue(inspect.ismethod(method), |
| 359 | name + "is a method name of object: " + str(obj)) |
| 360 | result = method() |
| 361 | if self.traceAlways: |
| 362 | print str(method) + ":", result |
| 363 | return result |
Johnny Chen | 9c10c18 | 2010-08-27 00:15:48 +0000 | [diff] [blame] | 364 | |
| 365 | def DebugSBValue(self, frame, val): |
| 366 | """Debug print a SBValue object, if self.traceAlways is True.""" |
| 367 | if not self.traceAlways: |
| 368 | return |
| 369 | |
| 370 | err = sys.stderr |
| 371 | err.write(val.GetName() + ":\n") |
| 372 | err.write('\t' + "TypeName -> " + val.GetTypeName() + '\n') |
| 373 | err.write('\t' + "ByteSize -> " + str(val.GetByteSize()) + '\n') |
| 374 | err.write('\t' + "NumChildren -> " + str(val.GetNumChildren()) + '\n') |
| 375 | err.write('\t' + "Value -> " + str(val.GetValue(frame)) + '\n') |
| 376 | err.write('\t' + "Summary -> " + str(val.GetSummary(frame)) + '\n') |
| 377 | err.write('\t' + "IsPtrType -> " + str(val.TypeIsPtrType()) + '\n') |
| 378 | err.write('\t' + "Location -> " + val.GetLocation(frame) + '\n') |
| 379 | |
| 380 | |