Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | A simple testing framework for lldb using python's unit testing framework. |
| 5 | |
| 6 | Tests for lldb are written as python scripts which take advantage of the script |
| 7 | bridging provided by LLDB.framework to interact with lldb core. |
| 8 | |
| 9 | A specific naming pattern is followed by the .py script to be recognized as |
| 10 | a module which implements a test scenario, namely, Test*.py. |
| 11 | |
| 12 | To specify the directories where "Test*.py" python test scripts are located, |
| 13 | you need to pass in a list of directory names. By default, the current |
| 14 | working directory is searched if nothing is specified on the command line. |
Johnny Chen | 872aee1 | 2010-09-16 15:44:23 +0000 | [diff] [blame] | 15 | |
| 16 | Type: |
| 17 | |
| 18 | ./dotest.py -h |
| 19 | |
| 20 | for available options. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 21 | """ |
| 22 | |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 23 | import os, signal, sys, time |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 24 | import unittest2 |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 25 | |
Johnny Chen | 877c7e4 | 2010-08-07 00:16:07 +0000 | [diff] [blame] | 26 | class _WritelnDecorator(object): |
| 27 | """Used to decorate file-like objects with a handy 'writeln' method""" |
| 28 | def __init__(self,stream): |
| 29 | self.stream = stream |
| 30 | |
| 31 | def __getattr__(self, attr): |
| 32 | if attr in ('stream', '__getstate__'): |
| 33 | raise AttributeError(attr) |
| 34 | return getattr(self.stream,attr) |
| 35 | |
| 36 | def writeln(self, arg=None): |
| 37 | if arg: |
| 38 | self.write(arg) |
| 39 | self.write('\n') # text-mode streams translate to \r\n if needed |
| 40 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 41 | # |
| 42 | # Global variables: |
| 43 | # |
| 44 | |
| 45 | # The test suite. |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 46 | suite = unittest2.TestSuite() |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 47 | |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 48 | # The config file is optional. |
| 49 | configFile = None |
| 50 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 51 | # The dictionary as a result of sourcing configFile. |
| 52 | config = {} |
| 53 | |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 54 | # Delay startup in order for the debugger to attach. |
| 55 | delay = False |
| 56 | |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 57 | # The filter (testcase.testmethod) used to admit tests into our test suite. |
| 58 | filterspec = None |
| 59 | |
| 60 | # If '-g' is specified, the filterspec must be consulted for each test module, default to False. |
| 61 | fs4all = False |
| 62 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 63 | # Ignore the build search path relative to this script to locate the lldb.py module. |
| 64 | ignore = False |
| 65 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 66 | # By default, we skip long running test case. Use '-l' option to override. |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 67 | skipLongRunningTest = True |
| 68 | |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 69 | # The regular expression pattern to match against eligible filenames as our test cases. |
| 70 | regexp = None |
| 71 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 72 | # By default, tests are executed in place and cleanups are performed afterwards. |
| 73 | # Use '-r dir' option to relocate the tests and their intermediate files to a |
| 74 | # different directory and to forgo any cleanups. The directory specified must |
| 75 | # not exist yet. |
| 76 | rdir = None |
| 77 | |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 78 | # By default, recorded session info for errored/failed test are dumped into its |
| 79 | # own file under a session directory named after the timestamp of the test suite |
| 80 | # run. Use '-s session-dir-name' to specify a specific dir name. |
| 81 | sdir_name = None |
| 82 | |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 83 | # Set this flag if there is any session info dumped during the test run. |
| 84 | sdir_has_content = False |
| 85 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 86 | # Default verbosity is 0. |
| 87 | verbose = 0 |
| 88 | |
| 89 | # By default, search from the current working directory. |
| 90 | testdirs = [ os.getcwd() ] |
| 91 | |
Johnny Chen | 877c7e4 | 2010-08-07 00:16:07 +0000 | [diff] [blame] | 92 | # Separator string. |
| 93 | separator = '-' * 70 |
| 94 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 95 | |
| 96 | def usage(): |
| 97 | print """ |
| 98 | Usage: dotest.py [option] [args] |
| 99 | where options: |
| 100 | -h : print this help message and exit (also --help) |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 101 | -c : read a config file specified after this option |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 102 | (see also lldb-trunk/example/test/usage-config) |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 103 | -d : delay startup for 10 seconds (in order for the debugger to attach) |
Johnny Chen | 46be75d | 2010-10-11 16:19:48 +0000 | [diff] [blame] | 104 | -f : specify a filter, which consists of the test class name, a dot, followed by |
| 105 | the test method, to admit tests into the test suite |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 106 | e.g., -f 'ClassTypesTestCase.test_with_dwarf_and_python_api' |
| 107 | -g : if specified, only the modules with the corect filter will be run |
| 108 | it has no effect if no '-f' option is present |
| 109 | '-f filterspec -g' can be used with '-p filename-regexp' to select only |
| 110 | the testfile.testclass.testmethod to run |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 111 | -i : ignore (don't bailout) if 'lldb.py' module cannot be located in the build |
| 112 | tree relative to this script; use PYTHONPATH to locate the module |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 113 | -l : don't skip long running test |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 114 | -p : specify a regexp filename pattern for inclusion in the test suite |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 115 | -r : specify a dir to relocate the tests and their intermediate files to; |
| 116 | the directory must not exist before running this test driver; |
| 117 | no cleanup of intermediate test files is performed in this case |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 118 | -s : specify the name of the dir created to store the session files of tests |
| 119 | with errored or failed status; if not specified, the test driver uses the |
| 120 | timestamp as the session dir name |
Johnny Chen | d0c24b2 | 2010-08-23 17:10:44 +0000 | [diff] [blame] | 121 | -t : trace lldb command execution and result |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 122 | -v : do verbose mode of unittest framework |
Johnny Chen | e47649c | 2010-10-07 02:04:14 +0000 | [diff] [blame] | 123 | -w : insert some wait time (currently 0.5 sec) between consecutive test cases |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 124 | |
| 125 | and: |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 126 | args : specify a list of directory names to search for test modules named after |
| 127 | Test*.py (test discovery) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 128 | if empty, search from the curret working directory, instead |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 129 | |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 130 | Examples: |
| 131 | |
Johnny Chen | 6ad7e5e | 2010-10-21 00:47:52 +0000 | [diff] [blame] | 132 | This is an example of using the -f -g options to pinpoint to a specfic test |
| 133 | method to be run: |
| 134 | |
| 135 | $ ./dotest.py -f ClassTypesTestCase.test_with_dsym_and_run_command -g |
| 136 | ---------------------------------------------------------------------- |
| 137 | Collected 1 test |
| 138 | |
| 139 | test_with_dsym_and_run_command (TestClassTypes.ClassTypesTestCase) |
| 140 | Test 'frame variable this' when stopped on a class constructor. ... ok |
| 141 | |
| 142 | ---------------------------------------------------------------------- |
| 143 | Ran 1 test in 1.396s |
| 144 | |
| 145 | OK |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 146 | |
| 147 | And this is an example of using the -p option to run a single file (the filename |
| 148 | matches the pattern 'ObjC' and it happens to be 'TestObjCMethods.py'): |
| 149 | |
| 150 | $ ./dotest.py -v -p ObjC |
| 151 | ---------------------------------------------------------------------- |
| 152 | Collected 4 tests |
| 153 | |
| 154 | test_break_with_dsym (TestObjCMethods.FoundationTestCase) |
| 155 | Test setting objc breakpoints using 'regexp-break' and 'breakpoint set'. ... ok |
| 156 | test_break_with_dwarf (TestObjCMethods.FoundationTestCase) |
| 157 | Test setting objc breakpoints using 'regexp-break' and 'breakpoint set'. ... ok |
| 158 | test_data_type_and_expr_with_dsym (TestObjCMethods.FoundationTestCase) |
| 159 | Lookup objective-c data types and evaluate expressions. ... ok |
| 160 | test_data_type_and_expr_with_dwarf (TestObjCMethods.FoundationTestCase) |
| 161 | Lookup objective-c data types and evaluate expressions. ... ok |
| 162 | |
| 163 | ---------------------------------------------------------------------- |
| 164 | Ran 4 tests in 16.661s |
| 165 | |
| 166 | OK |
Johnny Chen | 6ad7e5e | 2010-10-21 00:47:52 +0000 | [diff] [blame] | 167 | |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 168 | Running of this script also sets up the LLDB_TEST environment variable so that |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 169 | individual test cases can locate their supporting files correctly. The script |
| 170 | tries to set up Python's search paths for modules by looking at the build tree |
| 171 | relative to this script. See also the '-i' option. |
Johnny Chen | fde69bc | 2010-09-14 22:01:40 +0000 | [diff] [blame] | 172 | |
| 173 | Environment variables related to loggings: |
| 174 | |
| 175 | o LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem |
| 176 | with a default option of 'event process' if LLDB_LOG_OPTION is not defined. |
| 177 | |
| 178 | o GDB_REMOTE_LOG: if defined, specifies the log file pathname for the |
| 179 | 'process.gdb-remote' subsystem with a default option of 'packets' if |
| 180 | GDB_REMOTE_LOG_OPTION is not defined. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 181 | """ |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 182 | sys.exit(0) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 183 | |
| 184 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 185 | def parseOptionsAndInitTestdirs(): |
| 186 | """Initialize the list of directories containing our unittest scripts. |
| 187 | |
| 188 | '-h/--help as the first option prints out usage info and exit the program. |
| 189 | """ |
| 190 | |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 191 | global configFile |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 192 | global delay |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 193 | global filterspec |
| 194 | global fs4all |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 195 | global ignore |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 196 | global skipLongRunningTest |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 197 | global regexp |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 198 | global rdir |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 199 | global sdir_name |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 200 | global verbose |
| 201 | global testdirs |
| 202 | |
| 203 | if len(sys.argv) == 1: |
| 204 | return |
| 205 | |
| 206 | # Process possible trace and/or verbose flag, among other things. |
| 207 | index = 1 |
Johnny Chen | ce2212c | 2010-10-07 15:41:55 +0000 | [diff] [blame] | 208 | while index < len(sys.argv): |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 209 | if not sys.argv[index].startswith('-'): |
| 210 | # End of option processing. |
| 211 | break |
| 212 | |
| 213 | if sys.argv[index].find('-h') != -1: |
| 214 | usage() |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 215 | elif sys.argv[index].startswith('-c'): |
| 216 | # Increment by 1 to fetch the config file name option argument. |
| 217 | index += 1 |
| 218 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 219 | usage() |
| 220 | configFile = sys.argv[index] |
| 221 | if not os.path.isfile(configFile): |
| 222 | print "Config file:", configFile, "does not exist!" |
| 223 | usage() |
| 224 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 225 | elif sys.argv[index].startswith('-d'): |
| 226 | delay = True |
| 227 | index += 1 |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 228 | elif sys.argv[index].startswith('-f'): |
| 229 | # Increment by 1 to fetch the filter spec. |
| 230 | index += 1 |
| 231 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 232 | usage() |
| 233 | filterspec = sys.argv[index] |
| 234 | index += 1 |
| 235 | elif sys.argv[index].startswith('-g'): |
| 236 | fs4all = True |
| 237 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 238 | elif sys.argv[index].startswith('-i'): |
| 239 | ignore = True |
| 240 | index += 1 |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 241 | elif sys.argv[index].startswith('-l'): |
| 242 | skipLongRunningTest = False |
| 243 | index += 1 |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 244 | elif sys.argv[index].startswith('-p'): |
| 245 | # Increment by 1 to fetch the reg exp pattern argument. |
| 246 | index += 1 |
| 247 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 248 | usage() |
| 249 | regexp = sys.argv[index] |
| 250 | index += 1 |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 251 | elif sys.argv[index].startswith('-r'): |
| 252 | # Increment by 1 to fetch the relocated directory argument. |
| 253 | index += 1 |
| 254 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 255 | usage() |
| 256 | rdir = os.path.abspath(sys.argv[index]) |
| 257 | if os.path.exists(rdir): |
| 258 | print "Relocated directory:", rdir, "must not exist!" |
| 259 | usage() |
| 260 | index += 1 |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 261 | elif sys.argv[index].startswith('-s'): |
| 262 | # Increment by 1 to fetch the session dir name. |
| 263 | index += 1 |
| 264 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 265 | usage() |
| 266 | sdir_name = sys.argv[index] |
| 267 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 268 | elif sys.argv[index].startswith('-t'): |
| 269 | os.environ["LLDB_COMMAND_TRACE"] = "YES" |
| 270 | index += 1 |
| 271 | elif sys.argv[index].startswith('-v'): |
| 272 | verbose = 2 |
| 273 | index += 1 |
Johnny Chen | e47649c | 2010-10-07 02:04:14 +0000 | [diff] [blame] | 274 | elif sys.argv[index].startswith('-w'): |
| 275 | os.environ["LLDB_WAIT_BETWEEN_TEST_CASES"] = 'YES' |
| 276 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 277 | else: |
| 278 | print "Unknown option: ", sys.argv[index] |
| 279 | usage() |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 280 | |
| 281 | # Gather all the dirs passed on the command line. |
| 282 | if len(sys.argv) > index: |
| 283 | testdirs = map(os.path.abspath, sys.argv[index:]) |
| 284 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 285 | # If '-r dir' is specified, the tests should be run under the relocated |
| 286 | # directory. Let's copy the testdirs over. |
| 287 | if rdir: |
| 288 | from shutil import copytree, ignore_patterns |
| 289 | |
| 290 | tmpdirs = [] |
| 291 | for srcdir in testdirs: |
| 292 | dstdir = os.path.join(rdir, os.path.basename(srcdir)) |
| 293 | # Don't copy the *.pyc and .svn stuffs. |
| 294 | copytree(srcdir, dstdir, ignore=ignore_patterns('*.pyc', '.svn')) |
| 295 | tmpdirs.append(dstdir) |
| 296 | |
| 297 | # This will be our modified testdirs. |
| 298 | testdirs = tmpdirs |
| 299 | |
| 300 | # With '-r dir' specified, there's no cleanup of intermediate test files. |
| 301 | os.environ["LLDB_DO_CLEANUP"] = 'NO' |
| 302 | |
| 303 | # If testdirs is ['test'], the make directory has already been copied |
| 304 | # recursively and is contained within the rdir/test dir. For anything |
| 305 | # else, we would need to copy over the make directory and its contents, |
| 306 | # so that, os.listdir(rdir) looks like, for example: |
| 307 | # |
| 308 | # array_types conditional_break make |
| 309 | # |
| 310 | # where the make directory contains the Makefile.rules file. |
| 311 | if len(testdirs) != 1 or os.path.basename(testdirs[0]) != 'test': |
| 312 | # Don't copy the .svn stuffs. |
| 313 | copytree('make', os.path.join(rdir, 'make'), |
| 314 | ignore=ignore_patterns('.svn')) |
| 315 | |
| 316 | #print "testdirs:", testdirs |
| 317 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 318 | # Source the configFile if specified. |
| 319 | # The side effect, if any, will be felt from this point on. An example |
| 320 | # config file may be these simple two lines: |
| 321 | # |
| 322 | # sys.stderr = open("/tmp/lldbtest-stderr", "w") |
| 323 | # sys.stdout = open("/tmp/lldbtest-stdout", "w") |
| 324 | # |
| 325 | # which will reassign the two file objects to sys.stderr and sys.stdout, |
| 326 | # respectively. |
| 327 | # |
| 328 | # See also lldb-trunk/example/test/usage-config. |
| 329 | global config |
| 330 | if configFile: |
| 331 | # Pass config (a dictionary) as the locals namespace for side-effect. |
| 332 | execfile(configFile, globals(), config) |
| 333 | #print "config:", config |
| 334 | #print "sys.stderr:", sys.stderr |
| 335 | #print "sys.stdout:", sys.stdout |
| 336 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 337 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 338 | def setupSysPath(): |
| 339 | """Add LLDB.framework/Resources/Python to the search paths for modules.""" |
| 340 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 341 | global rdir |
| 342 | global testdirs |
| 343 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 344 | # Get the directory containing the current script. |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 345 | scriptPath = sys.path[0] |
| 346 | if not scriptPath.endswith('test'): |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 347 | print "This script expects to reside in lldb's test directory." |
| 348 | sys.exit(-1) |
| 349 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 350 | if rdir: |
| 351 | # Set up the LLDB_TEST environment variable appropriately, so that the |
| 352 | # individual tests can be located relatively. |
| 353 | # |
| 354 | # See also lldbtest.TestBase.setUpClass(cls). |
| 355 | if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test': |
| 356 | os.environ["LLDB_TEST"] = os.path.join(rdir, 'test') |
| 357 | else: |
| 358 | os.environ["LLDB_TEST"] = rdir |
| 359 | else: |
| 360 | os.environ["LLDB_TEST"] = scriptPath |
Johnny Chen | 9de4ede | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 361 | pluginPath = os.path.join(scriptPath, 'plugins') |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 362 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 363 | # Append script dir and plugin dir to the sys.path. |
| 364 | sys.path.append(scriptPath) |
| 365 | sys.path.append(pluginPath) |
| 366 | |
| 367 | global ignore |
| 368 | |
| 369 | # The '-i' option is used to skip looking for lldb.py in the build tree. |
| 370 | if ignore: |
| 371 | return |
| 372 | |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 373 | base = os.path.abspath(os.path.join(scriptPath, os.pardir)) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 374 | dbgPath = os.path.join(base, 'build', 'Debug', 'LLDB.framework', |
| 375 | 'Resources', 'Python') |
| 376 | relPath = os.path.join(base, 'build', 'Release', 'LLDB.framework', |
| 377 | 'Resources', 'Python') |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 378 | baiPath = os.path.join(base, 'build', 'BuildAndIntegration', |
| 379 | 'LLDB.framework', 'Resources', 'Python') |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 380 | |
| 381 | lldbPath = None |
| 382 | if os.path.isfile(os.path.join(dbgPath, 'lldb.py')): |
| 383 | lldbPath = dbgPath |
| 384 | elif os.path.isfile(os.path.join(relPath, 'lldb.py')): |
| 385 | lldbPath = relPath |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 386 | elif os.path.isfile(os.path.join(baiPath, 'lldb.py')): |
| 387 | lldbPath = baiPath |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 388 | |
| 389 | if not lldbPath: |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 390 | print 'This script requires lldb.py to be in either ' + dbgPath + ',', |
| 391 | print relPath + ', or ' + baiPath |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 392 | sys.exit(-1) |
| 393 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 394 | # This is to locate the lldb.py module. Insert it right after sys.path[0]. |
| 395 | sys.path[1:1] = [lldbPath] |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 396 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 397 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 398 | def doDelay(delta): |
| 399 | """Delaying startup for delta-seconds to facilitate debugger attachment.""" |
| 400 | def alarm_handler(*args): |
| 401 | raise Exception("timeout") |
| 402 | |
| 403 | signal.signal(signal.SIGALRM, alarm_handler) |
| 404 | signal.alarm(delta) |
| 405 | sys.stdout.write("pid=%d\n" % os.getpid()) |
| 406 | sys.stdout.write("Enter RET to proceed (or timeout after %d seconds):" % |
| 407 | delta) |
| 408 | sys.stdout.flush() |
| 409 | try: |
| 410 | text = sys.stdin.readline() |
| 411 | except: |
| 412 | text = "" |
| 413 | signal.alarm(0) |
| 414 | sys.stdout.write("proceeding...\n") |
| 415 | pass |
| 416 | |
| 417 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 418 | def visit(prefix, dir, names): |
| 419 | """Visitor function for os.path.walk(path, visit, arg).""" |
| 420 | |
| 421 | global suite |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 422 | global regexp |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 423 | global filterspec |
| 424 | global fs4all |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 425 | |
| 426 | for name in names: |
| 427 | if os.path.isdir(os.path.join(dir, name)): |
| 428 | continue |
| 429 | |
| 430 | if '.py' == os.path.splitext(name)[1] and name.startswith(prefix): |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 431 | # Try to match the regexp pattern, if specified. |
| 432 | if regexp: |
| 433 | import re |
| 434 | if re.search(regexp, name): |
| 435 | #print "Filename: '%s' matches pattern: '%s'" % (name, regexp) |
| 436 | pass |
| 437 | else: |
| 438 | #print "Filename: '%s' does not match pattern: '%s'" % (name, regexp) |
| 439 | continue |
| 440 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 441 | # We found a match for our test. Add it to the suite. |
Johnny Chen | 7972335 | 2010-10-12 15:53:22 +0000 | [diff] [blame] | 442 | |
| 443 | # Update the sys.path first. |
Johnny Chen | a85d7ee | 2010-06-26 00:19:32 +0000 | [diff] [blame] | 444 | if not sys.path.count(dir): |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 445 | sys.path.insert(0, dir) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 446 | base = os.path.splitext(name)[0] |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 447 | |
| 448 | # Thoroughly check the filterspec against the base module and admit |
| 449 | # the (base, filterspec) combination only when it makes sense. |
| 450 | if filterspec: |
| 451 | # Optimistically set the flag to True. |
| 452 | filtered = True |
| 453 | module = __import__(base) |
| 454 | parts = filterspec.split('.') |
| 455 | obj = module |
| 456 | for part in parts: |
| 457 | try: |
| 458 | parent, obj = obj, getattr(obj, part) |
| 459 | except AttributeError: |
| 460 | # The filterspec has failed. |
| 461 | filtered = False |
| 462 | break |
| 463 | # Forgo this module if the (base, filterspec) combo is invalid |
| 464 | # and the '-g' option is present. |
| 465 | if fs4all and not filtered: |
| 466 | continue |
| 467 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 468 | # Add either the filtered test case or the entire test class. |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 469 | if filterspec and filtered: |
| 470 | suite.addTests( |
| 471 | unittest2.defaultTestLoader.loadTestsFromName(filterspec, module)) |
| 472 | else: |
| 473 | # A simple case of just the module name. Also the failover case |
| 474 | # from the filterspec branch when the (base, filterspec) combo |
| 475 | # doesn't make sense. |
| 476 | suite.addTests(unittest2.defaultTestLoader.loadTestsFromName(base)) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 477 | |
| 478 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 479 | def lldbLoggings(): |
| 480 | """Check and do lldb loggings if necessary.""" |
| 481 | |
| 482 | # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is |
| 483 | # defined. Use ${LLDB_LOG} to specify the log file. |
| 484 | ci = lldb.DBG.GetCommandInterpreter() |
| 485 | res = lldb.SBCommandReturnObject() |
| 486 | if ("LLDB_LOG" in os.environ): |
| 487 | if ("LLDB_LOG_OPTION" in os.environ): |
| 488 | lldb_log_option = os.environ["LLDB_LOG_OPTION"] |
| 489 | else: |
| 490 | lldb_log_option = "event process" |
| 491 | ci.HandleCommand( |
| 492 | "log enable -f " + os.environ["LLDB_LOG"] + " lldb " + lldb_log_option, |
| 493 | res) |
| 494 | if not res.Succeeded(): |
| 495 | raise Exception('log enable failed (check LLDB_LOG env variable.') |
| 496 | # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined. |
| 497 | # Use ${GDB_REMOTE_LOG} to specify the log file. |
| 498 | if ("GDB_REMOTE_LOG" in os.environ): |
| 499 | if ("GDB_REMOTE_LOG_OPTION" in os.environ): |
| 500 | gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"] |
| 501 | else: |
| 502 | gdb_remote_log_option = "packets" |
| 503 | ci.HandleCommand( |
| 504 | "log enable -f " + os.environ["GDB_REMOTE_LOG"] + " process.gdb-remote " |
| 505 | + gdb_remote_log_option, |
| 506 | res) |
| 507 | if not res.Succeeded(): |
| 508 | raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.') |
| 509 | |
| 510 | |
| 511 | ############################################ |
| 512 | # # |
| 513 | # Execution of the test driver starts here # |
| 514 | # # |
| 515 | ############################################ |
| 516 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 517 | # |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 518 | # Start the actions by first parsing the options while setting up the test |
| 519 | # directories, followed by setting up the search paths for lldb utilities; |
| 520 | # then, we walk the directory trees and collect the tests into our test suite. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 521 | # |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 522 | parseOptionsAndInitTestdirs() |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 523 | setupSysPath() |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 524 | |
| 525 | # |
| 526 | # If '-d' is specified, do a delay of 10 seconds for the debugger to attach. |
| 527 | # |
| 528 | if delay: |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 529 | doDelay(10) |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 530 | |
Johnny Chen | 49f2f7a | 2010-09-20 17:25:45 +0000 | [diff] [blame] | 531 | # |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 532 | # If '-l' is specified, do not skip the long running tests. |
| 533 | if not skipLongRunningTest: |
| 534 | os.environ["LLDB_SKIP_LONG_RUNNING_TEST"] = "NO" |
| 535 | |
| 536 | # |
Johnny Chen | 7972335 | 2010-10-12 15:53:22 +0000 | [diff] [blame] | 537 | # Walk through the testdirs while collecting tests. |
Johnny Chen | 49f2f7a | 2010-09-20 17:25:45 +0000 | [diff] [blame] | 538 | # |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 539 | for testdir in testdirs: |
| 540 | os.path.walk(testdir, visit, 'Test') |
| 541 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 542 | # |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 543 | # Now that we have loaded all the test cases, run the whole test suite. |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 544 | # |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 545 | |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 546 | # For the time being, let's bracket the test runner within the |
| 547 | # lldb.SBDebugger.Initialize()/Terminate() pair. |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 548 | import lldb, atexit |
Johnny Chen | 6b6f5ba | 2010-10-14 16:36:49 +0000 | [diff] [blame] | 549 | # Update: the act of importing lldb now executes lldb.SBDebugger.Initialize(), |
| 550 | # there's no need to call it a second time. |
| 551 | #lldb.SBDebugger.Initialize() |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 552 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 553 | |
Johnny Chen | 909e5a6 | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 554 | # Create a singleton SBDebugger in the lldb namespace. |
| 555 | lldb.DBG = lldb.SBDebugger.Create() |
| 556 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 557 | # Turn on lldb loggings if necessary. |
| 558 | lldbLoggings() |
Johnny Chen | 909e5a6 | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 559 | |
Johnny Chen | 7987ac9 | 2010-08-09 20:40:52 +0000 | [diff] [blame] | 560 | # Install the control-c handler. |
| 561 | unittest2.signals.installHandler() |
| 562 | |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 563 | # If sdir_name is not specified through the '-s sdir_name' option, get a |
| 564 | # timestamp string and export it as LLDB_SESSION_DIR environment var. This will |
| 565 | # be used when/if we want to dump the session info of individual test cases |
| 566 | # later on. |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 567 | # |
| 568 | # See also TestBase.dumpSessionInfo() in lldbtest.py. |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 569 | if not sdir_name: |
| 570 | import datetime |
Johnny Chen | 41fae81 | 2010-10-29 22:26:38 +0000 | [diff] [blame] | 571 | # The windows platforms don't like ':' in the pathname. |
Johnny Chen | 76bd010 | 2010-10-28 16:32:13 +0000 | [diff] [blame] | 572 | timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 573 | sdir_name = timestamp |
| 574 | os.environ["LLDB_SESSION_DIRNAME"] = sdir_name |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 575 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 576 | # |
| 577 | # Invoke the default TextTestRunner to run the test suite, possibly iterating |
| 578 | # over different configurations. |
| 579 | # |
| 580 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 581 | iterArchs = False |
Johnny Chen | f032d90 | 2010-09-21 00:16:09 +0000 | [diff] [blame] | 582 | iterCompilers = False |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 583 | |
| 584 | from types import * |
| 585 | if "archs" in config: |
| 586 | archs = config["archs"] |
| 587 | if type(archs) is ListType and len(archs) >= 1: |
| 588 | iterArchs = True |
| 589 | if "compilers" in config: |
| 590 | compilers = config["compilers"] |
| 591 | if type(compilers) is ListType and len(compilers) >= 1: |
| 592 | iterCompilers = True |
| 593 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 594 | # Make a shallow copy of sys.path, we need to manipulate the search paths later. |
| 595 | # This is only necessary if we are relocated and with different configurations. |
| 596 | if rdir and (iterArchs or iterCompilers): |
| 597 | old_sys_path = sys.path[:] |
| 598 | old_stderr = sys.stderr |
| 599 | old_stdout = sys.stdout |
| 600 | new_stderr = None |
| 601 | new_stdout = None |
| 602 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 603 | for ia in range(len(archs) if iterArchs else 1): |
| 604 | archConfig = "" |
| 605 | if iterArchs: |
Johnny Chen | 18a921f | 2010-09-30 17:11:58 +0000 | [diff] [blame] | 606 | os.environ["ARCH"] = archs[ia] |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 607 | archConfig = "arch=%s" % archs[ia] |
| 608 | for ic in range(len(compilers) if iterCompilers else 1): |
| 609 | if iterCompilers: |
Johnny Chen | 18a921f | 2010-09-30 17:11:58 +0000 | [diff] [blame] | 610 | os.environ["CC"] = compilers[ic] |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 611 | configString = "%s compiler=%s" % (archConfig, compilers[ic]) |
| 612 | else: |
| 613 | configString = archConfig |
| 614 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 615 | if iterArchs or iterCompilers: |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 616 | # If we specified a relocated directory to run the test suite, do |
| 617 | # the extra housekeeping to copy the testdirs to a configStringified |
| 618 | # directory and to update sys.path before invoking the test runner. |
| 619 | # The purpose is to separate the configuration-specific directories |
| 620 | # from each other. |
| 621 | if rdir: |
| 622 | from string import maketrans |
| 623 | from shutil import copytree, ignore_patterns |
| 624 | |
| 625 | # Translate ' ' to '-' for dir name. |
| 626 | tbl = maketrans(' ', '-') |
| 627 | configPostfix = configString.translate(tbl) |
| 628 | newrdir = "%s.%s" % (rdir, configPostfix) |
| 629 | |
| 630 | # Copy the tree to a new directory with postfix name configPostfix. |
| 631 | copytree(rdir, newrdir, ignore=ignore_patterns('*.pyc', '*.o', '*.d')) |
| 632 | |
| 633 | # Check whether we need to split stderr/stdout into configuration |
| 634 | # specific files. |
| 635 | if old_stderr.name != '<stderr>' and config.get('split_stderr'): |
| 636 | if new_stderr: |
| 637 | new_stderr.close() |
| 638 | new_stderr = open("%s.%s" % (old_stderr.name, configPostfix), "w") |
| 639 | sys.stderr = new_stderr |
Johnny Chen | 4b6630e | 2010-10-12 21:50:36 +0000 | [diff] [blame] | 640 | if old_stdout.name != '<stdout>' and config.get('split_stdout'): |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 641 | if new_stdout: |
| 642 | new_stdout.close() |
| 643 | new_stdout = open("%s.%s" % (old_stdout.name, configPostfix), "w") |
| 644 | sys.stdout = new_stdout |
| 645 | |
| 646 | # Update the LLDB_TEST environment variable to reflect new top |
| 647 | # level test directory. |
| 648 | # |
| 649 | # See also lldbtest.TestBase.setUpClass(cls). |
| 650 | if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test': |
| 651 | os.environ["LLDB_TEST"] = os.path.join(newrdir, 'test') |
| 652 | else: |
| 653 | os.environ["LLDB_TEST"] = newrdir |
| 654 | |
| 655 | # And update the Python search paths for modules. |
| 656 | sys.path = [x.replace(rdir, newrdir, 1) for x in old_sys_path] |
| 657 | |
| 658 | # Output the configuration. |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 659 | sys.stderr.write("\nConfiguration: " + configString + "\n") |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 660 | |
| 661 | #print "sys.stderr name is", sys.stderr.name |
| 662 | #print "sys.stdout name is", sys.stdout.name |
| 663 | |
| 664 | # First, write out the number of collected test cases. |
| 665 | sys.stderr.write(separator + "\n") |
| 666 | sys.stderr.write("Collected %d test%s\n\n" |
| 667 | % (suite.countTestCases(), |
| 668 | suite.countTestCases() != 1 and "s" or "")) |
| 669 | |
| 670 | # Invoke the test runner. |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 671 | class LLDBTestResult(unittest2.TextTestResult): |
| 672 | """ |
| 673 | Enforce a singleton pattern to allow inspection of test progress. |
| 674 | """ |
| 675 | __singleton__ = None |
| 676 | |
| 677 | def __init__(self, *args): |
| 678 | if LLDBTestResult.__singleton__: |
| 679 | raise "LLDBTestResult instantiated more than once" |
| 680 | super(LLDBTestResult, self).__init__(*args) |
| 681 | LLDBTestResult.__singleton__ = self |
| 682 | # Now put this singleton into the lldb module namespace. |
| 683 | lldb.test_result = self |
| 684 | |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 685 | def addError(self, test, err): |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 686 | global sdir_has_content |
| 687 | sdir_has_content = True |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 688 | super(LLDBTestResult, self).addError(test, err) |
| 689 | method = getattr(test, "markError", None) |
| 690 | if method: |
| 691 | method() |
| 692 | |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 693 | def addFailure(self, test, err): |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 694 | global sdir_has_content |
| 695 | sdir_has_content = True |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 696 | super(LLDBTestResult, self).addFailure(test, err) |
| 697 | method = getattr(test, "markFailure", None) |
| 698 | if method: |
| 699 | method() |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 700 | |
Johnny Chen | dd2bb2c | 2010-11-03 18:17:03 +0000 | [diff] [blame^] | 701 | def addExpectedFailure(self, test, err): |
| 702 | global sdir_has_content |
| 703 | sdir_has_content = True |
| 704 | super(LLDBTestResult, self).addExpectedFailure(test, err) |
| 705 | method = getattr(test, "markExpectedFailure", None) |
| 706 | if method: |
| 707 | method() |
| 708 | |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 709 | result = unittest2.TextTestRunner(stream=sys.stderr, verbosity=verbose, |
| 710 | resultclass=LLDBTestResult).run(suite) |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 711 | |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 712 | |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 713 | if sdir_has_content: |
| 714 | sys.stderr.write("\nSession logs for test failures/errors can be found in directory '%s'\n" % sdir_name) |
| 715 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 716 | # Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined. |
| 717 | # This should not be necessary now. |
Johnny Chen | 83f6e51 | 2010-08-13 22:58:44 +0000 | [diff] [blame] | 718 | if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ): |
| 719 | import subprocess |
| 720 | print "Terminating Test suite..." |
| 721 | subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())]) |
| 722 | |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 723 | # Exiting. |
| 724 | sys.exit(not result.wasSuccessful) |