Johnny Chen | bf6ffa3 | 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 |
Johnny Chen | c98892e | 2012-05-16 20:41:28 +0000 | [diff] [blame] | 12 | entire of part of the test suite . Example: |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 13 | |
Johnny Chen | c98892e | 2012-05-16 20:41:28 +0000 | [diff] [blame] | 14 | # Exercises the test suite in the types directory.... |
| 15 | /Volumes/data/lldb/svn/ToT/test $ ./dotest.py -A x86_64 types |
Johnny Chen | 57b4738 | 2010-09-02 22:25:47 +0000 | [diff] [blame] | 16 | ... |
Johnny Chen | d0190a6 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 17 | |
Johnny Chen | c98892e | 2012-05-16 20:41:28 +0000 | [diff] [blame] | 18 | Session logs for test failures/errors/unexpected successes will go into directory '2012-05-16-13_35_42' |
| 19 | Command invoked: python ./dotest.py -A x86_64 types |
| 20 | compilers=['clang'] |
Johnny Chen | d0190a6 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 21 | |
Johnny Chen | c98892e | 2012-05-16 20:41:28 +0000 | [diff] [blame] | 22 | Configuration: arch=x86_64 compiler=clang |
Johnny Chen | d0190a6 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 23 | ---------------------------------------------------------------------- |
Johnny Chen | c98892e | 2012-05-16 20:41:28 +0000 | [diff] [blame] | 24 | Collected 72 tests |
| 25 | |
| 26 | ........................................................................ |
| 27 | ---------------------------------------------------------------------- |
| 28 | Ran 72 tests in 135.468s |
Johnny Chen | d0190a6 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 29 | |
| 30 | OK |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 31 | $ |
| 32 | """ |
| 33 | |
Johnny Chen | 90312a8 | 2010-09-21 22:34:45 +0000 | [diff] [blame] | 34 | import os, sys, traceback |
Enrico Granata | 7e137e3 | 2012-10-24 18:14:21 +0000 | [diff] [blame] | 35 | import os.path |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 36 | import re |
Daniel Malea | 6920746 | 2013-06-05 21:07:02 +0000 | [diff] [blame] | 37 | import signal |
Johnny Chen | 8952a2d | 2010-08-30 21:35:00 +0000 | [diff] [blame] | 38 | from subprocess import * |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 39 | import StringIO |
Johnny Chen | f2b7023 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 40 | import time |
Johnny Chen | a33a93c | 2010-08-30 23:08:52 +0000 | [diff] [blame] | 41 | import types |
Johnny Chen | 7325883 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 42 | import unittest2 |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 43 | import lldb |
| 44 | |
Johnny Chen | 707b3c9 | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 45 | # See also dotest.parseOptionsAndInitTestdirs(), where the environment variables |
Johnny Chen | d2047fa | 2011-01-19 18:18:47 +0000 | [diff] [blame] | 46 | # LLDB_COMMAND_TRACE and LLDB_DO_CLEANUP are set from '-t' and '-r dir' options. |
Johnny Chen | 707b3c9 | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 47 | |
| 48 | # By default, traceAlways is False. |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 49 | if "LLDB_COMMAND_TRACE" in os.environ and os.environ["LLDB_COMMAND_TRACE"]=="YES": |
| 50 | traceAlways = True |
| 51 | else: |
| 52 | traceAlways = False |
| 53 | |
Johnny Chen | 707b3c9 | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 54 | # By default, doCleanup is True. |
| 55 | if "LLDB_DO_CLEANUP" in os.environ and os.environ["LLDB_DO_CLEANUP"]=="NO": |
| 56 | doCleanup = False |
| 57 | else: |
| 58 | doCleanup = True |
| 59 | |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 60 | |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 61 | # |
| 62 | # Some commonly used assert messages. |
| 63 | # |
| 64 | |
Johnny Chen | aa90292 | 2010-09-17 22:45:27 +0000 | [diff] [blame] | 65 | COMMAND_FAILED_AS_EXPECTED = "Command has failed as expected" |
| 66 | |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 67 | CURRENT_EXECUTABLE_SET = "Current executable set successfully" |
| 68 | |
Johnny Chen | 7d1d753 | 2010-09-02 21:23:12 +0000 | [diff] [blame] | 69 | PROCESS_IS_VALID = "Process is valid" |
| 70 | |
| 71 | PROCESS_KILLED = "Process is killed successfully" |
| 72 | |
Johnny Chen | d5f66fc | 2010-12-23 01:12:19 +0000 | [diff] [blame] | 73 | PROCESS_EXITED = "Process exited successfully" |
| 74 | |
| 75 | PROCESS_STOPPED = "Process status should be stopped" |
| 76 | |
Johnny Chen | 5ee8819 | 2010-08-27 23:47:36 +0000 | [diff] [blame] | 77 | RUN_SUCCEEDED = "Process is launched successfully" |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 78 | |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 79 | RUN_COMPLETED = "Process exited successfully" |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 80 | |
Johnny Chen | 67af43f | 2010-10-05 19:27:32 +0000 | [diff] [blame] | 81 | BACKTRACE_DISPLAYED_CORRECTLY = "Backtrace displayed correctly" |
| 82 | |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 83 | BREAKPOINT_CREATED = "Breakpoint created successfully" |
| 84 | |
Johnny Chen | f10af38 | 2010-12-04 00:07:24 +0000 | [diff] [blame] | 85 | BREAKPOINT_STATE_CORRECT = "Breakpoint state is correct" |
| 86 | |
Johnny Chen | e76896c | 2010-08-17 21:33:31 +0000 | [diff] [blame] | 87 | BREAKPOINT_PENDING_CREATED = "Pending breakpoint created successfully" |
| 88 | |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 89 | BREAKPOINT_HIT_ONCE = "Breakpoint resolved with hit cout = 1" |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 90 | |
Johnny Chen | 703dbd0 | 2010-09-30 17:06:24 +0000 | [diff] [blame] | 91 | BREAKPOINT_HIT_TWICE = "Breakpoint resolved with hit cout = 2" |
| 92 | |
Johnny Chen | 164f1e1 | 2010-10-15 18:07:09 +0000 | [diff] [blame] | 93 | BREAKPOINT_HIT_THRICE = "Breakpoint resolved with hit cout = 3" |
| 94 | |
Greg Clayton | 5db6b79 | 2012-10-24 18:24:14 +0000 | [diff] [blame] | 95 | MISSING_EXPECTED_REGISTERS = "At least one expected register is unavailable." |
| 96 | |
Johnny Chen | 89109ed1 | 2011-06-27 20:05:23 +0000 | [diff] [blame] | 97 | OBJECT_PRINTED_CORRECTLY = "Object printed correctly" |
| 98 | |
Johnny Chen | 5b3a357 | 2010-12-09 18:22:12 +0000 | [diff] [blame] | 99 | SOURCE_DISPLAYED_CORRECTLY = "Source code displayed correctly" |
| 100 | |
Johnny Chen | c70b02a | 2010-09-22 23:00:20 +0000 | [diff] [blame] | 101 | STEP_OUT_SUCCEEDED = "Thread step-out succeeded" |
| 102 | |
Johnny Chen | 1691a16 | 2011-04-15 16:44:48 +0000 | [diff] [blame] | 103 | STOPPED_DUE_TO_EXC_BAD_ACCESS = "Process should be stopped due to bad access exception" |
| 104 | |
Ashok Thirumurthi | b4e5134 | 2013-05-17 15:35:15 +0000 | [diff] [blame] | 105 | STOPPED_DUE_TO_ASSERT = "Process should be stopped due to an assertion" |
| 106 | |
Johnny Chen | 5d6c464 | 2010-11-10 23:46:38 +0000 | [diff] [blame] | 107 | STOPPED_DUE_TO_BREAKPOINT = "Process should be stopped due to breakpoint" |
Johnny Chen | de0338b | 2010-11-10 20:20:06 +0000 | [diff] [blame] | 108 | |
Johnny Chen | 5d6c464 | 2010-11-10 23:46:38 +0000 | [diff] [blame] | 109 | STOPPED_DUE_TO_BREAKPOINT_WITH_STOP_REASON_AS = "%s, %s" % ( |
| 110 | STOPPED_DUE_TO_BREAKPOINT, "instead, the actual stop reason is: '%s'") |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 111 | |
Johnny Chen | 2e431ce | 2010-10-20 18:38:48 +0000 | [diff] [blame] | 112 | STOPPED_DUE_TO_BREAKPOINT_CONDITION = "Stopped due to breakpoint condition" |
| 113 | |
Johnny Chen | 0a3d1ca | 2010-12-13 21:49:58 +0000 | [diff] [blame] | 114 | STOPPED_DUE_TO_BREAKPOINT_IGNORE_COUNT = "Stopped due to breakpoint and ignore count" |
| 115 | |
Johnny Chen | c066ab4 | 2010-10-14 01:22:03 +0000 | [diff] [blame] | 116 | STOPPED_DUE_TO_SIGNAL = "Process state is stopped due to signal" |
| 117 | |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 118 | STOPPED_DUE_TO_STEP_IN = "Process state is stopped due to step in" |
| 119 | |
Johnny Chen | f68cc12 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 120 | STOPPED_DUE_TO_WATCHPOINT = "Process should be stopped due to watchpoint" |
| 121 | |
Johnny Chen | 3c884a0 | 2010-08-24 22:07:56 +0000 | [diff] [blame] | 122 | DATA_TYPES_DISPLAYED_CORRECTLY = "Data type(s) displayed correctly" |
| 123 | |
Johnny Chen | 5fca8ca | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 124 | VALID_BREAKPOINT = "Got a valid breakpoint" |
| 125 | |
Johnny Chen | 5bfb8ee | 2010-10-22 18:10:25 +0000 | [diff] [blame] | 126 | VALID_BREAKPOINT_LOCATION = "Got a valid breakpoint location" |
| 127 | |
Johnny Chen | 7209d84f | 2011-05-06 23:26:12 +0000 | [diff] [blame] | 128 | VALID_COMMAND_INTERPRETER = "Got a valid command interpreter" |
| 129 | |
Johnny Chen | 5ee8819 | 2010-08-27 23:47:36 +0000 | [diff] [blame] | 130 | VALID_FILESPEC = "Got a valid filespec" |
| 131 | |
Johnny Chen | 025d1b8 | 2010-12-08 01:25:21 +0000 | [diff] [blame] | 132 | VALID_MODULE = "Got a valid module" |
| 133 | |
Johnny Chen | 5fca8ca | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 134 | VALID_PROCESS = "Got a valid process" |
| 135 | |
Johnny Chen | 025d1b8 | 2010-12-08 01:25:21 +0000 | [diff] [blame] | 136 | VALID_SYMBOL = "Got a valid symbol" |
| 137 | |
Johnny Chen | 5fca8ca | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 138 | VALID_TARGET = "Got a valid target" |
| 139 | |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 140 | VALID_PLATFORM = "Got a valid platform" |
| 141 | |
Johnny Chen | 15f247a | 2012-02-03 20:43:00 +0000 | [diff] [blame] | 142 | VALID_TYPE = "Got a valid type" |
| 143 | |
Johnny Chen | 5819ab4 | 2011-07-15 22:28:10 +0000 | [diff] [blame] | 144 | VALID_VARIABLE = "Got a valid variable" |
| 145 | |
Johnny Chen | 981463d | 2010-08-25 19:00:04 +0000 | [diff] [blame] | 146 | VARIABLES_DISPLAYED_CORRECTLY = "Variable(s) displayed correctly" |
Johnny Chen | 0077809 | 2010-08-09 22:01:17 +0000 | [diff] [blame] | 147 | |
Johnny Chen | f68cc12 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 148 | WATCHPOINT_CREATED = "Watchpoint created successfully" |
Johnny Chen | 5fca8ca | 2010-08-26 20:04:17 +0000 | [diff] [blame] | 149 | |
Johnny Chen | c0c67f2 | 2010-11-09 18:42:22 +0000 | [diff] [blame] | 150 | def CMD_MSG(str): |
Johnny Chen | aacf92e | 2011-05-31 22:16:51 +0000 | [diff] [blame] | 151 | '''A generic "Command '%s' returns successfully" message generator.''' |
Johnny Chen | c0c67f2 | 2010-11-09 18:42:22 +0000 | [diff] [blame] | 152 | return "Command '%s' returns successfully" % str |
| 153 | |
Johnny Chen | 3bc8ae4 | 2012-03-15 19:10:00 +0000 | [diff] [blame] | 154 | def COMPLETION_MSG(str_before, str_after): |
Johnny Chen | 98aceb0 | 2012-01-20 23:02:51 +0000 | [diff] [blame] | 155 | '''A generic message generator for the completion mechanism.''' |
| 156 | return "'%s' successfully completes to '%s'" % (str_before, str_after) |
| 157 | |
Johnny Chen | c0c67f2 | 2010-11-09 18:42:22 +0000 | [diff] [blame] | 158 | def EXP_MSG(str, exe): |
Johnny Chen | aacf92e | 2011-05-31 22:16:51 +0000 | [diff] [blame] | 159 | '''A generic "'%s' returns expected result" message generator if exe. |
| 160 | Otherwise, it generates "'%s' matches expected result" message.''' |
Johnny Chen | c0c67f2 | 2010-11-09 18:42:22 +0000 | [diff] [blame] | 161 | return "'%s' %s expected result" % (str, 'returns' if exe else 'matches') |
Johnny Chen | 1794184 | 2010-08-09 23:44:24 +0000 | [diff] [blame] | 162 | |
Johnny Chen | 3343f04 | 2010-10-19 19:11:38 +0000 | [diff] [blame] | 163 | def SETTING_MSG(setting): |
Johnny Chen | aacf92e | 2011-05-31 22:16:51 +0000 | [diff] [blame] | 164 | '''A generic "Value of setting '%s' is correct" message generator.''' |
Johnny Chen | 3343f04 | 2010-10-19 19:11:38 +0000 | [diff] [blame] | 165 | return "Value of setting '%s' is correct" % setting |
| 166 | |
Johnny Chen | 27c4123 | 2010-08-26 21:49:29 +0000 | [diff] [blame] | 167 | def EnvArray(): |
Johnny Chen | aacf92e | 2011-05-31 22:16:51 +0000 | [diff] [blame] | 168 | """Returns an env variable array from the os.environ map object.""" |
Johnny Chen | 27c4123 | 2010-08-26 21:49:29 +0000 | [diff] [blame] | 169 | return map(lambda k,v: k+"="+v, os.environ.keys(), os.environ.values()) |
| 170 | |
Johnny Chen | 47ceb03 | 2010-10-11 23:52:19 +0000 | [diff] [blame] | 171 | def line_number(filename, string_to_match): |
| 172 | """Helper function to return the line number of the first matched string.""" |
| 173 | with open(filename, 'r') as f: |
| 174 | for i, line in enumerate(f): |
| 175 | if line.find(string_to_match) != -1: |
| 176 | # Found our match. |
Johnny Chen | cd9b777 | 2010-10-12 00:09:25 +0000 | [diff] [blame] | 177 | return i+1 |
Johnny Chen | 1691a16 | 2011-04-15 16:44:48 +0000 | [diff] [blame] | 178 | raise Exception("Unable to find '%s' within file %s" % (string_to_match, filename)) |
Johnny Chen | 47ceb03 | 2010-10-11 23:52:19 +0000 | [diff] [blame] | 179 | |
Johnny Chen | 67af43f | 2010-10-05 19:27:32 +0000 | [diff] [blame] | 180 | def pointer_size(): |
| 181 | """Return the pointer size of the host system.""" |
| 182 | import ctypes |
| 183 | a_pointer = ctypes.c_void_p(0xffff) |
| 184 | return 8 * ctypes.sizeof(a_pointer) |
| 185 | |
Johnny Chen | 5781673 | 2012-02-09 02:01:59 +0000 | [diff] [blame] | 186 | def is_exe(fpath): |
| 187 | """Returns true if fpath is an executable.""" |
| 188 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) |
| 189 | |
| 190 | def which(program): |
| 191 | """Returns the full path to a program; None otherwise.""" |
| 192 | fpath, fname = os.path.split(program) |
| 193 | if fpath: |
| 194 | if is_exe(program): |
| 195 | return program |
| 196 | else: |
| 197 | for path in os.environ["PATH"].split(os.pathsep): |
| 198 | exe_file = os.path.join(path, program) |
| 199 | if is_exe(exe_file): |
| 200 | return exe_file |
| 201 | return None |
| 202 | |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 203 | class recording(StringIO.StringIO): |
| 204 | """ |
| 205 | A nice little context manager for recording the debugger interactions into |
| 206 | our session object. If trace flag is ON, it also emits the interactions |
| 207 | into the stderr. |
| 208 | """ |
| 209 | def __init__(self, test, trace): |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 210 | """Create a StringIO instance; record the session obj and trace flag.""" |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 211 | StringIO.StringIO.__init__(self) |
Johnny Chen | 0241f14 | 2011-08-16 22:06:17 +0000 | [diff] [blame] | 212 | # The test might not have undergone the 'setUp(self)' phase yet, so that |
| 213 | # the attribute 'session' might not even exist yet. |
Johnny Chen | bfcf37f | 2011-08-16 17:06:45 +0000 | [diff] [blame] | 214 | self.session = getattr(test, "session", None) if test else None |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 215 | self.trace = trace |
| 216 | |
| 217 | def __enter__(self): |
| 218 | """ |
| 219 | Context management protocol on entry to the body of the with statement. |
| 220 | Just return the StringIO object. |
| 221 | """ |
| 222 | return self |
| 223 | |
| 224 | def __exit__(self, type, value, tb): |
| 225 | """ |
| 226 | Context management protocol on exit from the body of the with statement. |
| 227 | If trace is ON, it emits the recordings into stderr. Always add the |
| 228 | recordings to our session object. And close the StringIO object, too. |
| 229 | """ |
| 230 | if self.trace: |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 231 | print >> sys.stderr, self.getvalue() |
| 232 | if self.session: |
| 233 | print >> self.session, self.getvalue() |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 234 | self.close() |
| 235 | |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 236 | # From 2.7's subprocess.check_output() convenience function. |
Johnny Chen | ac77f3b | 2011-03-23 20:28:59 +0000 | [diff] [blame] | 237 | # Return a tuple (stdoutdata, stderrdata). |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 238 | def system(commands, **kwargs): |
Johnny Chen | 8eb14a9 | 2011-11-16 22:44:28 +0000 | [diff] [blame] | 239 | r"""Run an os command with arguments and return its output as a byte string. |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 240 | |
| 241 | If the exit code was non-zero it raises a CalledProcessError. The |
| 242 | CalledProcessError object will have the return code in the returncode |
| 243 | attribute and output in the output attribute. |
| 244 | |
| 245 | The arguments are the same as for the Popen constructor. Example: |
| 246 | |
| 247 | >>> check_output(["ls", "-l", "/dev/null"]) |
| 248 | 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' |
| 249 | |
| 250 | The stdout argument is not allowed as it is used internally. |
| 251 | To capture standard error in the result, use stderr=STDOUT. |
| 252 | |
| 253 | >>> check_output(["/bin/sh", "-c", |
| 254 | ... "ls -l non_existent_file ; exit 0"], |
| 255 | ... stderr=STDOUT) |
| 256 | 'ls: non_existent_file: No such file or directory\n' |
| 257 | """ |
| 258 | |
| 259 | # Assign the sender object to variable 'test' and remove it from kwargs. |
| 260 | test = kwargs.pop('sender', None) |
| 261 | |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 262 | separator = None |
| 263 | separator = " && " if os.name == "nt" else "; " |
| 264 | # [['make', 'clean', 'foo'], ['make', 'foo']] -> ['make clean foo', 'make foo'] |
| 265 | commandList = [' '.join(x) for x in commands] |
| 266 | # ['make clean foo', 'make foo'] -> 'make clean foo; make foo' |
| 267 | shellCommand = separator.join(commandList) |
| 268 | |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 269 | if 'stdout' in kwargs: |
| 270 | raise ValueError('stdout argument not allowed, it will be overridden.') |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 271 | if 'shell' in kwargs and kwargs['shell']==False: |
| 272 | raise ValueError('shell=False not allowed') |
| 273 | process = Popen(shellCommand, stdout=PIPE, stderr=PIPE, shell=True, **kwargs) |
Johnny Chen | 0bd8c31 | 2011-11-16 22:41:53 +0000 | [diff] [blame] | 274 | pid = process.pid |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 275 | output, error = process.communicate() |
| 276 | retcode = process.poll() |
| 277 | |
Ed Maste | 6e49633 | 2014-08-05 20:33:17 +0000 | [diff] [blame] | 278 | # Enable trace on failure return while tracking down FreeBSD buildbot issues |
| 279 | trace = traceAlways |
| 280 | if not trace and retcode and sys.platform.startswith("freebsd"): |
| 281 | trace = True |
| 282 | |
| 283 | with recording(test, trace) as sbuf: |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 284 | print >> sbuf |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 285 | print >> sbuf, "os command:", shellCommand |
Johnny Chen | 0bd8c31 | 2011-11-16 22:41:53 +0000 | [diff] [blame] | 286 | print >> sbuf, "with pid:", pid |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 287 | print >> sbuf, "stdout:", output |
| 288 | print >> sbuf, "stderr:", error |
| 289 | print >> sbuf, "retcode:", retcode |
| 290 | print >> sbuf |
| 291 | |
| 292 | if retcode: |
| 293 | cmd = kwargs.get("args") |
| 294 | if cmd is None: |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 295 | cmd = shellCommand |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 296 | raise CalledProcessError(retcode, cmd) |
Johnny Chen | ac77f3b | 2011-03-23 20:28:59 +0000 | [diff] [blame] | 297 | return (output, error) |
Johnny Chen | 690fcef | 2010-10-15 23:55:05 +0000 | [diff] [blame] | 298 | |
Johnny Chen | ab9c1dd | 2010-11-01 20:35:01 +0000 | [diff] [blame] | 299 | def getsource_if_available(obj): |
| 300 | """ |
| 301 | Return the text of the source code for an object if available. Otherwise, |
| 302 | a print representation is returned. |
| 303 | """ |
| 304 | import inspect |
| 305 | try: |
| 306 | return inspect.getsource(obj) |
| 307 | except: |
| 308 | return repr(obj) |
| 309 | |
Peter Collingbourne | 19f48d5 | 2011-06-20 19:06:20 +0000 | [diff] [blame] | 310 | def builder_module(): |
Ed Maste | 4d90f0f | 2013-07-25 13:24:34 +0000 | [diff] [blame] | 311 | if sys.platform.startswith("freebsd"): |
| 312 | return __import__("builder_freebsd") |
Peter Collingbourne | 19f48d5 | 2011-06-20 19:06:20 +0000 | [diff] [blame] | 313 | return __import__("builder_" + sys.platform) |
| 314 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 315 | # |
| 316 | # Decorators for categorizing test cases. |
| 317 | # |
| 318 | |
| 319 | from functools import wraps |
| 320 | def python_api_test(func): |
| 321 | """Decorate the item as a Python API only test.""" |
| 322 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 323 | raise Exception("@python_api_test can only be used to decorate a test method") |
| 324 | @wraps(func) |
| 325 | def wrapper(self, *args, **kwargs): |
| 326 | try: |
| 327 | if lldb.dont_do_python_api_test: |
| 328 | self.skipTest("python api tests") |
| 329 | except AttributeError: |
| 330 | pass |
| 331 | return func(self, *args, **kwargs) |
| 332 | |
| 333 | # Mark this function as such to separate them from lldb command line tests. |
| 334 | wrapper.__python_api_test__ = True |
| 335 | return wrapper |
| 336 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 337 | def benchmarks_test(func): |
| 338 | """Decorate the item as a benchmarks test.""" |
| 339 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 340 | raise Exception("@benchmarks_test can only be used to decorate a test method") |
| 341 | @wraps(func) |
| 342 | def wrapper(self, *args, **kwargs): |
| 343 | try: |
| 344 | if not lldb.just_do_benchmarks_test: |
| 345 | self.skipTest("benchmarks tests") |
| 346 | except AttributeError: |
| 347 | pass |
| 348 | return func(self, *args, **kwargs) |
| 349 | |
| 350 | # Mark this function as such to separate them from the regular tests. |
| 351 | wrapper.__benchmarks_test__ = True |
| 352 | return wrapper |
| 353 | |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 354 | def dsym_test(func): |
| 355 | """Decorate the item as a dsym test.""" |
| 356 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 357 | raise Exception("@dsym_test can only be used to decorate a test method") |
| 358 | @wraps(func) |
| 359 | def wrapper(self, *args, **kwargs): |
| 360 | try: |
| 361 | if lldb.dont_do_dsym_test: |
| 362 | self.skipTest("dsym tests") |
| 363 | except AttributeError: |
| 364 | pass |
| 365 | return func(self, *args, **kwargs) |
| 366 | |
| 367 | # Mark this function as such to separate them from the regular tests. |
| 368 | wrapper.__dsym_test__ = True |
| 369 | return wrapper |
| 370 | |
| 371 | def dwarf_test(func): |
| 372 | """Decorate the item as a dwarf test.""" |
| 373 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 374 | raise Exception("@dwarf_test can only be used to decorate a test method") |
| 375 | @wraps(func) |
| 376 | def wrapper(self, *args, **kwargs): |
| 377 | try: |
| 378 | if lldb.dont_do_dwarf_test: |
| 379 | self.skipTest("dwarf tests") |
| 380 | except AttributeError: |
| 381 | pass |
| 382 | return func(self, *args, **kwargs) |
| 383 | |
| 384 | # Mark this function as such to separate them from the regular tests. |
| 385 | wrapper.__dwarf_test__ = True |
| 386 | return wrapper |
| 387 | |
Todd Fiala | a41d48c | 2014-04-28 04:49:40 +0000 | [diff] [blame] | 388 | def debugserver_test(func): |
| 389 | """Decorate the item as a debugserver test.""" |
| 390 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 391 | raise Exception("@debugserver_test can only be used to decorate a test method") |
| 392 | @wraps(func) |
| 393 | def wrapper(self, *args, **kwargs): |
| 394 | try: |
| 395 | if lldb.dont_do_debugserver_test: |
| 396 | self.skipTest("debugserver tests") |
| 397 | except AttributeError: |
| 398 | pass |
| 399 | return func(self, *args, **kwargs) |
| 400 | |
| 401 | # Mark this function as such to separate them from the regular tests. |
| 402 | wrapper.__debugserver_test__ = True |
| 403 | return wrapper |
| 404 | |
| 405 | def llgs_test(func): |
| 406 | """Decorate the item as a lldb-gdbserver test.""" |
| 407 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 408 | raise Exception("@llgs_test can only be used to decorate a test method") |
| 409 | @wraps(func) |
| 410 | def wrapper(self, *args, **kwargs): |
| 411 | try: |
| 412 | if lldb.dont_do_llgs_test: |
| 413 | self.skipTest("llgs tests") |
| 414 | except AttributeError: |
| 415 | pass |
| 416 | return func(self, *args, **kwargs) |
| 417 | |
| 418 | # Mark this function as such to separate them from the regular tests. |
| 419 | wrapper.__llgs_test__ = True |
| 420 | return wrapper |
| 421 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 422 | def not_remote_testsuite_ready(func): |
| 423 | """Decorate the item as a test which is not ready yet for remote testsuite.""" |
| 424 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 425 | raise Exception("@not_remote_testsuite_ready can only be used to decorate a test method") |
| 426 | @wraps(func) |
| 427 | def wrapper(self, *args, **kwargs): |
| 428 | try: |
| 429 | if lldb.lldbtest_remote_sandbox: |
| 430 | self.skipTest("not ready for remote testsuite") |
| 431 | except AttributeError: |
| 432 | pass |
| 433 | return func(self, *args, **kwargs) |
| 434 | |
| 435 | # Mark this function as such to separate them from the regular tests. |
| 436 | wrapper.__not_ready_for_remote_testsuite_test__ = True |
| 437 | return wrapper |
| 438 | |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 439 | def expectedFailure(expected_fn, bugnumber=None): |
| 440 | def expectedFailure_impl(func): |
| 441 | @wraps(func) |
| 442 | def wrapper(*args, **kwargs): |
Enrico Granata | 43f6213 | 2013-02-23 01:28:30 +0000 | [diff] [blame] | 443 | from unittest2 import case |
| 444 | self = args[0] |
Enrico Granata | 43f6213 | 2013-02-23 01:28:30 +0000 | [diff] [blame] | 445 | try: |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 446 | func(*args, **kwargs) |
Enrico Granata | 43f6213 | 2013-02-23 01:28:30 +0000 | [diff] [blame] | 447 | except Exception: |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 448 | if expected_fn(self): |
| 449 | raise case._ExpectedFailure(sys.exc_info(), bugnumber) |
Enrico Granata | 43f6213 | 2013-02-23 01:28:30 +0000 | [diff] [blame] | 450 | else: |
| 451 | raise |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 452 | if expected_fn(self): |
| 453 | raise case._UnexpectedSuccess(sys.exc_info(), bugnumber) |
| 454 | return wrapper |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 455 | if bugnumber: |
| 456 | if callable(bugnumber): |
| 457 | return expectedFailure_impl(bugnumber) |
| 458 | else: |
| 459 | return expectedFailure_impl |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 460 | |
| 461 | def expectedFailureCompiler(compiler, compiler_version=None, bugnumber=None): |
| 462 | if compiler_version is None: |
| 463 | compiler_version=['=', None] |
| 464 | def fn(self): |
| 465 | return compiler in self.getCompiler() and self.expectedCompilerVersion(compiler_version) |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 466 | if bugnumber: return expectedFailure(fn, bugnumber) |
Daniel Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 467 | |
Enrico Granata | 2b3a0c4 | 2013-02-23 01:35:21 +0000 | [diff] [blame] | 468 | def expectedFailureClang(bugnumber=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 469 | if bugnumber: return expectedFailureCompiler('clang', None, bugnumber) |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 470 | |
| 471 | def expectedFailureGcc(bugnumber=None, compiler_version=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 472 | if bugnumber: return expectedFailureCompiler('gcc', compiler_version, bugnumber) |
Daniel Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 473 | |
Matt Kopec | 0de53f0 | 2013-03-15 19:10:12 +0000 | [diff] [blame] | 474 | def expectedFailureIcc(bugnumber=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 475 | if bugnumber: return expectedFailureCompiler('icc', None, bugnumber) |
Matt Kopec | 0de53f0 | 2013-03-15 19:10:12 +0000 | [diff] [blame] | 476 | |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 477 | def expectedFailureArch(arch, bugnumber=None): |
| 478 | def fn(self): |
| 479 | return arch in self.getArchitecture() |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 480 | if bugnumber: return expectedFailure(fn, bugnumber) |
Daniel Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 481 | |
Enrico Granata | e6cedc1 | 2013-02-23 01:05:23 +0000 | [diff] [blame] | 482 | def expectedFailurei386(bugnumber=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 483 | if bugnumber: return expectedFailureArch('i386', bugnumber) |
Johnny Chen | a33843f | 2011-12-22 21:14:31 +0000 | [diff] [blame] | 484 | |
Matt Kopec | ee969f9 | 2013-09-26 23:30:59 +0000 | [diff] [blame] | 485 | def expectedFailurex86_64(bugnumber=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 486 | if bugnumber: return expectedFailureArch('x86_64', bugnumber) |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 487 | |
| 488 | def expectedFailureOS(os, bugnumber=None, compilers=None): |
| 489 | def fn(self): |
| 490 | return os in sys.platform and self.expectedCompiler(compilers) |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 491 | if bugnumber: return expectedFailure(fn, bugnumber) |
Ed Maste | 433790a | 2014-04-23 12:55:41 +0000 | [diff] [blame] | 492 | |
| 493 | def expectedFailureDarwin(bugnumber=None, compilers=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 494 | if bugnumber: return expectedFailureOS('darwin', bugnumber, compilers) |
Matt Kopec | ee969f9 | 2013-09-26 23:30:59 +0000 | [diff] [blame] | 495 | |
Ed Maste | 24a7f7d | 2013-07-24 19:47:08 +0000 | [diff] [blame] | 496 | def expectedFailureFreeBSD(bugnumber=None, compilers=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 497 | if bugnumber: return expectedFailureOS('freebsd', bugnumber, compilers) |
Ed Maste | 24a7f7d | 2013-07-24 19:47:08 +0000 | [diff] [blame] | 498 | |
Ashok Thirumurthi | c97a608 | 2013-05-17 20:15:07 +0000 | [diff] [blame] | 499 | def expectedFailureLinux(bugnumber=None, compilers=None): |
Enrico Granata | cf3ab58 | 2014-10-17 01:11:29 +0000 | [diff] [blame] | 500 | if bugnumber: return expectedFailureOS('linux', bugnumber, compilers) |
Matt Kopec | e9ea0da | 2013-05-07 19:29:28 +0000 | [diff] [blame] | 501 | |
Greg Clayton | 1251456 | 2013-12-05 22:22:32 +0000 | [diff] [blame] | 502 | def skipIfRemote(func): |
| 503 | """Decorate the item to skip tests if testing remotely.""" |
| 504 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 505 | raise Exception("@skipIfRemote can only be used to decorate a test method") |
| 506 | @wraps(func) |
| 507 | def wrapper(*args, **kwargs): |
| 508 | from unittest2 import case |
| 509 | if lldb.remote_platform: |
| 510 | self = args[0] |
| 511 | self.skipTest("skip on remote platform") |
| 512 | else: |
| 513 | func(*args, **kwargs) |
| 514 | return wrapper |
| 515 | |
| 516 | def skipIfRemoteDueToDeadlock(func): |
| 517 | """Decorate the item to skip tests if testing remotely due to the test deadlocking.""" |
| 518 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 519 | raise Exception("@skipIfRemote can only be used to decorate a test method") |
| 520 | @wraps(func) |
| 521 | def wrapper(*args, **kwargs): |
| 522 | from unittest2 import case |
| 523 | if lldb.remote_platform: |
| 524 | self = args[0] |
| 525 | self.skipTest("skip on remote platform (deadlocks)") |
| 526 | else: |
| 527 | func(*args, **kwargs) |
| 528 | return wrapper |
| 529 | |
Ed Maste | 09617a5 | 2013-06-25 19:11:36 +0000 | [diff] [blame] | 530 | def skipIfFreeBSD(func): |
| 531 | """Decorate the item to skip tests that should be skipped on FreeBSD.""" |
| 532 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 533 | raise Exception("@skipIfFreeBSD can only be used to decorate a test method") |
| 534 | @wraps(func) |
| 535 | def wrapper(*args, **kwargs): |
| 536 | from unittest2 import case |
| 537 | self = args[0] |
| 538 | platform = sys.platform |
| 539 | if "freebsd" in platform: |
| 540 | self.skipTest("skip on FreeBSD") |
| 541 | else: |
| 542 | func(*args, **kwargs) |
| 543 | return wrapper |
| 544 | |
Daniel Malea | e8bdd1f | 2013-05-15 18:48:32 +0000 | [diff] [blame] | 545 | def skipIfLinux(func): |
Daniel Malea | 93aec0f | 2012-11-23 21:59:29 +0000 | [diff] [blame] | 546 | """Decorate the item to skip tests that should be skipped on Linux.""" |
| 547 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
Daniel Malea | e8bdd1f | 2013-05-15 18:48:32 +0000 | [diff] [blame] | 548 | raise Exception("@skipIfLinux can only be used to decorate a test method") |
Daniel Malea | 93aec0f | 2012-11-23 21:59:29 +0000 | [diff] [blame] | 549 | @wraps(func) |
| 550 | def wrapper(*args, **kwargs): |
| 551 | from unittest2 import case |
| 552 | self = args[0] |
| 553 | platform = sys.platform |
| 554 | if "linux" in platform: |
| 555 | self.skipTest("skip on linux") |
| 556 | else: |
Jim Ingham | 9732e08 | 2012-11-27 01:21:28 +0000 | [diff] [blame] | 557 | func(*args, **kwargs) |
Daniel Malea | 93aec0f | 2012-11-23 21:59:29 +0000 | [diff] [blame] | 558 | return wrapper |
| 559 | |
Enrico Granata | b633e43 | 2014-10-06 21:37:06 +0000 | [diff] [blame] | 560 | def skipIfNoSBHeaders(func): |
| 561 | """Decorate the item to mark tests that should be skipped when LLDB is built with no SB API headers.""" |
| 562 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
Ed Maste | 59cca5d | 2014-10-07 01:57:52 +0000 | [diff] [blame] | 563 | raise Exception("@skipIfNoSBHeaders can only be used to decorate a test method") |
Enrico Granata | b633e43 | 2014-10-06 21:37:06 +0000 | [diff] [blame] | 564 | @wraps(func) |
| 565 | def wrapper(*args, **kwargs): |
| 566 | from unittest2 import case |
| 567 | self = args[0] |
Enrico Granata | e9afaf7 | 2014-10-27 20:31:12 +0000 | [diff] [blame] | 568 | header = os.path.join(self.lib_dir, 'LLDB.framework', 'Versions','Current','Headers','LLDB.h') |
Enrico Granata | b633e43 | 2014-10-06 21:37:06 +0000 | [diff] [blame] | 569 | platform = sys.platform |
Enrico Granata | b633e43 | 2014-10-06 21:37:06 +0000 | [diff] [blame] | 570 | if not os.path.exists(header): |
| 571 | self.skipTest("skip because LLDB.h header not found") |
| 572 | else: |
| 573 | func(*args, **kwargs) |
| 574 | return wrapper |
| 575 | |
Zachary Turner | c782652 | 2014-08-13 17:44:53 +0000 | [diff] [blame] | 576 | def skipIfWindows(func): |
| 577 | """Decorate the item to skip tests that should be skipped on Windows.""" |
| 578 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 579 | raise Exception("@skipIfWindows can only be used to decorate a test method") |
| 580 | @wraps(func) |
| 581 | def wrapper(*args, **kwargs): |
| 582 | from unittest2 import case |
| 583 | self = args[0] |
| 584 | platform = sys.platform |
| 585 | if "win32" in platform: |
| 586 | self.skipTest("skip on Windows") |
| 587 | else: |
| 588 | func(*args, **kwargs) |
| 589 | return wrapper |
| 590 | |
Daniel Malea | b3d41a2 | 2013-07-09 00:08:01 +0000 | [diff] [blame] | 591 | def skipIfDarwin(func): |
| 592 | """Decorate the item to skip tests that should be skipped on Darwin.""" |
| 593 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
Ed Maste | a7f13f0 | 2013-07-09 00:24:52 +0000 | [diff] [blame] | 594 | raise Exception("@skipIfDarwin can only be used to decorate a test method") |
Daniel Malea | b3d41a2 | 2013-07-09 00:08:01 +0000 | [diff] [blame] | 595 | @wraps(func) |
| 596 | def wrapper(*args, **kwargs): |
| 597 | from unittest2 import case |
| 598 | self = args[0] |
| 599 | platform = sys.platform |
| 600 | if "darwin" in platform: |
| 601 | self.skipTest("skip on darwin") |
| 602 | else: |
| 603 | func(*args, **kwargs) |
| 604 | return wrapper |
| 605 | |
| 606 | |
Daniel Malea | 4835990 | 2013-05-14 20:48:54 +0000 | [diff] [blame] | 607 | def skipIfLinuxClang(func): |
| 608 | """Decorate the item to skip tests that should be skipped if building on |
| 609 | Linux with clang. |
| 610 | """ |
| 611 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 612 | raise Exception("@skipIfLinuxClang can only be used to decorate a test method") |
| 613 | @wraps(func) |
| 614 | def wrapper(*args, **kwargs): |
| 615 | from unittest2 import case |
| 616 | self = args[0] |
| 617 | compiler = self.getCompiler() |
| 618 | platform = sys.platform |
| 619 | if "clang" in compiler and "linux" in platform: |
| 620 | self.skipTest("skipping because Clang is used on Linux") |
| 621 | else: |
| 622 | func(*args, **kwargs) |
| 623 | return wrapper |
| 624 | |
Daniel Malea | be23079 | 2013-01-24 23:52:09 +0000 | [diff] [blame] | 625 | def skipIfGcc(func): |
| 626 | """Decorate the item to skip tests that should be skipped if building with gcc .""" |
| 627 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
Daniel Malea | 0aea016 | 2013-02-27 17:29:46 +0000 | [diff] [blame] | 628 | raise Exception("@skipIfGcc can only be used to decorate a test method") |
Daniel Malea | be23079 | 2013-01-24 23:52:09 +0000 | [diff] [blame] | 629 | @wraps(func) |
| 630 | def wrapper(*args, **kwargs): |
| 631 | from unittest2 import case |
| 632 | self = args[0] |
| 633 | compiler = self.getCompiler() |
| 634 | if "gcc" in compiler: |
| 635 | self.skipTest("skipping because gcc is the test compiler") |
| 636 | else: |
| 637 | func(*args, **kwargs) |
| 638 | return wrapper |
| 639 | |
Matt Kopec | 0de53f0 | 2013-03-15 19:10:12 +0000 | [diff] [blame] | 640 | def skipIfIcc(func): |
| 641 | """Decorate the item to skip tests that should be skipped if building with icc .""" |
| 642 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 643 | raise Exception("@skipIfIcc can only be used to decorate a test method") |
| 644 | @wraps(func) |
| 645 | def wrapper(*args, **kwargs): |
| 646 | from unittest2 import case |
| 647 | self = args[0] |
| 648 | compiler = self.getCompiler() |
| 649 | if "icc" in compiler: |
| 650 | self.skipTest("skipping because icc is the test compiler") |
| 651 | else: |
| 652 | func(*args, **kwargs) |
| 653 | return wrapper |
| 654 | |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 655 | def skipIfi386(func): |
| 656 | """Decorate the item to skip tests that should be skipped if building 32-bit.""" |
| 657 | if isinstance(func, type) and issubclass(func, unittest2.TestCase): |
| 658 | raise Exception("@skipIfi386 can only be used to decorate a test method") |
| 659 | @wraps(func) |
| 660 | def wrapper(*args, **kwargs): |
| 661 | from unittest2 import case |
| 662 | self = args[0] |
| 663 | if "i386" == self.getArchitecture(): |
| 664 | self.skipTest("skipping because i386 is not a supported architecture") |
| 665 | else: |
| 666 | func(*args, **kwargs) |
| 667 | return wrapper |
| 668 | |
| 669 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 670 | class Base(unittest2.TestCase): |
Johnny Chen | 8334dad | 2010-10-22 23:15:46 +0000 | [diff] [blame] | 671 | """ |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 672 | Abstract base for performing lldb (see TestBase) or other generic tests (see |
| 673 | BenchBase for one example). lldbtest.Base works with the test driver to |
| 674 | accomplish things. |
| 675 | |
Johnny Chen | 8334dad | 2010-10-22 23:15:46 +0000 | [diff] [blame] | 676 | """ |
Enrico Granata | 5020f95 | 2012-10-24 21:42:49 +0000 | [diff] [blame] | 677 | |
Enrico Granata | 1918627 | 2012-10-24 21:44:48 +0000 | [diff] [blame] | 678 | # The concrete subclass should override this attribute. |
| 679 | mydir = None |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 680 | |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 681 | # Keep track of the old current working directory. |
| 682 | oldcwd = None |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 683 | |
| 684 | @staticmethod |
| 685 | def compute_mydir(test_file): |
| 686 | '''Subclasses should call this function to correctly calculate the required "mydir" attribute as follows: |
| 687 | |
| 688 | mydir = TestBase.compute_mydir(__file__)''' |
| 689 | test_dir = os.path.dirname(test_file) |
| 690 | return test_dir[len(os.environ["LLDB_TEST"])+1:] |
| 691 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 692 | def TraceOn(self): |
| 693 | """Returns True if we are in trace mode (tracing detailed test execution).""" |
| 694 | return traceAlways |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 695 | |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 696 | @classmethod |
| 697 | def setUpClass(cls): |
Johnny Chen | da88434 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 698 | """ |
| 699 | Python unittest framework class setup fixture. |
| 700 | Do current directory manipulation. |
| 701 | """ |
| 702 | |
Johnny Chen | f02ec12 | 2010-07-03 20:41:42 +0000 | [diff] [blame] | 703 | # Fail fast if 'mydir' attribute is not overridden. |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 704 | if not cls.mydir or len(cls.mydir) == 0: |
Johnny Chen | f02ec12 | 2010-07-03 20:41:42 +0000 | [diff] [blame] | 705 | raise Exception("Subclasses must override the 'mydir' attribute.") |
Enrico Granata | 7e137e3 | 2012-10-24 18:14:21 +0000 | [diff] [blame] | 706 | |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 707 | # Save old working directory. |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 708 | cls.oldcwd = os.getcwd() |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 709 | |
| 710 | # Change current working directory if ${LLDB_TEST} is defined. |
| 711 | # See also dotest.py which sets up ${LLDB_TEST}. |
| 712 | if ("LLDB_TEST" in os.environ): |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 713 | if traceAlways: |
Johnny Chen | 703dbd0 | 2010-09-30 17:06:24 +0000 | [diff] [blame] | 714 | print >> sys.stderr, "Change dir to:", os.path.join(os.environ["LLDB_TEST"], cls.mydir) |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 715 | os.chdir(os.path.join(os.environ["LLDB_TEST"], cls.mydir)) |
| 716 | |
| 717 | @classmethod |
| 718 | def tearDownClass(cls): |
Johnny Chen | da88434 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 719 | """ |
| 720 | Python unittest framework class teardown fixture. |
| 721 | Do class-wide cleanup. |
| 722 | """ |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 723 | |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 724 | if doCleanup and not lldb.skip_build_and_cleanup: |
Johnny Chen | 707b3c9 | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 725 | # First, let's do the platform-specific cleanup. |
Peter Collingbourne | 19f48d5 | 2011-06-20 19:06:20 +0000 | [diff] [blame] | 726 | module = builder_module() |
Johnny Chen | 707b3c9 | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 727 | if not module.cleanup(): |
| 728 | raise Exception("Don't know how to do cleanup") |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 729 | |
Johnny Chen | 707b3c9 | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 730 | # Subclass might have specific cleanup function defined. |
| 731 | if getattr(cls, "classCleanup", None): |
| 732 | if traceAlways: |
| 733 | print >> sys.stderr, "Call class-specific cleanup function for class:", cls |
| 734 | try: |
| 735 | cls.classCleanup() |
| 736 | except: |
| 737 | exc_type, exc_value, exc_tb = sys.exc_info() |
| 738 | traceback.print_exception(exc_type, exc_value, exc_tb) |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 739 | |
| 740 | # Restore old working directory. |
| 741 | if traceAlways: |
Johnny Chen | 703dbd0 | 2010-09-30 17:06:24 +0000 | [diff] [blame] | 742 | print >> sys.stderr, "Restore dir to:", cls.oldcwd |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 743 | os.chdir(cls.oldcwd) |
| 744 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 745 | @classmethod |
| 746 | def skipLongRunningTest(cls): |
| 747 | """ |
| 748 | By default, we skip long running test case. |
| 749 | This can be overridden by passing '-l' to the test driver (dotest.py). |
| 750 | """ |
| 751 | if "LLDB_SKIP_LONG_RUNNING_TEST" in os.environ and "NO" == os.environ["LLDB_SKIP_LONG_RUNNING_TEST"]: |
| 752 | return False |
| 753 | else: |
| 754 | return True |
Johnny Chen | ed49202 | 2011-06-21 00:53:00 +0000 | [diff] [blame] | 755 | |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 756 | def setUp(self): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 757 | """Fixture for unittest test case setup. |
| 758 | |
| 759 | It works with the test driver to conditionally skip tests and does other |
| 760 | initializations.""" |
Johnny Chen | 1a9f4dd | 2010-09-16 01:53:04 +0000 | [diff] [blame] | 761 | #import traceback |
| 762 | #traceback.print_stack() |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 763 | |
Daniel Malea | 9115f07 | 2013-08-06 15:02:32 +0000 | [diff] [blame] | 764 | if "LIBCXX_PATH" in os.environ: |
| 765 | self.libcxxPath = os.environ["LIBCXX_PATH"] |
| 766 | else: |
| 767 | self.libcxxPath = None |
| 768 | |
Johnny Chen | aaa82ff | 2011-08-02 22:54:37 +0000 | [diff] [blame] | 769 | if "LLDB_EXEC" in os.environ: |
| 770 | self.lldbExec = os.environ["LLDB_EXEC"] |
Johnny Chen | d890bfc | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 771 | else: |
| 772 | self.lldbExec = None |
| 773 | if "LLDB_HERE" in os.environ: |
| 774 | self.lldbHere = os.environ["LLDB_HERE"] |
| 775 | else: |
| 776 | self.lldbHere = None |
Johnny Chen | ebe5172 | 2011-10-07 19:21:09 +0000 | [diff] [blame] | 777 | # If we spawn an lldb process for test (via pexpect), do not load the |
| 778 | # init file unless told otherwise. |
| 779 | if "NO_LLDBINIT" in os.environ and "NO" == os.environ["NO_LLDBINIT"]: |
| 780 | self.lldbOption = "" |
| 781 | else: |
| 782 | self.lldbOption = "--no-lldbinit" |
Johnny Chen | aaa82ff | 2011-08-02 22:54:37 +0000 | [diff] [blame] | 783 | |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 784 | # Assign the test method name to self.testMethodName. |
| 785 | # |
| 786 | # For an example of the use of this attribute, look at test/types dir. |
| 787 | # There are a bunch of test cases under test/types and we don't want the |
| 788 | # module cacheing subsystem to be confused with executable name "a.out" |
| 789 | # used for all the test cases. |
| 790 | self.testMethodName = self._testMethodName |
| 791 | |
Johnny Chen | f3e22ac | 2010-12-10 18:52:10 +0000 | [diff] [blame] | 792 | # Python API only test is decorated with @python_api_test, |
| 793 | # which also sets the "__python_api_test__" attribute of the |
| 794 | # function object to True. |
Johnny Chen | 4533dad | 2011-05-31 23:21:42 +0000 | [diff] [blame] | 795 | try: |
| 796 | if lldb.just_do_python_api_test: |
| 797 | testMethod = getattr(self, self._testMethodName) |
| 798 | if getattr(testMethod, "__python_api_test__", False): |
| 799 | pass |
| 800 | else: |
Johnny Chen | 5ccbccf | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 801 | self.skipTest("non python api test") |
| 802 | except AttributeError: |
| 803 | pass |
| 804 | |
| 805 | # Benchmarks test is decorated with @benchmarks_test, |
| 806 | # which also sets the "__benchmarks_test__" attribute of the |
| 807 | # function object to True. |
| 808 | try: |
| 809 | if lldb.just_do_benchmarks_test: |
| 810 | testMethod = getattr(self, self._testMethodName) |
| 811 | if getattr(testMethod, "__benchmarks_test__", False): |
| 812 | pass |
| 813 | else: |
| 814 | self.skipTest("non benchmarks test") |
Johnny Chen | 4533dad | 2011-05-31 23:21:42 +0000 | [diff] [blame] | 815 | except AttributeError: |
| 816 | pass |
Johnny Chen | f3e22ac | 2010-12-10 18:52:10 +0000 | [diff] [blame] | 817 | |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 818 | # This is for the case of directly spawning 'lldb'/'gdb' and interacting |
| 819 | # with it using pexpect. |
| 820 | self.child = None |
| 821 | self.child_prompt = "(lldb) " |
| 822 | # If the child is interacting with the embedded script interpreter, |
| 823 | # there are two exits required during tear down, first to quit the |
| 824 | # embedded script interpreter and second to quit the lldb command |
| 825 | # interpreter. |
| 826 | self.child_in_script_interpreter = False |
| 827 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 828 | # These are for customized teardown cleanup. |
| 829 | self.dict = None |
| 830 | self.doTearDownCleanup = False |
| 831 | # And in rare cases where there are multiple teardown cleanups. |
| 832 | self.dicts = [] |
| 833 | self.doTearDownCleanups = False |
| 834 | |
Daniel Malea | 2dd69bb | 2013-02-15 21:21:52 +0000 | [diff] [blame] | 835 | # List of spawned subproces.Popen objects |
| 836 | self.subprocesses = [] |
| 837 | |
Daniel Malea | 6920746 | 2013-06-05 21:07:02 +0000 | [diff] [blame] | 838 | # List of forked process PIDs |
| 839 | self.forkedProcessPids = [] |
| 840 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 841 | # Create a string buffer to record the session info, to be dumped into a |
| 842 | # test case specific file if test failure is encountered. |
| 843 | self.session = StringIO.StringIO() |
| 844 | |
| 845 | # Optimistically set __errored__, __failed__, __expected__ to False |
| 846 | # initially. If the test errored/failed, the session info |
| 847 | # (self.session) is then dumped into a session specific file for |
| 848 | # diagnosis. |
| 849 | self.__errored__ = False |
| 850 | self.__failed__ = False |
| 851 | self.__expected__ = False |
| 852 | # We are also interested in unexpected success. |
| 853 | self.__unexpected__ = False |
Johnny Chen | f79b076 | 2011-08-16 00:48:58 +0000 | [diff] [blame] | 854 | # And skipped tests. |
| 855 | self.__skipped__ = False |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 856 | |
| 857 | # See addTearDownHook(self, hook) which allows the client to add a hook |
| 858 | # function to be run during tearDown() time. |
| 859 | self.hooks = [] |
| 860 | |
| 861 | # See HideStdout(self). |
| 862 | self.sys_stdout_hidden = False |
| 863 | |
Daniel Malea | 179ff29 | 2012-11-26 21:21:11 +0000 | [diff] [blame] | 864 | # set environment variable names for finding shared libraries |
| 865 | if sys.platform.startswith("darwin"): |
| 866 | self.dylibPath = 'DYLD_LIBRARY_PATH' |
| 867 | elif sys.platform.startswith("linux") or sys.platform.startswith("freebsd"): |
| 868 | self.dylibPath = 'LD_LIBRARY_PATH' |
| 869 | |
Johnny Chen | 2a80858 | 2011-10-19 16:48:07 +0000 | [diff] [blame] | 870 | def runHooks(self, child=None, child_prompt=None, use_cmd_api=False): |
Johnny Chen | a737ba5 | 2011-10-19 01:06:21 +0000 | [diff] [blame] | 871 | """Perform the run hooks to bring lldb debugger to the desired state. |
| 872 | |
Johnny Chen | 2a80858 | 2011-10-19 16:48:07 +0000 | [diff] [blame] | 873 | By default, expect a pexpect spawned child and child prompt to be |
| 874 | supplied (use_cmd_api=False). If use_cmd_api is true, ignore the child |
| 875 | and child prompt and use self.runCmd() to run the hooks one by one. |
| 876 | |
Johnny Chen | a737ba5 | 2011-10-19 01:06:21 +0000 | [diff] [blame] | 877 | Note that child is a process spawned by pexpect.spawn(). If not, your |
| 878 | test case is mostly likely going to fail. |
| 879 | |
| 880 | See also dotest.py where lldb.runHooks are processed/populated. |
| 881 | """ |
| 882 | if not lldb.runHooks: |
| 883 | self.skipTest("No runhooks specified for lldb, skip the test") |
Johnny Chen | 2a80858 | 2011-10-19 16:48:07 +0000 | [diff] [blame] | 884 | if use_cmd_api: |
| 885 | for hook in lldb.runhooks: |
| 886 | self.runCmd(hook) |
| 887 | else: |
| 888 | if not child or not child_prompt: |
| 889 | self.fail("Both child and child_prompt need to be defined.") |
| 890 | for hook in lldb.runHooks: |
| 891 | child.sendline(hook) |
| 892 | child.expect_exact(child_prompt) |
Johnny Chen | a737ba5 | 2011-10-19 01:06:21 +0000 | [diff] [blame] | 893 | |
Daniel Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 894 | def setAsync(self, value): |
| 895 | """ Sets async mode to True/False and ensures it is reset after the testcase completes.""" |
| 896 | old_async = self.dbg.GetAsync() |
| 897 | self.dbg.SetAsync(value) |
| 898 | self.addTearDownHook(lambda: self.dbg.SetAsync(old_async)) |
| 899 | |
Daniel Malea | 2dd69bb | 2013-02-15 21:21:52 +0000 | [diff] [blame] | 900 | def cleanupSubprocesses(self): |
| 901 | # Ensure any subprocesses are cleaned up |
| 902 | for p in self.subprocesses: |
| 903 | if p.poll() == None: |
| 904 | p.terminate() |
| 905 | del p |
| 906 | del self.subprocesses[:] |
Daniel Malea | 6920746 | 2013-06-05 21:07:02 +0000 | [diff] [blame] | 907 | # Ensure any forked processes are cleaned up |
| 908 | for pid in self.forkedProcessPids: |
| 909 | if os.path.exists("/proc/" + str(pid)): |
| 910 | os.kill(pid, signal.SIGTERM) |
Daniel Malea | 2dd69bb | 2013-02-15 21:21:52 +0000 | [diff] [blame] | 911 | |
| 912 | def spawnSubprocess(self, executable, args=[]): |
| 913 | """ Creates a subprocess.Popen object with the specified executable and arguments, |
| 914 | saves it in self.subprocesses, and returns the object. |
| 915 | NOTE: if using this function, ensure you also call: |
| 916 | |
| 917 | self.addTearDownHook(self.cleanupSubprocesses) |
| 918 | |
| 919 | otherwise the test suite will leak processes. |
| 920 | """ |
| 921 | |
| 922 | # Don't display the stdout if not in TraceOn() mode. |
| 923 | proc = Popen([executable] + args, |
| 924 | stdout = open(os.devnull) if not self.TraceOn() else None, |
| 925 | stdin = PIPE) |
| 926 | self.subprocesses.append(proc) |
| 927 | return proc |
| 928 | |
Daniel Malea | 6920746 | 2013-06-05 21:07:02 +0000 | [diff] [blame] | 929 | def forkSubprocess(self, executable, args=[]): |
| 930 | """ Fork a subprocess with its own group ID. |
| 931 | NOTE: if using this function, ensure you also call: |
| 932 | |
| 933 | self.addTearDownHook(self.cleanupSubprocesses) |
| 934 | |
| 935 | otherwise the test suite will leak processes. |
| 936 | """ |
| 937 | child_pid = os.fork() |
| 938 | if child_pid == 0: |
| 939 | # If more I/O support is required, this can be beefed up. |
| 940 | fd = os.open(os.devnull, os.O_RDWR) |
Daniel Malea | 6920746 | 2013-06-05 21:07:02 +0000 | [diff] [blame] | 941 | os.dup2(fd, 1) |
| 942 | os.dup2(fd, 2) |
| 943 | # This call causes the child to have its of group ID |
| 944 | os.setpgid(0,0) |
| 945 | os.execvp(executable, [executable] + args) |
| 946 | # Give the child time to get through the execvp() call |
| 947 | time.sleep(0.1) |
| 948 | self.forkedProcessPids.append(child_pid) |
| 949 | return child_pid |
| 950 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 951 | def HideStdout(self): |
| 952 | """Hide output to stdout from the user. |
| 953 | |
| 954 | During test execution, there might be cases where we don't want to show the |
| 955 | standard output to the user. For example, |
| 956 | |
| 957 | self.runCmd(r'''sc print "\n\n\tHello!\n"''') |
| 958 | |
| 959 | tests whether command abbreviation for 'script' works or not. There is no |
| 960 | need to show the 'Hello' output to the user as long as the 'script' command |
| 961 | succeeds and we are not in TraceOn() mode (see the '-t' option). |
| 962 | |
| 963 | In this case, the test method calls self.HideStdout(self) to redirect the |
| 964 | sys.stdout to a null device, and restores the sys.stdout upon teardown. |
| 965 | |
| 966 | Note that you should only call this method at most once during a test case |
| 967 | execution. Any subsequent call has no effect at all.""" |
| 968 | if self.sys_stdout_hidden: |
| 969 | return |
| 970 | |
| 971 | self.sys_stdout_hidden = True |
| 972 | old_stdout = sys.stdout |
| 973 | sys.stdout = open(os.devnull, 'w') |
| 974 | def restore_stdout(): |
| 975 | sys.stdout = old_stdout |
| 976 | self.addTearDownHook(restore_stdout) |
| 977 | |
| 978 | # ======================================================================= |
| 979 | # Methods for customized teardown cleanups as well as execution of hooks. |
| 980 | # ======================================================================= |
| 981 | |
| 982 | def setTearDownCleanup(self, dictionary=None): |
| 983 | """Register a cleanup action at tearDown() time with a dictinary""" |
| 984 | self.dict = dictionary |
| 985 | self.doTearDownCleanup = True |
| 986 | |
| 987 | def addTearDownCleanup(self, dictionary): |
| 988 | """Add a cleanup action at tearDown() time with a dictinary""" |
| 989 | self.dicts.append(dictionary) |
| 990 | self.doTearDownCleanups = True |
| 991 | |
| 992 | def addTearDownHook(self, hook): |
| 993 | """ |
| 994 | Add a function to be run during tearDown() time. |
| 995 | |
| 996 | Hooks are executed in a first come first serve manner. |
| 997 | """ |
| 998 | if callable(hook): |
| 999 | with recording(self, traceAlways) as sbuf: |
| 1000 | print >> sbuf, "Adding tearDown hook:", getsource_if_available(hook) |
| 1001 | self.hooks.append(hook) |
Enrico Granata | ab0e831 | 2014-11-05 21:31:57 +0000 | [diff] [blame] | 1002 | |
| 1003 | return self |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1004 | |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 1005 | def deletePexpectChild(self): |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 1006 | # This is for the case of directly spawning 'lldb' and interacting with it |
| 1007 | # using pexpect. |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 1008 | if self.child and self.child.isalive(): |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 1009 | import pexpect |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 1010 | with recording(self, traceAlways) as sbuf: |
| 1011 | print >> sbuf, "tearing down the child process...." |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 1012 | try: |
Daniel Malea | c9a0ec3 | 2013-02-22 00:41:26 +0000 | [diff] [blame] | 1013 | if self.child_in_script_interpreter: |
| 1014 | self.child.sendline('quit()') |
| 1015 | self.child.expect_exact(self.child_prompt) |
| 1016 | self.child.sendline('settings set interpreter.prompt-on-quit false') |
| 1017 | self.child.sendline('quit') |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 1018 | self.child.expect(pexpect.EOF) |
Jim Ingham | 65b3f54 | 2014-10-24 18:51:57 +0000 | [diff] [blame] | 1019 | except (ValueError, pexpect.ExceptionPexpect): |
Daniel Malea | c9a0ec3 | 2013-02-22 00:41:26 +0000 | [diff] [blame] | 1020 | # child is already terminated |
Johnny Chen | 985e740 | 2011-08-01 21:13:26 +0000 | [diff] [blame] | 1021 | pass |
Shawn Best | eb3e905 | 2014-11-06 17:52:15 +0000 | [diff] [blame^] | 1022 | finally: |
| 1023 | # Give it one final blow to make sure the child is terminated. |
| 1024 | self.child.close() |
Jim Ingham | da3a386 | 2014-10-16 23:02:14 +0000 | [diff] [blame] | 1025 | |
| 1026 | def tearDown(self): |
| 1027 | """Fixture for unittest test case teardown.""" |
| 1028 | #import traceback |
| 1029 | #traceback.print_stack() |
| 1030 | |
| 1031 | self.deletePexpectChild() |
| 1032 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1033 | # Check and run any hook functions. |
| 1034 | for hook in reversed(self.hooks): |
| 1035 | with recording(self, traceAlways) as sbuf: |
| 1036 | print >> sbuf, "Executing tearDown hook:", getsource_if_available(hook) |
Enrico Granata | ab0e831 | 2014-11-05 21:31:57 +0000 | [diff] [blame] | 1037 | import inspect |
| 1038 | hook_argc = len(inspect.getargspec(hook).args) |
| 1039 | if hook_argc == 0: |
| 1040 | hook() |
| 1041 | elif hook_argc == 1: |
| 1042 | hook(self) |
| 1043 | else: |
| 1044 | hook() # try the plain call and hope it works |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1045 | |
| 1046 | del self.hooks |
| 1047 | |
| 1048 | # Perform registered teardown cleanup. |
| 1049 | if doCleanup and self.doTearDownCleanup: |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1050 | self.cleanup(dictionary=self.dict) |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1051 | |
| 1052 | # In rare cases where there are multiple teardown cleanups added. |
| 1053 | if doCleanup and self.doTearDownCleanups: |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1054 | if self.dicts: |
| 1055 | for dict in reversed(self.dicts): |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1056 | self.cleanup(dictionary=dict) |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1057 | |
| 1058 | # Decide whether to dump the session info. |
| 1059 | self.dumpSessionInfo() |
| 1060 | |
| 1061 | # ========================================================= |
| 1062 | # Various callbacks to allow introspection of test progress |
| 1063 | # ========================================================= |
| 1064 | |
| 1065 | def markError(self): |
| 1066 | """Callback invoked when an error (unexpected exception) errored.""" |
| 1067 | self.__errored__ = True |
| 1068 | with recording(self, False) as sbuf: |
| 1069 | # False because there's no need to write "ERROR" to the stderr twice. |
| 1070 | # Once by the Python unittest framework, and a second time by us. |
| 1071 | print >> sbuf, "ERROR" |
| 1072 | |
| 1073 | def markFailure(self): |
| 1074 | """Callback invoked when a failure (test assertion failure) occurred.""" |
| 1075 | self.__failed__ = True |
| 1076 | with recording(self, False) as sbuf: |
| 1077 | # False because there's no need to write "FAIL" to the stderr twice. |
| 1078 | # Once by the Python unittest framework, and a second time by us. |
| 1079 | print >> sbuf, "FAIL" |
| 1080 | |
Enrico Granata | e6cedc1 | 2013-02-23 01:05:23 +0000 | [diff] [blame] | 1081 | def markExpectedFailure(self,err,bugnumber): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1082 | """Callback invoked when an expected failure/error occurred.""" |
| 1083 | self.__expected__ = True |
| 1084 | with recording(self, False) as sbuf: |
| 1085 | # False because there's no need to write "expected failure" to the |
| 1086 | # stderr twice. |
| 1087 | # Once by the Python unittest framework, and a second time by us. |
Enrico Granata | e6cedc1 | 2013-02-23 01:05:23 +0000 | [diff] [blame] | 1088 | if bugnumber == None: |
| 1089 | print >> sbuf, "expected failure" |
| 1090 | else: |
| 1091 | print >> sbuf, "expected failure (problem id:" + str(bugnumber) + ")" |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1092 | |
Johnny Chen | c5cc625 | 2011-08-15 23:09:08 +0000 | [diff] [blame] | 1093 | def markSkippedTest(self): |
| 1094 | """Callback invoked when a test is skipped.""" |
| 1095 | self.__skipped__ = True |
| 1096 | with recording(self, False) as sbuf: |
| 1097 | # False because there's no need to write "skipped test" to the |
| 1098 | # stderr twice. |
| 1099 | # Once by the Python unittest framework, and a second time by us. |
| 1100 | print >> sbuf, "skipped test" |
| 1101 | |
Enrico Granata | e6cedc1 | 2013-02-23 01:05:23 +0000 | [diff] [blame] | 1102 | def markUnexpectedSuccess(self, bugnumber): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1103 | """Callback invoked when an unexpected success occurred.""" |
| 1104 | self.__unexpected__ = True |
| 1105 | with recording(self, False) as sbuf: |
| 1106 | # False because there's no need to write "unexpected success" to the |
| 1107 | # stderr twice. |
| 1108 | # Once by the Python unittest framework, and a second time by us. |
Enrico Granata | e6cedc1 | 2013-02-23 01:05:23 +0000 | [diff] [blame] | 1109 | if bugnumber == None: |
| 1110 | print >> sbuf, "unexpected success" |
| 1111 | else: |
| 1112 | print >> sbuf, "unexpected success (problem id:" + str(bugnumber) + ")" |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1113 | |
| 1114 | def dumpSessionInfo(self): |
| 1115 | """ |
| 1116 | Dump the debugger interactions leading to a test error/failure. This |
| 1117 | allows for more convenient postmortem analysis. |
| 1118 | |
| 1119 | See also LLDBTestResult (dotest.py) which is a singlton class derived |
| 1120 | from TextTestResult and overwrites addError, addFailure, and |
| 1121 | addExpectedFailure methods to allow us to to mark the test instance as |
| 1122 | such. |
| 1123 | """ |
| 1124 | |
| 1125 | # We are here because self.tearDown() detected that this test instance |
| 1126 | # either errored or failed. The lldb.test_result singleton contains |
| 1127 | # two lists (erros and failures) which get populated by the unittest |
| 1128 | # framework. Look over there for stack trace information. |
| 1129 | # |
| 1130 | # The lists contain 2-tuples of TestCase instances and strings holding |
| 1131 | # formatted tracebacks. |
| 1132 | # |
| 1133 | # See http://docs.python.org/library/unittest.html#unittest.TestResult. |
| 1134 | if self.__errored__: |
| 1135 | pairs = lldb.test_result.errors |
| 1136 | prefix = 'Error' |
| 1137 | elif self.__failed__: |
| 1138 | pairs = lldb.test_result.failures |
| 1139 | prefix = 'Failure' |
| 1140 | elif self.__expected__: |
| 1141 | pairs = lldb.test_result.expectedFailures |
| 1142 | prefix = 'ExpectedFailure' |
Johnny Chen | c5cc625 | 2011-08-15 23:09:08 +0000 | [diff] [blame] | 1143 | elif self.__skipped__: |
| 1144 | prefix = 'SkippedTest' |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1145 | elif self.__unexpected__: |
| 1146 | prefix = "UnexpectedSuccess" |
| 1147 | else: |
| 1148 | # Simply return, there's no session info to dump! |
| 1149 | return |
| 1150 | |
Johnny Chen | c5cc625 | 2011-08-15 23:09:08 +0000 | [diff] [blame] | 1151 | if not self.__unexpected__ and not self.__skipped__: |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1152 | for test, traceback in pairs: |
| 1153 | if test is self: |
| 1154 | print >> self.session, traceback |
| 1155 | |
Johnny Chen | 8082a00 | 2011-08-11 00:16:28 +0000 | [diff] [blame] | 1156 | testMethod = getattr(self, self._testMethodName) |
| 1157 | if getattr(testMethod, "__benchmarks_test__", False): |
| 1158 | benchmarks = True |
| 1159 | else: |
| 1160 | benchmarks = False |
| 1161 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1162 | dname = os.path.join(os.environ["LLDB_TEST"], |
| 1163 | os.environ["LLDB_SESSION_DIRNAME"]) |
| 1164 | if not os.path.isdir(dname): |
| 1165 | os.mkdir(dname) |
Zachary Turner | 756acba | 2014-10-14 21:54:14 +0000 | [diff] [blame] | 1166 | compiler = self.getCompiler() |
| 1167 | if compiler[1] == ':': |
| 1168 | compiler = compiler[2:] |
| 1169 | |
| 1170 | fname = os.path.join(dname, "%s-%s-%s-%s.log" % (prefix, self.getArchitecture(), "_".join(compiler.split(os.path.sep)), self.id())) |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1171 | with open(fname, "w") as f: |
| 1172 | import datetime |
| 1173 | print >> f, "Session info generated @", datetime.datetime.now().ctime() |
| 1174 | print >> f, self.session.getvalue() |
| 1175 | print >> f, "To rerun this test, issue the following command from the 'test' directory:\n" |
Johnny Chen | 8082a00 | 2011-08-11 00:16:28 +0000 | [diff] [blame] | 1176 | print >> f, "./dotest.py %s -v %s -f %s.%s" % (self.getRunOptions(), |
| 1177 | ('+b' if benchmarks else '-t'), |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1178 | self.__class__.__name__, |
| 1179 | self._testMethodName) |
| 1180 | |
| 1181 | # ==================================================== |
| 1182 | # Config. methods supported through a plugin interface |
| 1183 | # (enables reading of the current test configuration) |
| 1184 | # ==================================================== |
| 1185 | |
| 1186 | def getArchitecture(self): |
| 1187 | """Returns the architecture in effect the test suite is running with.""" |
| 1188 | module = builder_module() |
| 1189 | return module.getArchitecture() |
| 1190 | |
| 1191 | def getCompiler(self): |
| 1192 | """Returns the compiler in effect the test suite is running with.""" |
| 1193 | module = builder_module() |
| 1194 | return module.getCompiler() |
| 1195 | |
Daniel Malea | 0aea016 | 2013-02-27 17:29:46 +0000 | [diff] [blame] | 1196 | def getCompilerVersion(self): |
| 1197 | """ Returns a string that represents the compiler version. |
| 1198 | Supports: llvm, clang. |
| 1199 | """ |
| 1200 | from lldbutil import which |
| 1201 | version = 'unknown' |
| 1202 | |
| 1203 | compiler = self.getCompiler() |
Zachary Turner | 9ef307b | 2014-07-22 16:19:29 +0000 | [diff] [blame] | 1204 | version_output = system([[which(compiler), "-v"]])[1] |
Daniel Malea | 0aea016 | 2013-02-27 17:29:46 +0000 | [diff] [blame] | 1205 | for line in version_output.split(os.linesep): |
Greg Clayton | 2a844b7 | 2013-03-06 02:34:51 +0000 | [diff] [blame] | 1206 | m = re.search('version ([0-9\.]+)', line) |
Daniel Malea | 0aea016 | 2013-02-27 17:29:46 +0000 | [diff] [blame] | 1207 | if m: |
| 1208 | version = m.group(1) |
| 1209 | return version |
| 1210 | |
Daniel Malea | adaaec9 | 2013-08-06 20:51:41 +0000 | [diff] [blame] | 1211 | def isIntelCompiler(self): |
| 1212 | """ Returns true if using an Intel (ICC) compiler, false otherwise. """ |
| 1213 | return any([x in self.getCompiler() for x in ["icc", "icpc", "icl"]]) |
| 1214 | |
Ashok Thirumurthi | 3b03728 | 2013-06-06 14:23:31 +0000 | [diff] [blame] | 1215 | def expectedCompilerVersion(self, compiler_version): |
| 1216 | """Returns True iff compiler_version[1] matches the current compiler version. |
| 1217 | Use compiler_version[0] to specify the operator used to determine if a match has occurred. |
| 1218 | Any operator other than the following defaults to an equality test: |
| 1219 | '>', '>=', "=>", '<', '<=', '=<', '!=', "!" or 'not' |
| 1220 | """ |
Ashok Thirumurthi | c97a608 | 2013-05-17 20:15:07 +0000 | [diff] [blame] | 1221 | if (compiler_version == None): |
| 1222 | return True |
| 1223 | operator = str(compiler_version[0]) |
| 1224 | version = compiler_version[1] |
| 1225 | |
| 1226 | if (version == None): |
| 1227 | return True |
| 1228 | if (operator == '>'): |
| 1229 | return self.getCompilerVersion() > version |
| 1230 | if (operator == '>=' or operator == '=>'): |
| 1231 | return self.getCompilerVersion() >= version |
| 1232 | if (operator == '<'): |
| 1233 | return self.getCompilerVersion() < version |
| 1234 | if (operator == '<=' or operator == '=<'): |
| 1235 | return self.getCompilerVersion() <= version |
| 1236 | if (operator == '!=' or operator == '!' or operator == 'not'): |
| 1237 | return str(version) not in str(self.getCompilerVersion()) |
| 1238 | return str(version) in str(self.getCompilerVersion()) |
| 1239 | |
| 1240 | def expectedCompiler(self, compilers): |
Ashok Thirumurthi | 3b03728 | 2013-06-06 14:23:31 +0000 | [diff] [blame] | 1241 | """Returns True iff any element of compilers is a sub-string of the current compiler.""" |
Ashok Thirumurthi | c97a608 | 2013-05-17 20:15:07 +0000 | [diff] [blame] | 1242 | if (compilers == None): |
| 1243 | return True |
Ashok Thirumurthi | 3b03728 | 2013-06-06 14:23:31 +0000 | [diff] [blame] | 1244 | |
| 1245 | for compiler in compilers: |
| 1246 | if compiler in self.getCompiler(): |
| 1247 | return True |
| 1248 | |
| 1249 | return False |
Ashok Thirumurthi | c97a608 | 2013-05-17 20:15:07 +0000 | [diff] [blame] | 1250 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1251 | def getRunOptions(self): |
| 1252 | """Command line option for -A and -C to run this test again, called from |
| 1253 | self.dumpSessionInfo().""" |
| 1254 | arch = self.getArchitecture() |
| 1255 | comp = self.getCompiler() |
Johnny Chen | b7bdd10 | 2011-08-24 19:48:51 +0000 | [diff] [blame] | 1256 | if arch: |
| 1257 | option_str = "-A " + arch |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1258 | else: |
Johnny Chen | b7bdd10 | 2011-08-24 19:48:51 +0000 | [diff] [blame] | 1259 | option_str = "" |
| 1260 | if comp: |
Johnny Chen | 531c085 | 2012-03-16 20:44:00 +0000 | [diff] [blame] | 1261 | option_str += " -C " + comp |
Johnny Chen | b7bdd10 | 2011-08-24 19:48:51 +0000 | [diff] [blame] | 1262 | return option_str |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1263 | |
| 1264 | # ================================================== |
| 1265 | # Build methods supported through a plugin interface |
| 1266 | # ================================================== |
| 1267 | |
Ed Maste | c97323e | 2014-04-01 18:47:58 +0000 | [diff] [blame] | 1268 | def getstdlibFlag(self): |
| 1269 | """ Returns the proper -stdlib flag, or empty if not required.""" |
| 1270 | if sys.platform.startswith("darwin") or sys.platform.startswith("freebsd"): |
| 1271 | stdlibflag = "-stdlib=libc++" |
| 1272 | else: |
| 1273 | stdlibflag = "" |
| 1274 | return stdlibflag |
| 1275 | |
Matt Kopec | 7663b3a | 2013-09-25 17:44:00 +0000 | [diff] [blame] | 1276 | def getstdFlag(self): |
| 1277 | """ Returns the proper stdflag. """ |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1278 | if "gcc" in self.getCompiler() and "4.6" in self.getCompilerVersion(): |
Daniel Malea | 0b7c611 | 2013-05-06 19:31:31 +0000 | [diff] [blame] | 1279 | stdflag = "-std=c++0x" |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1280 | else: |
| 1281 | stdflag = "-std=c++11" |
Matt Kopec | 7663b3a | 2013-09-25 17:44:00 +0000 | [diff] [blame] | 1282 | return stdflag |
| 1283 | |
| 1284 | def buildDriver(self, sources, exe_name): |
| 1285 | """ Platform-specific way to build a program that links with LLDB (via the liblldb.so |
| 1286 | or LLDB.framework). |
| 1287 | """ |
| 1288 | |
| 1289 | stdflag = self.getstdFlag() |
Ed Maste | c97323e | 2014-04-01 18:47:58 +0000 | [diff] [blame] | 1290 | stdlibflag = self.getstdlibFlag() |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1291 | |
| 1292 | if sys.platform.startswith("darwin"): |
| 1293 | dsym = os.path.join(self.lib_dir, 'LLDB.framework', 'LLDB') |
| 1294 | d = {'CXX_SOURCES' : sources, |
| 1295 | 'EXE' : exe_name, |
Ed Maste | c97323e | 2014-04-01 18:47:58 +0000 | [diff] [blame] | 1296 | 'CFLAGS_EXTRAS' : "%s %s" % (stdflag, stdlibflag), |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1297 | 'FRAMEWORK_INCLUDES' : "-F%s" % self.lib_dir, |
Stefanus Du Toit | 0400444 | 2013-07-30 19:19:49 +0000 | [diff] [blame] | 1298 | 'LD_EXTRAS' : "%s -Wl,-rpath,%s" % (dsym, self.lib_dir), |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1299 | } |
Ed Maste | 372c24d | 2013-07-25 21:02:34 +0000 | [diff] [blame] | 1300 | elif sys.platform.startswith('freebsd') or sys.platform.startswith("linux") or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile': |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1301 | d = {'CXX_SOURCES' : sources, |
| 1302 | 'EXE' : exe_name, |
Ed Maste | c97323e | 2014-04-01 18:47:58 +0000 | [diff] [blame] | 1303 | 'CFLAGS_EXTRAS' : "%s %s -I%s" % (stdflag, stdlibflag, os.path.join(os.environ["LLDB_SRC"], "include")), |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1304 | 'LD_EXTRAS' : "-L%s -llldb" % self.lib_dir} |
| 1305 | if self.TraceOn(): |
| 1306 | print "Building LLDB Driver (%s) from sources %s" % (exe_name, sources) |
| 1307 | |
| 1308 | self.buildDefault(dictionary=d) |
| 1309 | |
Matt Kopec | 7663b3a | 2013-09-25 17:44:00 +0000 | [diff] [blame] | 1310 | def buildLibrary(self, sources, lib_name): |
| 1311 | """Platform specific way to build a default library. """ |
| 1312 | |
| 1313 | stdflag = self.getstdFlag() |
| 1314 | |
| 1315 | if sys.platform.startswith("darwin"): |
| 1316 | dsym = os.path.join(self.lib_dir, 'LLDB.framework', 'LLDB') |
| 1317 | d = {'DYLIB_CXX_SOURCES' : sources, |
| 1318 | 'DYLIB_NAME' : lib_name, |
| 1319 | 'CFLAGS_EXTRAS' : "%s -stdlib=libc++" % stdflag, |
| 1320 | 'FRAMEWORK_INCLUDES' : "-F%s" % self.lib_dir, |
| 1321 | 'LD_EXTRAS' : "%s -Wl,-rpath,%s -dynamiclib" % (dsym, self.lib_dir), |
| 1322 | } |
| 1323 | elif sys.platform.startswith('freebsd') or sys.platform.startswith("linux") or os.environ.get('LLDB_BUILD_TYPE') == 'Makefile': |
| 1324 | d = {'DYLIB_CXX_SOURCES' : sources, |
| 1325 | 'DYLIB_NAME' : lib_name, |
| 1326 | 'CFLAGS_EXTRAS' : "%s -I%s -fPIC" % (stdflag, os.path.join(os.environ["LLDB_SRC"], "include")), |
| 1327 | 'LD_EXTRAS' : "-shared -L%s -llldb" % self.lib_dir} |
| 1328 | if self.TraceOn(): |
| 1329 | print "Building LLDB Library (%s) from sources %s" % (lib_name, sources) |
| 1330 | |
| 1331 | self.buildDefault(dictionary=d) |
| 1332 | |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1333 | def buildProgram(self, sources, exe_name): |
| 1334 | """ Platform specific way to build an executable from C/C++ sources. """ |
| 1335 | d = {'CXX_SOURCES' : sources, |
| 1336 | 'EXE' : exe_name} |
| 1337 | self.buildDefault(dictionary=d) |
| 1338 | |
Johnny Chen | fdc80a5c | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 1339 | def buildDefault(self, architecture=None, compiler=None, dictionary=None, clean=True): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1340 | """Platform specific way to build the default binaries.""" |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1341 | if lldb.skip_build_and_cleanup: |
| 1342 | return |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1343 | module = builder_module() |
Johnny Chen | fdc80a5c | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 1344 | if not module.buildDefault(self, architecture, compiler, dictionary, clean): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1345 | raise Exception("Don't know how to build default binary") |
| 1346 | |
Johnny Chen | fdc80a5c | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 1347 | def buildDsym(self, architecture=None, compiler=None, dictionary=None, clean=True): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1348 | """Platform specific way to build binaries with dsym info.""" |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1349 | if lldb.skip_build_and_cleanup: |
| 1350 | return |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1351 | module = builder_module() |
Johnny Chen | fdc80a5c | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 1352 | if not module.buildDsym(self, architecture, compiler, dictionary, clean): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1353 | raise Exception("Don't know how to build binary with dsym") |
| 1354 | |
Johnny Chen | fdc80a5c | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 1355 | def buildDwarf(self, architecture=None, compiler=None, dictionary=None, clean=True): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1356 | """Platform specific way to build binaries with dwarf maps.""" |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1357 | if lldb.skip_build_and_cleanup: |
| 1358 | return |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1359 | module = builder_module() |
Johnny Chen | fdc80a5c | 2012-02-01 01:49:50 +0000 | [diff] [blame] | 1360 | if not module.buildDwarf(self, architecture, compiler, dictionary, clean): |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1361 | raise Exception("Don't know how to build binary with dwarf") |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 1362 | |
Kuba Brecka | beed821 | 2014-09-04 01:03:18 +0000 | [diff] [blame] | 1363 | def findBuiltClang(self): |
| 1364 | """Tries to find and use Clang from the build directory as the compiler (instead of the system compiler).""" |
| 1365 | paths_to_try = [ |
| 1366 | "llvm-build/Release+Asserts/x86_64/Release+Asserts/bin/clang", |
| 1367 | "llvm-build/Debug+Asserts/x86_64/Debug+Asserts/bin/clang", |
| 1368 | "llvm-build/Release/x86_64/Release/bin/clang", |
| 1369 | "llvm-build/Debug/x86_64/Debug/bin/clang", |
| 1370 | ] |
| 1371 | lldb_root_path = os.path.join(os.path.dirname(__file__), "..") |
| 1372 | for p in paths_to_try: |
| 1373 | path = os.path.join(lldb_root_path, p) |
| 1374 | if os.path.exists(path): |
| 1375 | return path |
| 1376 | |
| 1377 | return os.environ["CC"] |
| 1378 | |
Daniel Malea | 9115f07 | 2013-08-06 15:02:32 +0000 | [diff] [blame] | 1379 | def getBuildFlags(self, use_cpp11=True, use_libcxx=False, use_libstdcxx=False, use_pthreads=True): |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 1380 | """ Returns a dictionary (which can be provided to build* functions above) which |
| 1381 | contains OS-specific build flags. |
| 1382 | """ |
| 1383 | cflags = "" |
Daniel Malea | 9115f07 | 2013-08-06 15:02:32 +0000 | [diff] [blame] | 1384 | |
| 1385 | # On Mac OS X, unless specifically requested to use libstdc++, use libc++ |
| 1386 | if not use_libstdcxx and sys.platform.startswith('darwin'): |
| 1387 | use_libcxx = True |
| 1388 | |
| 1389 | if use_libcxx and self.libcxxPath: |
| 1390 | cflags += "-stdlib=libc++ " |
| 1391 | if self.libcxxPath: |
| 1392 | libcxxInclude = os.path.join(self.libcxxPath, "include") |
| 1393 | libcxxLib = os.path.join(self.libcxxPath, "lib") |
| 1394 | if os.path.isdir(libcxxInclude) and os.path.isdir(libcxxLib): |
| 1395 | cflags += "-nostdinc++ -I%s -L%s -Wl,-rpath,%s " % (libcxxInclude, libcxxLib, libcxxLib) |
| 1396 | |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 1397 | if use_cpp11: |
| 1398 | cflags += "-std=" |
| 1399 | if "gcc" in self.getCompiler() and "4.6" in self.getCompilerVersion(): |
| 1400 | cflags += "c++0x" |
| 1401 | else: |
| 1402 | cflags += "c++11" |
Ed Maste | dbd5950 | 2014-02-02 19:24:15 +0000 | [diff] [blame] | 1403 | if sys.platform.startswith("darwin") or sys.platform.startswith("freebsd"): |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 1404 | cflags += " -stdlib=libc++" |
| 1405 | elif "clang" in self.getCompiler(): |
| 1406 | cflags += " -stdlib=libstdc++" |
| 1407 | |
| 1408 | if use_pthreads: |
| 1409 | ldflags = "-lpthread" |
| 1410 | |
| 1411 | return {'CFLAGS_EXTRAS' : cflags, |
| 1412 | 'LD_EXTRAS' : ldflags, |
| 1413 | } |
| 1414 | |
Johnny Chen | 9f4f5d9 | 2011-08-12 20:19:22 +0000 | [diff] [blame] | 1415 | def cleanup(self, dictionary=None): |
| 1416 | """Platform specific way to do cleanup after build.""" |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1417 | if lldb.skip_build_and_cleanup: |
| 1418 | return |
Johnny Chen | 9f4f5d9 | 2011-08-12 20:19:22 +0000 | [diff] [blame] | 1419 | module = builder_module() |
| 1420 | if not module.cleanup(self, dictionary): |
Johnny Chen | 0fddfb2 | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 1421 | raise Exception("Don't know how to do cleanup with dictionary: "+dictionary) |
Johnny Chen | 9f4f5d9 | 2011-08-12 20:19:22 +0000 | [diff] [blame] | 1422 | |
Daniel Malea | 55faa40 | 2013-05-02 21:44:31 +0000 | [diff] [blame] | 1423 | def getLLDBLibraryEnvVal(self): |
| 1424 | """ Returns the path that the OS-specific library search environment variable |
| 1425 | (self.dylibPath) should be set to in order for a program to find the LLDB |
| 1426 | library. If an environment variable named self.dylibPath is already set, |
| 1427 | the new path is appended to it and returned. |
| 1428 | """ |
| 1429 | existing_library_path = os.environ[self.dylibPath] if self.dylibPath in os.environ else None |
| 1430 | if existing_library_path: |
| 1431 | return "%s:%s" % (existing_library_path, self.lib_dir) |
| 1432 | elif sys.platform.startswith("darwin"): |
| 1433 | return os.path.join(self.lib_dir, 'LLDB.framework') |
| 1434 | else: |
| 1435 | return self.lib_dir |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 1436 | |
Ed Maste | 437f8f6 | 2013-09-09 14:04:04 +0000 | [diff] [blame] | 1437 | def getLibcPlusPlusLibs(self): |
| 1438 | if sys.platform.startswith('freebsd'): |
| 1439 | return ['libc++.so.1'] |
| 1440 | else: |
| 1441 | return ['libc++.1.dylib','libc++abi.dylib'] |
| 1442 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 1443 | class TestBase(Base): |
| 1444 | """ |
| 1445 | This abstract base class is meant to be subclassed. It provides default |
| 1446 | implementations for setUpClass(), tearDownClass(), setUp(), and tearDown(), |
| 1447 | among other things. |
| 1448 | |
| 1449 | Important things for test class writers: |
| 1450 | |
| 1451 | - Overwrite the mydir class attribute, otherwise your test class won't |
| 1452 | run. It specifies the relative directory to the top level 'test' so |
| 1453 | the test harness can change to the correct working directory before |
| 1454 | running your test. |
| 1455 | |
| 1456 | - The setUp method sets up things to facilitate subsequent interactions |
| 1457 | with the debugger as part of the test. These include: |
| 1458 | - populate the test method name |
| 1459 | - create/get a debugger set with synchronous mode (self.dbg) |
| 1460 | - get the command interpreter from with the debugger (self.ci) |
| 1461 | - create a result object for use with the command interpreter |
| 1462 | (self.res) |
| 1463 | - plus other stuffs |
| 1464 | |
| 1465 | - The tearDown method tries to perform some necessary cleanup on behalf |
| 1466 | of the test to return the debugger to a good state for the next test. |
| 1467 | These include: |
| 1468 | - execute any tearDown hooks registered by the test method with |
| 1469 | TestBase.addTearDownHook(); examples can be found in |
| 1470 | settings/TestSettings.py |
| 1471 | - kill the inferior process associated with each target, if any, |
| 1472 | and, then delete the target from the debugger's target list |
| 1473 | - perform build cleanup before running the next test method in the |
| 1474 | same test class; examples of registering for this service can be |
| 1475 | found in types/TestIntegerTypes.py with the call: |
| 1476 | - self.setTearDownCleanup(dictionary=d) |
| 1477 | |
| 1478 | - Similarly setUpClass and tearDownClass perform classwise setup and |
| 1479 | teardown fixtures. The tearDownClass method invokes a default build |
| 1480 | cleanup for the entire test class; also, subclasses can implement the |
| 1481 | classmethod classCleanup(cls) to perform special class cleanup action. |
| 1482 | |
| 1483 | - The instance methods runCmd and expect are used heavily by existing |
| 1484 | test cases to send a command to the command interpreter and to perform |
| 1485 | string/pattern matching on the output of such command execution. The |
| 1486 | expect method also provides a mode to peform string/pattern matching |
| 1487 | without running a command. |
| 1488 | |
| 1489 | - The build methods buildDefault, buildDsym, and buildDwarf are used to |
| 1490 | build the binaries used during a particular test scenario. A plugin |
| 1491 | should be provided for the sys.platform running the test suite. The |
| 1492 | Mac OS X implementation is located in plugins/darwin.py. |
| 1493 | """ |
| 1494 | |
| 1495 | # Maximum allowed attempts when launching the inferior process. |
| 1496 | # Can be overridden by the LLDB_MAX_LAUNCH_COUNT environment variable. |
| 1497 | maxLaunchCount = 3; |
| 1498 | |
| 1499 | # Time to wait before the next launching attempt in second(s). |
| 1500 | # Can be overridden by the LLDB_TIME_WAIT_NEXT_LAUNCH environment variable. |
| 1501 | timeWaitNextLaunch = 1.0; |
| 1502 | |
| 1503 | def doDelay(self): |
| 1504 | """See option -w of dotest.py.""" |
| 1505 | if ("LLDB_WAIT_BETWEEN_TEST_CASES" in os.environ and |
| 1506 | os.environ["LLDB_WAIT_BETWEEN_TEST_CASES"] == 'YES'): |
| 1507 | waitTime = 1.0 |
| 1508 | if "LLDB_TIME_WAIT_BETWEEN_TEST_CASES" in os.environ: |
| 1509 | waitTime = float(os.environ["LLDB_TIME_WAIT_BETWEEN_TEST_CASES"]) |
| 1510 | time.sleep(waitTime) |
| 1511 | |
Enrico Granata | 165f8af | 2012-09-21 19:10:53 +0000 | [diff] [blame] | 1512 | # Returns the list of categories to which this test case belongs |
| 1513 | # by default, look for a ".categories" file, and read its contents |
| 1514 | # if no such file exists, traverse the hierarchy - we guarantee |
| 1515 | # a .categories to exist at the top level directory so we do not end up |
| 1516 | # looping endlessly - subclasses are free to define their own categories |
| 1517 | # in whatever way makes sense to them |
| 1518 | def getCategories(self): |
| 1519 | import inspect |
| 1520 | import os.path |
| 1521 | folder = inspect.getfile(self.__class__) |
| 1522 | folder = os.path.dirname(folder) |
| 1523 | while folder != '/': |
| 1524 | categories_file_name = os.path.join(folder,".categories") |
| 1525 | if os.path.exists(categories_file_name): |
| 1526 | categories_file = open(categories_file_name,'r') |
| 1527 | categories = categories_file.readline() |
| 1528 | categories_file.close() |
| 1529 | categories = str.replace(categories,'\n','') |
| 1530 | categories = str.replace(categories,'\r','') |
| 1531 | return categories.split(',') |
| 1532 | else: |
| 1533 | folder = os.path.dirname(folder) |
| 1534 | continue |
| 1535 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 1536 | def setUp(self): |
| 1537 | #import traceback |
| 1538 | #traceback.print_stack() |
| 1539 | |
| 1540 | # Works with the test driver to conditionally skip tests via decorators. |
| 1541 | Base.setUp(self) |
| 1542 | |
Johnny Chen | a74bb0a | 2011-08-01 18:46:13 +0000 | [diff] [blame] | 1543 | try: |
| 1544 | if lldb.blacklist: |
| 1545 | className = self.__class__.__name__ |
| 1546 | classAndMethodName = "%s.%s" % (className, self._testMethodName) |
| 1547 | if className in lldb.blacklist: |
| 1548 | self.skipTest(lldb.blacklist.get(className)) |
| 1549 | elif classAndMethodName in lldb.blacklist: |
| 1550 | self.skipTest(lldb.blacklist.get(classAndMethodName)) |
| 1551 | except AttributeError: |
| 1552 | pass |
| 1553 | |
Johnny Chen | ed49202 | 2011-06-21 00:53:00 +0000 | [diff] [blame] | 1554 | # Insert some delay between successive test cases if specified. |
| 1555 | self.doDelay() |
Johnny Chen | 0ed37c9 | 2010-10-07 02:04:14 +0000 | [diff] [blame] | 1556 | |
Johnny Chen | f2b7023 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 1557 | if "LLDB_MAX_LAUNCH_COUNT" in os.environ: |
| 1558 | self.maxLaunchCount = int(os.environ["LLDB_MAX_LAUNCH_COUNT"]) |
| 1559 | |
Johnny Chen | 430eb76 | 2010-10-19 16:00:42 +0000 | [diff] [blame] | 1560 | if "LLDB_TIME_WAIT_NEXT_LAUNCH" in os.environ: |
Johnny Chen | 4921b11 | 2010-11-29 20:20:34 +0000 | [diff] [blame] | 1561 | self.timeWaitNextLaunch = float(os.environ["LLDB_TIME_WAIT_NEXT_LAUNCH"]) |
Johnny Chen | f2b7023 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 1562 | |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1563 | # Create the debugger instance if necessary. |
| 1564 | try: |
| 1565 | self.dbg = lldb.DBG |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1566 | except AttributeError: |
| 1567 | self.dbg = lldb.SBDebugger.Create() |
Johnny Chen | f02ec12 | 2010-07-03 20:41:42 +0000 | [diff] [blame] | 1568 | |
Johnny Chen | 3cd1e55 | 2011-05-25 19:06:18 +0000 | [diff] [blame] | 1569 | if not self.dbg: |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1570 | raise Exception('Invalid debugger instance') |
| 1571 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1572 | # |
| 1573 | # Warning: MAJOR HACK AHEAD! |
| 1574 | # If we are running testsuite remotely (by checking lldb.lldbtest_remote_sandbox), |
| 1575 | # redefine the self.dbg.CreateTarget(filename) method to execute a "file filename" |
| 1576 | # command, instead. See also runCmd() where it decorates the "file filename" call |
| 1577 | # with additional functionality when running testsuite remotely. |
| 1578 | # |
| 1579 | if lldb.lldbtest_remote_sandbox: |
| 1580 | def DecoratedCreateTarget(arg): |
| 1581 | self.runCmd("file %s" % arg) |
| 1582 | target = self.dbg.GetSelectedTarget() |
| 1583 | # |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 1584 | # SBtarget.LaunchSimple () currently not working for remote platform? |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1585 | # johnny @ 04/23/2012 |
| 1586 | # |
| 1587 | def DecoratedLaunchSimple(argv, envp, wd): |
| 1588 | self.runCmd("run") |
| 1589 | return target.GetProcess() |
| 1590 | target.LaunchSimple = DecoratedLaunchSimple |
| 1591 | |
| 1592 | return target |
| 1593 | self.dbg.CreateTarget = DecoratedCreateTarget |
| 1594 | if self.TraceOn(): |
| 1595 | print "self.dbg.Create is redefined to:\n%s" % getsource_if_available(DecoratedCreateTarget) |
| 1596 | |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1597 | # We want our debugger to be synchronous. |
| 1598 | self.dbg.SetAsync(False) |
| 1599 | |
| 1600 | # Retrieve the associated command interpreter instance. |
| 1601 | self.ci = self.dbg.GetCommandInterpreter() |
| 1602 | if not self.ci: |
| 1603 | raise Exception('Could not get the command interpreter') |
| 1604 | |
| 1605 | # And the result object. |
| 1606 | self.res = lldb.SBCommandReturnObject() |
| 1607 | |
Johnny Chen | 44d2497 | 2012-04-16 18:55:15 +0000 | [diff] [blame] | 1608 | # Run global pre-flight code, if defined via the config file. |
| 1609 | if lldb.pre_flight: |
| 1610 | lldb.pre_flight(self) |
| 1611 | |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 1612 | if lldb.remote_platform: |
| 1613 | #remote_test_dir = os.path.join(lldb.remote_platform_working_dir, self.mydir) |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 1614 | remote_test_dir = os.path.join(lldb.remote_platform_working_dir, |
| 1615 | self.getArchitecture(), |
| 1616 | str(self.test_number), |
| 1617 | self.mydir) |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 1618 | error = lldb.remote_platform.MakeDirectory(remote_test_dir, 0700) |
| 1619 | if error.Success(): |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 1620 | lldb.remote_platform.SetWorkingDirectory(remote_test_dir) |
| 1621 | else: |
| 1622 | print "error: making remote directory '%s': %s" % (remote_test_dir, error) |
| 1623 | |
Enrico Granata | 4481816 | 2012-10-24 01:23:57 +0000 | [diff] [blame] | 1624 | # utility methods that tests can use to access the current objects |
| 1625 | def target(self): |
| 1626 | if not self.dbg: |
| 1627 | raise Exception('Invalid debugger instance') |
| 1628 | return self.dbg.GetSelectedTarget() |
| 1629 | |
| 1630 | def process(self): |
| 1631 | if not self.dbg: |
| 1632 | raise Exception('Invalid debugger instance') |
| 1633 | return self.dbg.GetSelectedTarget().GetProcess() |
| 1634 | |
| 1635 | def thread(self): |
| 1636 | if not self.dbg: |
| 1637 | raise Exception('Invalid debugger instance') |
| 1638 | return self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread() |
| 1639 | |
| 1640 | def frame(self): |
| 1641 | if not self.dbg: |
| 1642 | raise Exception('Invalid debugger instance') |
| 1643 | return self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() |
| 1644 | |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 1645 | def get_process_working_directory(self): |
| 1646 | '''Get the working directory that should be used when launching processes for local or remote processes.''' |
| 1647 | if lldb.remote_platform: |
| 1648 | # Remote tests set the platform working directory up in TestBase.setUp() |
| 1649 | return lldb.remote_platform.GetWorkingDirectory() |
| 1650 | else: |
| 1651 | # local tests change directory into each test subdirectory |
| 1652 | return os.getcwd() |
| 1653 | |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1654 | def tearDown(self): |
Johnny Chen | 7d1d753 | 2010-09-02 21:23:12 +0000 | [diff] [blame] | 1655 | #import traceback |
| 1656 | #traceback.print_stack() |
| 1657 | |
Johnny Chen | fb4264c | 2011-08-01 19:50:58 +0000 | [diff] [blame] | 1658 | Base.tearDown(self) |
Johnny Chen | 707d822 | 2010-10-19 23:40:13 +0000 | [diff] [blame] | 1659 | |
Johnny Chen | 3794ad9 | 2011-06-15 21:24:24 +0000 | [diff] [blame] | 1660 | # Delete the target(s) from the debugger as a general cleanup step. |
| 1661 | # This includes terminating the process for each target, if any. |
| 1662 | # We'd like to reuse the debugger for our next test without incurring |
| 1663 | # the initialization overhead. |
| 1664 | targets = [] |
| 1665 | for target in self.dbg: |
| 1666 | if target: |
| 1667 | targets.append(target) |
| 1668 | process = target.GetProcess() |
| 1669 | if process: |
| 1670 | rc = self.invoke(process, "Kill") |
| 1671 | self.assertTrue(rc.Success(), PROCESS_KILLED) |
| 1672 | for target in targets: |
| 1673 | self.dbg.DeleteTarget(target) |
Johnny Chen | 6ca006c | 2010-08-16 21:28:10 +0000 | [diff] [blame] | 1674 | |
Johnny Chen | 44d2497 | 2012-04-16 18:55:15 +0000 | [diff] [blame] | 1675 | # Run global post-flight code, if defined via the config file. |
| 1676 | if lldb.post_flight: |
| 1677 | lldb.post_flight(self) |
| 1678 | |
Johnny Chen | bf6ffa3 | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 1679 | del self.dbg |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1680 | |
Johnny Chen | 86268e4 | 2011-09-30 21:48:35 +0000 | [diff] [blame] | 1681 | def switch_to_thread_with_stop_reason(self, stop_reason): |
| 1682 | """ |
| 1683 | Run the 'thread list' command, and select the thread with stop reason as |
| 1684 | 'stop_reason'. If no such thread exists, no select action is done. |
| 1685 | """ |
| 1686 | from lldbutil import stop_reason_to_str |
| 1687 | self.runCmd('thread list') |
| 1688 | output = self.res.GetOutput() |
| 1689 | thread_line_pattern = re.compile("^[ *] thread #([0-9]+):.*stop reason = %s" % |
| 1690 | stop_reason_to_str(stop_reason)) |
| 1691 | for line in output.splitlines(): |
| 1692 | matched = thread_line_pattern.match(line) |
| 1693 | if matched: |
| 1694 | self.runCmd('thread select %s' % matched.group(1)) |
| 1695 | |
Enrico Granata | 7594f14 | 2013-06-17 22:51:50 +0000 | [diff] [blame] | 1696 | def runCmd(self, cmd, msg=None, check=True, trace=False, inHistory=False): |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1697 | """ |
| 1698 | Ask the command interpreter to handle the command and then check its |
| 1699 | return status. |
| 1700 | """ |
| 1701 | # Fail fast if 'cmd' is not meaningful. |
| 1702 | if not cmd or len(cmd) == 0: |
| 1703 | raise Exception("Bad 'cmd' parameter encountered") |
Johnny Chen | 5bbb88f | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 1704 | |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 1705 | trace = (True if traceAlways else trace) |
Johnny Chen | d0190a6 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 1706 | |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1707 | # This is an opportunity to insert the 'platform target-install' command if we are told so |
| 1708 | # via the settig of lldb.lldbtest_remote_sandbox. |
| 1709 | if cmd.startswith("target create "): |
| 1710 | cmd = cmd.replace("target create ", "file ") |
| 1711 | if cmd.startswith("file ") and lldb.lldbtest_remote_sandbox: |
| 1712 | with recording(self, trace) as sbuf: |
| 1713 | the_rest = cmd.split("file ")[1] |
| 1714 | # Split the rest of the command line. |
| 1715 | atoms = the_rest.split() |
| 1716 | # |
| 1717 | # NOTE: This assumes that the options, if any, follow the file command, |
| 1718 | # instead of follow the specified target. |
| 1719 | # |
| 1720 | target = atoms[-1] |
| 1721 | # Now let's get the absolute pathname of our target. |
| 1722 | abs_target = os.path.abspath(target) |
| 1723 | print >> sbuf, "Found a file command, target (with absolute pathname)=%s" % abs_target |
| 1724 | fpath, fname = os.path.split(abs_target) |
| 1725 | parent_dir = os.path.split(fpath)[0] |
| 1726 | platform_target_install_command = 'platform target-install %s %s' % (fpath, lldb.lldbtest_remote_sandbox) |
| 1727 | print >> sbuf, "Insert this command to be run first: %s" % platform_target_install_command |
| 1728 | self.ci.HandleCommand(platform_target_install_command, self.res) |
| 1729 | # And this is the file command we want to execute, instead. |
| 1730 | # |
| 1731 | # Warning: SIDE EFFECT AHEAD!!! |
| 1732 | # Populate the remote executable pathname into the lldb namespace, |
| 1733 | # so that test cases can grab this thing out of the namespace. |
| 1734 | # |
| 1735 | lldb.lldbtest_remote_sandboxed_executable = abs_target.replace(parent_dir, lldb.lldbtest_remote_sandbox) |
| 1736 | cmd = "file -P %s %s %s" % (lldb.lldbtest_remote_sandboxed_executable, the_rest.replace(target, ''), abs_target) |
| 1737 | print >> sbuf, "And this is the replaced file command: %s" % cmd |
| 1738 | |
Johnny Chen | 63dfb27 | 2010-09-01 00:15:19 +0000 | [diff] [blame] | 1739 | running = (cmd.startswith("run") or cmd.startswith("process launch")) |
Johnny Chen | 5bbb88f | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 1740 | |
Johnny Chen | 63dfb27 | 2010-09-01 00:15:19 +0000 | [diff] [blame] | 1741 | for i in range(self.maxLaunchCount if running else 1): |
Enrico Granata | 7594f14 | 2013-06-17 22:51:50 +0000 | [diff] [blame] | 1742 | self.ci.HandleCommand(cmd, self.res, inHistory) |
Johnny Chen | 5bbb88f | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 1743 | |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1744 | with recording(self, trace) as sbuf: |
| 1745 | print >> sbuf, "runCmd:", cmd |
Johnny Chen | ab254f5 | 2010-10-15 16:13:00 +0000 | [diff] [blame] | 1746 | if not check: |
Johnny Chen | 27b107b | 2010-10-15 18:52:22 +0000 | [diff] [blame] | 1747 | print >> sbuf, "check of return status not required" |
Johnny Chen | f2b7023 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 1748 | if self.res.Succeeded(): |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1749 | print >> sbuf, "output:", self.res.GetOutput() |
Johnny Chen | f2b7023 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 1750 | else: |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1751 | print >> sbuf, "runCmd failed!" |
| 1752 | print >> sbuf, self.res.GetError() |
Johnny Chen | 5bbb88f | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 1753 | |
Johnny Chen | ff3d01d | 2010-08-20 21:03:09 +0000 | [diff] [blame] | 1754 | if self.res.Succeeded(): |
Johnny Chen | f2b7023 | 2010-08-25 18:49:48 +0000 | [diff] [blame] | 1755 | break |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1756 | elif running: |
Johnny Chen | cf7f74e | 2011-01-19 02:02:08 +0000 | [diff] [blame] | 1757 | # For process launch, wait some time before possible next try. |
| 1758 | time.sleep(self.timeWaitNextLaunch) |
Johnny Chen | 552d671 | 2012-08-01 19:56:04 +0000 | [diff] [blame] | 1759 | with recording(self, trace) as sbuf: |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1760 | print >> sbuf, "Command '" + cmd + "' failed!" |
Johnny Chen | 5bbb88f | 2010-08-20 17:57:32 +0000 | [diff] [blame] | 1761 | |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1762 | if check: |
| 1763 | self.assertTrue(self.res.Succeeded(), |
Johnny Chen | c0c67f2 | 2010-11-09 18:42:22 +0000 | [diff] [blame] | 1764 | msg if msg else CMD_MSG(cmd)) |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1765 | |
Jim Ingham | 63dfc72 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 1766 | def match (self, str, patterns, msg=None, trace=False, error=False, matching=True, exe=True): |
| 1767 | """run command in str, and match the result against regexp in patterns returning the match object for the first matching pattern |
| 1768 | |
| 1769 | Otherwise, all the arguments have the same meanings as for the expect function""" |
| 1770 | |
| 1771 | trace = (True if traceAlways else trace) |
| 1772 | |
| 1773 | if exe: |
| 1774 | # First run the command. If we are expecting error, set check=False. |
| 1775 | # Pass the assert message along since it provides more semantic info. |
| 1776 | self.runCmd(str, msg=msg, trace = (True if trace else False), check = not error) |
| 1777 | |
| 1778 | # Then compare the output against expected strings. |
| 1779 | output = self.res.GetError() if error else self.res.GetOutput() |
| 1780 | |
| 1781 | # If error is True, the API client expects the command to fail! |
| 1782 | if error: |
| 1783 | self.assertFalse(self.res.Succeeded(), |
| 1784 | "Command '" + str + "' is expected to fail!") |
| 1785 | else: |
| 1786 | # No execution required, just compare str against the golden input. |
| 1787 | output = str |
| 1788 | with recording(self, trace) as sbuf: |
| 1789 | print >> sbuf, "looking at:", output |
| 1790 | |
| 1791 | # The heading says either "Expecting" or "Not expecting". |
| 1792 | heading = "Expecting" if matching else "Not expecting" |
| 1793 | |
| 1794 | for pattern in patterns: |
| 1795 | # Match Objects always have a boolean value of True. |
| 1796 | match_object = re.search(pattern, output) |
| 1797 | matched = bool(match_object) |
| 1798 | with recording(self, trace) as sbuf: |
| 1799 | print >> sbuf, "%s pattern: %s" % (heading, pattern) |
| 1800 | print >> sbuf, "Matched" if matched else "Not matched" |
| 1801 | if matched: |
| 1802 | break |
| 1803 | |
| 1804 | self.assertTrue(matched if matching else not matched, |
| 1805 | msg if msg else EXP_MSG(str, exe)) |
| 1806 | |
| 1807 | return match_object |
| 1808 | |
Enrico Granata | 7594f14 | 2013-06-17 22:51:50 +0000 | [diff] [blame] | 1809 | def expect(self, str, msg=None, patterns=None, startstr=None, endstr=None, substrs=None, trace=False, error=False, matching=True, exe=True, inHistory=False): |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1810 | """ |
| 1811 | Similar to runCmd; with additional expect style output matching ability. |
| 1812 | |
| 1813 | Ask the command interpreter to handle the command and then check its |
| 1814 | return status. The 'msg' parameter specifies an informational assert |
| 1815 | message. We expect the output from running the command to start with |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1816 | 'startstr', matches the substrings contained in 'substrs', and regexp |
| 1817 | matches the patterns contained in 'patterns'. |
Johnny Chen | b330786 | 2010-09-17 22:28:51 +0000 | [diff] [blame] | 1818 | |
| 1819 | If the keyword argument error is set to True, it signifies that the API |
| 1820 | client is expecting the command to fail. In this case, the error stream |
Johnny Chen | aa90292 | 2010-09-17 22:45:27 +0000 | [diff] [blame] | 1821 | from running the command is retrieved and compared against the golden |
Johnny Chen | b330786 | 2010-09-17 22:28:51 +0000 | [diff] [blame] | 1822 | input, instead. |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1823 | |
| 1824 | If the keyword argument matching is set to False, it signifies that the API |
| 1825 | client is expecting the output of the command not to match the golden |
| 1826 | input. |
Johnny Chen | 9c48b8d | 2010-09-21 23:33:30 +0000 | [diff] [blame] | 1827 | |
| 1828 | Finally, the required argument 'str' represents the lldb command to be |
| 1829 | sent to the command interpreter. In case the keyword argument 'exe' is |
| 1830 | set to False, the 'str' is treated as a string to be matched/not-matched |
| 1831 | against the golden input. |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1832 | """ |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 1833 | trace = (True if traceAlways else trace) |
Johnny Chen | d0190a6 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 1834 | |
Johnny Chen | 9c48b8d | 2010-09-21 23:33:30 +0000 | [diff] [blame] | 1835 | if exe: |
| 1836 | # First run the command. If we are expecting error, set check=False. |
Johnny Chen | 62d4f86 | 2010-10-28 21:10:32 +0000 | [diff] [blame] | 1837 | # Pass the assert message along since it provides more semantic info. |
Enrico Granata | 7594f14 | 2013-06-17 22:51:50 +0000 | [diff] [blame] | 1838 | self.runCmd(str, msg=msg, trace = (True if trace else False), check = not error, inHistory=inHistory) |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1839 | |
Johnny Chen | 9c48b8d | 2010-09-21 23:33:30 +0000 | [diff] [blame] | 1840 | # Then compare the output against expected strings. |
| 1841 | output = self.res.GetError() if error else self.res.GetOutput() |
Johnny Chen | b330786 | 2010-09-17 22:28:51 +0000 | [diff] [blame] | 1842 | |
Johnny Chen | 9c48b8d | 2010-09-21 23:33:30 +0000 | [diff] [blame] | 1843 | # If error is True, the API client expects the command to fail! |
| 1844 | if error: |
| 1845 | self.assertFalse(self.res.Succeeded(), |
| 1846 | "Command '" + str + "' is expected to fail!") |
| 1847 | else: |
| 1848 | # No execution required, just compare str against the golden input. |
Enrico Granata | bc08ab4 | 2012-10-23 00:09:02 +0000 | [diff] [blame] | 1849 | if isinstance(str,lldb.SBCommandReturnObject): |
| 1850 | output = str.GetOutput() |
| 1851 | else: |
| 1852 | output = str |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1853 | with recording(self, trace) as sbuf: |
| 1854 | print >> sbuf, "looking at:", output |
Johnny Chen | b330786 | 2010-09-17 22:28:51 +0000 | [diff] [blame] | 1855 | |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1856 | # The heading says either "Expecting" or "Not expecting". |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1857 | heading = "Expecting" if matching else "Not expecting" |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1858 | |
| 1859 | # Start from the startstr, if specified. |
| 1860 | # If there's no startstr, set the initial state appropriately. |
| 1861 | matched = output.startswith(startstr) if startstr else (True if matching else False) |
Johnny Chen | b145bba | 2010-08-20 18:25:15 +0000 | [diff] [blame] | 1862 | |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1863 | if startstr: |
| 1864 | with recording(self, trace) as sbuf: |
| 1865 | print >> sbuf, "%s start string: %s" % (heading, startstr) |
| 1866 | print >> sbuf, "Matched" if matched else "Not matched" |
Johnny Chen | b145bba | 2010-08-20 18:25:15 +0000 | [diff] [blame] | 1867 | |
Johnny Chen | 86268e4 | 2011-09-30 21:48:35 +0000 | [diff] [blame] | 1868 | # Look for endstr, if specified. |
| 1869 | keepgoing = matched if matching else not matched |
| 1870 | if endstr: |
| 1871 | matched = output.endswith(endstr) |
| 1872 | with recording(self, trace) as sbuf: |
| 1873 | print >> sbuf, "%s end string: %s" % (heading, endstr) |
| 1874 | print >> sbuf, "Matched" if matched else "Not matched" |
| 1875 | |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1876 | # Look for sub strings, if specified. |
| 1877 | keepgoing = matched if matching else not matched |
| 1878 | if substrs and keepgoing: |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1879 | for str in substrs: |
Johnny Chen | b052f6c | 2010-09-23 23:35:28 +0000 | [diff] [blame] | 1880 | matched = output.find(str) != -1 |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1881 | with recording(self, trace) as sbuf: |
| 1882 | print >> sbuf, "%s sub string: %s" % (heading, str) |
| 1883 | print >> sbuf, "Matched" if matched else "Not matched" |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1884 | keepgoing = matched if matching else not matched |
| 1885 | if not keepgoing: |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1886 | break |
| 1887 | |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1888 | # Search for regular expression patterns, if specified. |
| 1889 | keepgoing = matched if matching else not matched |
| 1890 | if patterns and keepgoing: |
| 1891 | for pattern in patterns: |
| 1892 | # Match Objects always have a boolean value of True. |
| 1893 | matched = bool(re.search(pattern, output)) |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1894 | with recording(self, trace) as sbuf: |
| 1895 | print >> sbuf, "%s pattern: %s" % (heading, pattern) |
| 1896 | print >> sbuf, "Matched" if matched else "Not matched" |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1897 | keepgoing = matched if matching else not matched |
| 1898 | if not keepgoing: |
| 1899 | break |
Johnny Chen | ea88e94 | 2010-09-21 21:08:53 +0000 | [diff] [blame] | 1900 | |
| 1901 | self.assertTrue(matched if matching else not matched, |
Johnny Chen | c0c67f2 | 2010-11-09 18:42:22 +0000 | [diff] [blame] | 1902 | msg if msg else EXP_MSG(str, exe)) |
Johnny Chen | 27f212d | 2010-08-19 23:26:59 +0000 | [diff] [blame] | 1903 | |
Johnny Chen | f3c5923 | 2010-08-25 22:52:45 +0000 | [diff] [blame] | 1904 | def invoke(self, obj, name, trace=False): |
Johnny Chen | 61703c9 | 2010-08-25 22:56:10 +0000 | [diff] [blame] | 1905 | """Use reflection to call a method dynamically with no argument.""" |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 1906 | trace = (True if traceAlways else trace) |
Johnny Chen | f3c5923 | 2010-08-25 22:52:45 +0000 | [diff] [blame] | 1907 | |
| 1908 | method = getattr(obj, name) |
| 1909 | import inspect |
| 1910 | self.assertTrue(inspect.ismethod(method), |
| 1911 | name + "is a method name of object: " + str(obj)) |
| 1912 | result = method() |
Johnny Chen | 150c3cc | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1913 | with recording(self, trace) as sbuf: |
| 1914 | print >> sbuf, str(method) + ":", result |
Johnny Chen | f3c5923 | 2010-08-25 22:52:45 +0000 | [diff] [blame] | 1915 | return result |
Johnny Chen | 827edff | 2010-08-27 00:15:48 +0000 | [diff] [blame] | 1916 | |
Johnny Chen | f359cf2 | 2011-05-27 23:36:52 +0000 | [diff] [blame] | 1917 | # ================================================= |
| 1918 | # Misc. helper methods for debugging test execution |
| 1919 | # ================================================= |
| 1920 | |
Johnny Chen | 56b92a7 | 2011-07-11 19:15:11 +0000 | [diff] [blame] | 1921 | def DebugSBValue(self, val): |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 1922 | """Debug print a SBValue object, if traceAlways is True.""" |
Johnny Chen | de90f1d | 2011-04-27 17:43:07 +0000 | [diff] [blame] | 1923 | from lldbutil import value_type_to_str |
Johnny Chen | 87bb589 | 2010-11-03 21:37:58 +0000 | [diff] [blame] | 1924 | |
Johnny Chen | 8d55a34 | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 1925 | if not traceAlways: |
Johnny Chen | 827edff | 2010-08-27 00:15:48 +0000 | [diff] [blame] | 1926 | return |
| 1927 | |
| 1928 | err = sys.stderr |
| 1929 | err.write(val.GetName() + ":\n") |
Johnny Chen | 86268e4 | 2011-09-30 21:48:35 +0000 | [diff] [blame] | 1930 | err.write('\t' + "TypeName -> " + val.GetTypeName() + '\n') |
| 1931 | err.write('\t' + "ByteSize -> " + str(val.GetByteSize()) + '\n') |
| 1932 | err.write('\t' + "NumChildren -> " + str(val.GetNumChildren()) + '\n') |
| 1933 | err.write('\t' + "Value -> " + str(val.GetValue()) + '\n') |
| 1934 | err.write('\t' + "ValueAsUnsigned -> " + str(val.GetValueAsUnsigned())+ '\n') |
| 1935 | err.write('\t' + "ValueType -> " + value_type_to_str(val.GetValueType()) + '\n') |
| 1936 | err.write('\t' + "Summary -> " + str(val.GetSummary()) + '\n') |
| 1937 | err.write('\t' + "IsPointerType -> " + str(val.TypeIsPointerType()) + '\n') |
| 1938 | err.write('\t' + "Location -> " + val.GetLocation() + '\n') |
Johnny Chen | 827edff | 2010-08-27 00:15:48 +0000 | [diff] [blame] | 1939 | |
Johnny Chen | 36c5eb1 | 2011-08-05 20:17:27 +0000 | [diff] [blame] | 1940 | def DebugSBType(self, type): |
| 1941 | """Debug print a SBType object, if traceAlways is True.""" |
| 1942 | if not traceAlways: |
| 1943 | return |
| 1944 | |
| 1945 | err = sys.stderr |
| 1946 | err.write(type.GetName() + ":\n") |
| 1947 | err.write('\t' + "ByteSize -> " + str(type.GetByteSize()) + '\n') |
| 1948 | err.write('\t' + "IsPointerType -> " + str(type.IsPointerType()) + '\n') |
| 1949 | err.write('\t' + "IsReferenceType -> " + str(type.IsReferenceType()) + '\n') |
| 1950 | |
Johnny Chen | b877f1e | 2011-03-12 01:18:19 +0000 | [diff] [blame] | 1951 | def DebugPExpect(self, child): |
| 1952 | """Debug the spwaned pexpect object.""" |
| 1953 | if not traceAlways: |
| 1954 | return |
| 1955 | |
| 1956 | print child |
Filipe Cabecinhas | 0eec15a | 2012-06-20 10:13:40 +0000 | [diff] [blame] | 1957 | |
| 1958 | @classmethod |
| 1959 | def RemoveTempFile(cls, file): |
| 1960 | if os.path.exists(file): |
| 1961 | os.remove(file) |