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 | 2891bb0 | 2011-09-16 01:04:26 +0000 | [diff] [blame] | 24 | import subprocess |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 25 | import unittest2 |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 26 | |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 27 | def is_exe(fpath): |
Johnny Chen | f2c7b28 | 2011-04-26 23:10:51 +0000 | [diff] [blame] | 28 | """Returns true if fpath is an executable.""" |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 29 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) |
| 30 | |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 31 | def which(program): |
Johnny Chen | f2c7b28 | 2011-04-26 23:10:51 +0000 | [diff] [blame] | 32 | """Returns the full path to a program; None otherwise.""" |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 33 | fpath, fname = os.path.split(program) |
| 34 | if fpath: |
| 35 | if is_exe(program): |
| 36 | return program |
| 37 | else: |
| 38 | for path in os.environ["PATH"].split(os.pathsep): |
| 39 | exe_file = os.path.join(path, program) |
| 40 | if is_exe(exe_file): |
| 41 | return exe_file |
| 42 | return None |
| 43 | |
Johnny Chen | 877c7e4 | 2010-08-07 00:16:07 +0000 | [diff] [blame] | 44 | class _WritelnDecorator(object): |
| 45 | """Used to decorate file-like objects with a handy 'writeln' method""" |
| 46 | def __init__(self,stream): |
| 47 | self.stream = stream |
| 48 | |
| 49 | def __getattr__(self, attr): |
| 50 | if attr in ('stream', '__getstate__'): |
| 51 | raise AttributeError(attr) |
| 52 | return getattr(self.stream,attr) |
| 53 | |
| 54 | def writeln(self, arg=None): |
| 55 | if arg: |
| 56 | self.write(arg) |
| 57 | self.write('\n') # text-mode streams translate to \r\n if needed |
| 58 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 59 | # |
| 60 | # Global variables: |
| 61 | # |
| 62 | |
| 63 | # The test suite. |
Johnny Chen | 75e28f9 | 2010-08-05 23:42:46 +0000 | [diff] [blame] | 64 | suite = unittest2.TestSuite() |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 65 | |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 66 | # By default, both command line and Python API tests are performed. |
Johnny Chen | 3ebdacc | 2010-12-10 18:52:10 +0000 | [diff] [blame] | 67 | # Use @python_api_test decorator, defined in lldbtest.py, to mark a test as |
| 68 | # a Python API test. |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 69 | dont_do_python_api_test = False |
| 70 | |
| 71 | # By default, both command line and Python API tests are performed. |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 72 | just_do_python_api_test = False |
| 73 | |
Johnny Chen | 82ccf40 | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 74 | # By default, benchmarks tests are not run. |
| 75 | just_do_benchmarks_test = False |
| 76 | |
Johnny Chen | 82e6b1e | 2010-12-01 22:47:54 +0000 | [diff] [blame] | 77 | # The blacklist is optional (-b blacklistFile) and allows a central place to skip |
| 78 | # testclass's and/or testclass.testmethod's. |
| 79 | blacklist = None |
| 80 | |
| 81 | # The dictionary as a result of sourcing blacklistFile. |
| 82 | blacklistConfig = {} |
| 83 | |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 84 | # The config file is optional. |
| 85 | configFile = None |
| 86 | |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 87 | # Test suite repeat count. Can be overwritten with '-# count'. |
| 88 | count = 1 |
| 89 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 90 | # The dictionary as a result of sourcing configFile. |
| 91 | config = {} |
| 92 | |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 93 | # The 'archs' and 'compilers' can be specified via either command line or configFile, |
| 94 | # with the command line overriding the configFile. When specified, they should be |
| 95 | # of the list type. For example, "-A x86_64^i386" => archs=['x86_64', 'i386'] and |
| 96 | # "-C gcc^clang" => compilers=['gcc', 'clang']. |
| 97 | archs = None |
| 98 | compilers = None |
| 99 | |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 100 | # Delay startup in order for the debugger to attach. |
| 101 | delay = False |
| 102 | |
Johnny Chen | d536233 | 2011-01-29 01:21:04 +0000 | [diff] [blame] | 103 | # Dump the Python sys.path variable. Use '-D' to dump sys.path. |
Johnny Chen | 50bc638 | 2011-01-29 01:16:52 +0000 | [diff] [blame] | 104 | dumpSysPath = False |
| 105 | |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 106 | # Full path of the benchmark executable, as specified by the '-e' option. |
| 107 | bmExecutable = None |
| 108 | # The breakpoint specification of bmExecutable, as specified by the '-x' option. |
| 109 | bmBreakpointSpec = None |
Johnny Chen | 5f2ed17 | 2011-10-20 18:43:28 +0000 | [diff] [blame] | 110 | # The benchamrk iteration count, as specified by the '-y' option. |
| 111 | bmIterationCount = -1 |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 112 | |
Johnny Chen | 7d6d844 | 2010-12-03 19:59:35 +0000 | [diff] [blame] | 113 | # By default, failfast is False. Use '-F' to overwrite it. |
| 114 | failfast = False |
| 115 | |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 116 | # The filters (testclass.testmethod) used to admit tests into our test suite. |
| 117 | filters = [] |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 118 | |
Johnny Chen | 38f823c | 2011-10-11 01:30:27 +0000 | [diff] [blame] | 119 | # The runhooks is a list of lldb commands specifically for the debugger. |
| 120 | # Use '-k' to specify a runhook. |
| 121 | runHooks = [] |
| 122 | |
Johnny Chen | a224cd1 | 2010-11-08 01:21:03 +0000 | [diff] [blame] | 123 | # If '-g' is specified, the filterspec is not exclusive. If a test module does |
| 124 | # not contain testclass.testmethod which matches the filterspec, the whole test |
| 125 | # module is still admitted into our test suite. fs4all flag defaults to True. |
| 126 | fs4all = True |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 127 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 128 | # Ignore the build search path relative to this script to locate the lldb.py module. |
| 129 | ignore = False |
| 130 | |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 131 | # By default, we do not skip build and cleanup. Use '-S' option to override. |
| 132 | skip_build_and_cleanup = False |
| 133 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 134 | # By default, we skip long running test case. Use '-l' option to override. |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 135 | skip_long_running_test = True |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 136 | |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 137 | # By default, we print the build dir, lldb version, and svn info. Use '-n' option to |
| 138 | # turn it off. |
| 139 | noHeaders = False |
| 140 | |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 141 | # The regular expression pattern to match against eligible filenames as our test cases. |
| 142 | regexp = None |
| 143 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 144 | # By default, tests are executed in place and cleanups are performed afterwards. |
| 145 | # Use '-r dir' option to relocate the tests and their intermediate files to a |
| 146 | # different directory and to forgo any cleanups. The directory specified must |
| 147 | # not exist yet. |
| 148 | rdir = None |
| 149 | |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 150 | # By default, recorded session info for errored/failed test are dumped into its |
| 151 | # own file under a session directory named after the timestamp of the test suite |
| 152 | # run. Use '-s session-dir-name' to specify a specific dir name. |
| 153 | sdir_name = None |
| 154 | |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 155 | # Set this flag if there is any session info dumped during the test run. |
| 156 | sdir_has_content = False |
| 157 | |
Johnny Chen | b5fe80c | 2011-05-17 22:58:50 +0000 | [diff] [blame] | 158 | # svn_info stores the output from 'svn info lldb.base.dir'. |
| 159 | svn_info = '' |
| 160 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 161 | # Default verbosity is 0. |
| 162 | verbose = 0 |
| 163 | |
Johnny Chen | 0896719 | 2011-11-18 00:19:29 +0000 | [diff] [blame^] | 164 | # Set to True only if verbose is 0 and LLDB trace mode is off. |
| 165 | progress_bar = False |
| 166 | |
Peter Collingbourne | 61aca48 | 2011-06-20 19:06:29 +0000 | [diff] [blame] | 167 | # By default, search from the script directory. |
| 168 | testdirs = [ sys.path[0] ] |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 169 | |
Johnny Chen | 877c7e4 | 2010-08-07 00:16:07 +0000 | [diff] [blame] | 170 | # Separator string. |
| 171 | separator = '-' * 70 |
| 172 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 173 | |
| 174 | def usage(): |
| 175 | print """ |
| 176 | Usage: dotest.py [option] [args] |
| 177 | where options: |
Jim Ingham | 4f347cb | 2011-04-13 21:11:41 +0000 | [diff] [blame] | 178 | -h : print this help message and exit. Add '-v' for more detailed help. |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 179 | -A : specify the architecture(s) to launch for the inferior process |
| 180 | -A i386 => launch inferior with i386 architecture |
| 181 | -A x86_64^i386 => launch inferior with x86_64 and i386 architectures |
| 182 | -C : specify the compiler(s) used to build the inferior executable |
| 183 | -C clang => build debuggee using clang compiler |
| 184 | -C clang^gcc => build debuggee using clang and gcc compilers |
Johnny Chen | 50bc638 | 2011-01-29 01:16:52 +0000 | [diff] [blame] | 185 | -D : dump the Python sys.path variable |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 186 | -a : don't do lldb Python API tests |
| 187 | use @python_api_test to decorate a test case as lldb Python API test |
Johnny Chen | 3ebdacc | 2010-12-10 18:52:10 +0000 | [diff] [blame] | 188 | +a : just do lldb Python API tests |
Johnny Chen | cc659ad | 2010-12-10 19:02:23 +0000 | [diff] [blame] | 189 | do not specify both '-a' and '+a' at the same time |
Johnny Chen | 82ccf40 | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 190 | +b : just do benchmark tests |
| 191 | use @benchmark_test to decorate a test case as such |
Johnny Chen | 82e6b1e | 2010-12-01 22:47:54 +0000 | [diff] [blame] | 192 | -b : read a blacklist file specified after this option |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 193 | -c : read a config file specified after this option |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 194 | the architectures and compilers (note the plurals) specified via '-A' and '-C' |
| 195 | will override those specified via a config file |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 196 | (see also lldb-trunk/example/test/usage-config) |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 197 | -d : delay startup for 10 seconds (in order for the debugger to attach) |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 198 | -e : specify the full path of an executable used for benchmark purpose; |
| 199 | see also '-x', which provides the breakpoint sepcification |
Johnny Chen | 7d6d844 | 2010-12-03 19:59:35 +0000 | [diff] [blame] | 200 | -F : failfast, stop the test suite on the first error/failure |
Johnny Chen | 46be75d | 2010-10-11 16:19:48 +0000 | [diff] [blame] | 201 | -f : specify a filter, which consists of the test class name, a dot, followed by |
Johnny Chen | 1a6e92a | 2010-11-08 20:17:04 +0000 | [diff] [blame] | 202 | the test method, to only admit such test into the test suite |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 203 | e.g., -f 'ClassTypesTestCase.test_with_dwarf_and_python_api' |
Johnny Chen | a224cd1 | 2010-11-08 01:21:03 +0000 | [diff] [blame] | 204 | -g : if specified, the filterspec by -f is not exclusive, i.e., if a test module |
| 205 | does not match the filterspec (testclass.testmethod), the whole module is |
| 206 | still admitted to the test suite |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 207 | -i : ignore (don't bailout) if 'lldb.py' module cannot be located in the build |
| 208 | tree relative to this script; use PYTHONPATH to locate the module |
Johnny Chen | 38f823c | 2011-10-11 01:30:27 +0000 | [diff] [blame] | 209 | -k : specify a runhook, which is an lldb command to be executed by the debugger; |
| 210 | '-k' option can occur multiple times, the commands are executed one after the |
| 211 | other to bring the debugger to a desired state, so that, for example, further |
| 212 | benchmarking can be done |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 213 | -l : don't skip long running test |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 214 | -n : don't print the headers like build dir, lldb version, and svn info at all |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 215 | -p : specify a regexp filename pattern for inclusion in the test suite |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 216 | -r : specify a dir to relocate the tests and their intermediate files to; |
| 217 | the directory must not exist before running this test driver; |
| 218 | no cleanup of intermediate test files is performed in this case |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 219 | -S : skip the build and cleanup while running the test |
| 220 | use this option with care as you would need to build the inferior(s) by hand |
| 221 | and build the executable(s) with the correct name(s) |
| 222 | this can be used with '-# n' to stress test certain test cases for n number of |
| 223 | times |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 224 | -s : specify the name of the dir created to store the session files of tests |
| 225 | with errored or failed status; if not specified, the test driver uses the |
| 226 | timestamp as the session dir name |
Johnny Chen | a2486f2 | 2011-04-21 20:48:32 +0000 | [diff] [blame] | 227 | -t : turn on tracing of lldb command and other detailed test executions |
| 228 | -v : do verbose mode of unittest framework (print out each test case invocation) |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 229 | -x : specify the breakpoint specification for the benchmark executable; |
| 230 | see also '-e', which provides the full path of the executable |
Johnny Chen | 5f2ed17 | 2011-10-20 18:43:28 +0000 | [diff] [blame] | 231 | -y : specify the iteration count used to collect our benchmarks; an example is |
| 232 | the number of times to do 'thread step-over' to measure stepping speed |
| 233 | see also '-e' and '-x' options |
Johnny Chen | e47649c | 2010-10-07 02:04:14 +0000 | [diff] [blame] | 234 | -w : insert some wait time (currently 0.5 sec) between consecutive test cases |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 235 | -# : Repeat the test suite for a specified number of times |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 236 | |
| 237 | and: |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 238 | args : specify a list of directory names to search for test modules named after |
| 239 | Test*.py (test discovery) |
Peter Collingbourne | 5f2b5d6 | 2011-06-14 03:55:45 +0000 | [diff] [blame] | 240 | if empty, search from the current working directory, instead |
Jim Ingham | 4f347cb | 2011-04-13 21:11:41 +0000 | [diff] [blame] | 241 | """ |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 242 | |
Jim Ingham | 4f347cb | 2011-04-13 21:11:41 +0000 | [diff] [blame] | 243 | if verbose > 0: |
| 244 | print """ |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 245 | Examples: |
| 246 | |
Johnny Chen | a224cd1 | 2010-11-08 01:21:03 +0000 | [diff] [blame] | 247 | This is an example of using the -f option to pinpoint to a specfic test class |
| 248 | and test method to be run: |
Johnny Chen | 6ad7e5e | 2010-10-21 00:47:52 +0000 | [diff] [blame] | 249 | |
Johnny Chen | a224cd1 | 2010-11-08 01:21:03 +0000 | [diff] [blame] | 250 | $ ./dotest.py -f ClassTypesTestCase.test_with_dsym_and_run_command |
Johnny Chen | 6ad7e5e | 2010-10-21 00:47:52 +0000 | [diff] [blame] | 251 | ---------------------------------------------------------------------- |
| 252 | Collected 1 test |
| 253 | |
| 254 | test_with_dsym_and_run_command (TestClassTypes.ClassTypesTestCase) |
| 255 | Test 'frame variable this' when stopped on a class constructor. ... ok |
| 256 | |
| 257 | ---------------------------------------------------------------------- |
| 258 | Ran 1 test in 1.396s |
| 259 | |
| 260 | OK |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 261 | |
| 262 | And this is an example of using the -p option to run a single file (the filename |
| 263 | matches the pattern 'ObjC' and it happens to be 'TestObjCMethods.py'): |
| 264 | |
| 265 | $ ./dotest.py -v -p ObjC |
| 266 | ---------------------------------------------------------------------- |
| 267 | Collected 4 tests |
| 268 | |
| 269 | test_break_with_dsym (TestObjCMethods.FoundationTestCase) |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 270 | Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 271 | test_break_with_dwarf (TestObjCMethods.FoundationTestCase) |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 272 | Test setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok |
Johnny Chen | 9656ab2 | 2010-10-22 19:00:18 +0000 | [diff] [blame] | 273 | test_data_type_and_expr_with_dsym (TestObjCMethods.FoundationTestCase) |
| 274 | Lookup objective-c data types and evaluate expressions. ... ok |
| 275 | test_data_type_and_expr_with_dwarf (TestObjCMethods.FoundationTestCase) |
| 276 | Lookup objective-c data types and evaluate expressions. ... ok |
| 277 | |
| 278 | ---------------------------------------------------------------------- |
| 279 | Ran 4 tests in 16.661s |
| 280 | |
| 281 | OK |
Johnny Chen | 6ad7e5e | 2010-10-21 00:47:52 +0000 | [diff] [blame] | 282 | |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 283 | 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] | 284 | individual test cases can locate their supporting files correctly. The script |
| 285 | tries to set up Python's search paths for modules by looking at the build tree |
Johnny Chen | a85859f | 2010-11-11 22:14:56 +0000 | [diff] [blame] | 286 | relative to this script. See also the '-i' option in the following example. |
| 287 | |
| 288 | Finally, this is an example of using the lldb.py module distributed/installed by |
| 289 | Xcode4 to run against the tests under the 'forward' directory, and with the '-w' |
| 290 | option to add some delay between two tests. It uses ARCH=x86_64 to specify that |
| 291 | as the architecture and CC=clang to specify the compiler used for the test run: |
| 292 | |
| 293 | $ PYTHONPATH=/Xcode4/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python ARCH=x86_64 CC=clang ./dotest.py -v -w -i forward |
| 294 | |
| 295 | Session logs for test failures/errors will go into directory '2010-11-11-13_56_16' |
| 296 | ---------------------------------------------------------------------- |
| 297 | Collected 2 tests |
| 298 | |
| 299 | test_with_dsym_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase) |
| 300 | Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok |
| 301 | test_with_dwarf_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase) |
| 302 | Display *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok |
| 303 | |
| 304 | ---------------------------------------------------------------------- |
| 305 | Ran 2 tests in 5.659s |
| 306 | |
| 307 | OK |
| 308 | |
| 309 | The 'Session ...' verbiage is recently introduced (see also the '-s' option) to |
| 310 | notify the directory containing the session logs for test failures or errors. |
| 311 | In case there is any test failure/error, a similar message is appended at the |
| 312 | end of the stderr output for your convenience. |
Johnny Chen | fde69bc | 2010-09-14 22:01:40 +0000 | [diff] [blame] | 313 | |
| 314 | Environment variables related to loggings: |
| 315 | |
| 316 | o LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem |
| 317 | with a default option of 'event process' if LLDB_LOG_OPTION is not defined. |
| 318 | |
| 319 | o GDB_REMOTE_LOG: if defined, specifies the log file pathname for the |
| 320 | 'process.gdb-remote' subsystem with a default option of 'packets' if |
| 321 | GDB_REMOTE_LOG_OPTION is not defined. |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 322 | """ |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 323 | sys.exit(0) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 324 | |
| 325 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 326 | def parseOptionsAndInitTestdirs(): |
| 327 | """Initialize the list of directories containing our unittest scripts. |
| 328 | |
| 329 | '-h/--help as the first option prints out usage info and exit the program. |
| 330 | """ |
| 331 | |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 332 | global dont_do_python_api_test |
| 333 | global just_do_python_api_test |
Johnny Chen | 82ccf40 | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 334 | global just_do_benchmarks_test |
Johnny Chen | 82e6b1e | 2010-12-01 22:47:54 +0000 | [diff] [blame] | 335 | global blacklist |
| 336 | global blacklistConfig |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 337 | global configFile |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 338 | global archs |
| 339 | global compilers |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 340 | global count |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 341 | global delay |
Johnny Chen | 50bc638 | 2011-01-29 01:16:52 +0000 | [diff] [blame] | 342 | global dumpSysPath |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 343 | global bmExecutable |
| 344 | global bmBreakpointSpec |
Johnny Chen | 5f2ed17 | 2011-10-20 18:43:28 +0000 | [diff] [blame] | 345 | global bmIterationCount |
Johnny Chen | 7d6d844 | 2010-12-03 19:59:35 +0000 | [diff] [blame] | 346 | global failfast |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 347 | global filters |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 348 | global fs4all |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 349 | global ignore |
Johnny Chen | 0896719 | 2011-11-18 00:19:29 +0000 | [diff] [blame^] | 350 | global progress_bar |
Johnny Chen | 38f823c | 2011-10-11 01:30:27 +0000 | [diff] [blame] | 351 | global runHooks |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 352 | global skip_build_and_cleanup |
| 353 | global skip_long_running_test |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 354 | global noHeaders |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 355 | global regexp |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 356 | global rdir |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 357 | global sdir_name |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 358 | global verbose |
| 359 | global testdirs |
| 360 | |
Jim Ingham | 4f347cb | 2011-04-13 21:11:41 +0000 | [diff] [blame] | 361 | do_help = False |
| 362 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 363 | if len(sys.argv) == 1: |
| 364 | return |
| 365 | |
| 366 | # Process possible trace and/or verbose flag, among other things. |
| 367 | index = 1 |
Johnny Chen | ce2212c | 2010-10-07 15:41:55 +0000 | [diff] [blame] | 368 | while index < len(sys.argv): |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 369 | if sys.argv[index].startswith('-') or sys.argv[index].startswith('+'): |
| 370 | # We should continue processing... |
| 371 | pass |
| 372 | else: |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 373 | # End of option processing. |
| 374 | break |
| 375 | |
| 376 | if sys.argv[index].find('-h') != -1: |
Jim Ingham | 4f347cb | 2011-04-13 21:11:41 +0000 | [diff] [blame] | 377 | index += 1 |
| 378 | do_help = True |
Johnny Chen | 012cba1 | 2011-01-26 19:07:42 +0000 | [diff] [blame] | 379 | elif sys.argv[index].startswith('-A'): |
| 380 | # Increment by 1 to fetch the ARCH spec. |
| 381 | index += 1 |
| 382 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 383 | usage() |
Johnny Chen | eee9b86 | 2011-04-26 20:45:00 +0000 | [diff] [blame] | 384 | archs = sys.argv[index].split('^') |
Johnny Chen | 012cba1 | 2011-01-26 19:07:42 +0000 | [diff] [blame] | 385 | index += 1 |
| 386 | elif sys.argv[index].startswith('-C'): |
| 387 | # Increment by 1 to fetch the CC spec. |
| 388 | index += 1 |
| 389 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 390 | usage() |
Johnny Chen | eee9b86 | 2011-04-26 20:45:00 +0000 | [diff] [blame] | 391 | compilers = sys.argv[index].split('^') |
Johnny Chen | 012cba1 | 2011-01-26 19:07:42 +0000 | [diff] [blame] | 392 | index += 1 |
Johnny Chen | 50bc638 | 2011-01-29 01:16:52 +0000 | [diff] [blame] | 393 | elif sys.argv[index].startswith('-D'): |
| 394 | dumpSysPath = True |
| 395 | index += 1 |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 396 | elif sys.argv[index].startswith('-a'): |
| 397 | dont_do_python_api_test = True |
| 398 | index += 1 |
| 399 | elif sys.argv[index].startswith('+a'): |
| 400 | just_do_python_api_test = True |
| 401 | index += 1 |
Johnny Chen | 82ccf40 | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 402 | elif sys.argv[index].startswith('+b'): |
| 403 | just_do_benchmarks_test = True |
| 404 | index += 1 |
Johnny Chen | 82e6b1e | 2010-12-01 22:47:54 +0000 | [diff] [blame] | 405 | elif sys.argv[index].startswith('-b'): |
| 406 | # Increment by 1 to fetch the blacklist file name option argument. |
| 407 | index += 1 |
| 408 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 409 | usage() |
| 410 | blacklistFile = sys.argv[index] |
| 411 | if not os.path.isfile(blacklistFile): |
| 412 | print "Blacklist file:", blacklistFile, "does not exist!" |
| 413 | usage() |
| 414 | index += 1 |
| 415 | # Now read the blacklist contents and assign it to blacklist. |
| 416 | execfile(blacklistFile, globals(), blacklistConfig) |
| 417 | blacklist = blacklistConfig.get('blacklist') |
Johnny Chen | 9fdb0a9 | 2010-09-18 00:16:47 +0000 | [diff] [blame] | 418 | elif sys.argv[index].startswith('-c'): |
| 419 | # Increment by 1 to fetch the config file name option argument. |
| 420 | index += 1 |
| 421 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 422 | usage() |
| 423 | configFile = sys.argv[index] |
| 424 | if not os.path.isfile(configFile): |
| 425 | print "Config file:", configFile, "does not exist!" |
| 426 | usage() |
| 427 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 428 | elif sys.argv[index].startswith('-d'): |
| 429 | delay = True |
| 430 | index += 1 |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 431 | elif sys.argv[index].startswith('-e'): |
| 432 | # Increment by 1 to fetch the full path of the benchmark executable. |
| 433 | index += 1 |
| 434 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 435 | usage() |
| 436 | bmExecutable = sys.argv[index] |
| 437 | if not is_exe(bmExecutable): |
| 438 | usage() |
| 439 | index += 1 |
Johnny Chen | 7d6d844 | 2010-12-03 19:59:35 +0000 | [diff] [blame] | 440 | elif sys.argv[index].startswith('-F'): |
| 441 | failfast = True |
| 442 | index += 1 |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 443 | elif sys.argv[index].startswith('-f'): |
| 444 | # Increment by 1 to fetch the filter spec. |
| 445 | index += 1 |
| 446 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 447 | usage() |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 448 | filters.append(sys.argv[index]) |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 449 | index += 1 |
| 450 | elif sys.argv[index].startswith('-g'): |
Johnny Chen | a224cd1 | 2010-11-08 01:21:03 +0000 | [diff] [blame] | 451 | fs4all = False |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 452 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 453 | elif sys.argv[index].startswith('-i'): |
| 454 | ignore = True |
| 455 | index += 1 |
Johnny Chen | 38f823c | 2011-10-11 01:30:27 +0000 | [diff] [blame] | 456 | elif sys.argv[index].startswith('-k'): |
| 457 | # Increment by 1 to fetch the runhook lldb command. |
| 458 | index += 1 |
| 459 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 460 | usage() |
| 461 | runHooks.append(sys.argv[index]) |
| 462 | index += 1 |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 463 | elif sys.argv[index].startswith('-l'): |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 464 | skip_long_running_test = False |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 465 | index += 1 |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 466 | elif sys.argv[index].startswith('-n'): |
| 467 | noHeaders = True |
| 468 | index += 1 |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 469 | elif sys.argv[index].startswith('-p'): |
| 470 | # Increment by 1 to fetch the reg exp pattern argument. |
| 471 | index += 1 |
| 472 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 473 | usage() |
| 474 | regexp = sys.argv[index] |
| 475 | index += 1 |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 476 | elif sys.argv[index].startswith('-r'): |
| 477 | # Increment by 1 to fetch the relocated directory argument. |
| 478 | index += 1 |
| 479 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 480 | usage() |
| 481 | rdir = os.path.abspath(sys.argv[index]) |
| 482 | if os.path.exists(rdir): |
| 483 | print "Relocated directory:", rdir, "must not exist!" |
| 484 | usage() |
| 485 | index += 1 |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 486 | elif sys.argv[index].startswith('-S'): |
| 487 | skip_build_and_cleanup = True |
| 488 | index += 1 |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 489 | elif sys.argv[index].startswith('-s'): |
| 490 | # Increment by 1 to fetch the session dir name. |
| 491 | index += 1 |
| 492 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 493 | usage() |
| 494 | sdir_name = sys.argv[index] |
| 495 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 496 | elif sys.argv[index].startswith('-t'): |
| 497 | os.environ["LLDB_COMMAND_TRACE"] = "YES" |
| 498 | index += 1 |
| 499 | elif sys.argv[index].startswith('-v'): |
| 500 | verbose = 2 |
| 501 | index += 1 |
Johnny Chen | e47649c | 2010-10-07 02:04:14 +0000 | [diff] [blame] | 502 | elif sys.argv[index].startswith('-w'): |
| 503 | os.environ["LLDB_WAIT_BETWEEN_TEST_CASES"] = 'YES' |
| 504 | index += 1 |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 505 | elif sys.argv[index].startswith('-x'): |
| 506 | # Increment by 1 to fetch the breakpoint specification of the benchmark executable. |
| 507 | index += 1 |
Johnny Chen | 8a1b122 | 2011-10-20 22:16:24 +0000 | [diff] [blame] | 508 | if index >= len(sys.argv): |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 509 | usage() |
| 510 | bmBreakpointSpec = sys.argv[index] |
| 511 | index += 1 |
Johnny Chen | 5f2ed17 | 2011-10-20 18:43:28 +0000 | [diff] [blame] | 512 | elif sys.argv[index].startswith('-y'): |
| 513 | # Increment by 1 to fetch the the benchmark iteration count. |
| 514 | index += 1 |
| 515 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 516 | usage() |
| 517 | bmIterationCount = int(sys.argv[index]) |
| 518 | index += 1 |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 519 | elif sys.argv[index].startswith('-#'): |
| 520 | # Increment by 1 to fetch the repeat count argument. |
| 521 | index += 1 |
| 522 | if index >= len(sys.argv) or sys.argv[index].startswith('-'): |
| 523 | usage() |
| 524 | count = int(sys.argv[index]) |
| 525 | index += 1 |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 526 | else: |
| 527 | print "Unknown option: ", sys.argv[index] |
| 528 | usage() |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 529 | |
Jim Ingham | 4f347cb | 2011-04-13 21:11:41 +0000 | [diff] [blame] | 530 | if do_help == True: |
| 531 | usage() |
| 532 | |
Johnny Chen | cc659ad | 2010-12-10 19:02:23 +0000 | [diff] [blame] | 533 | # Do not specify both '-a' and '+a' at the same time. |
| 534 | if dont_do_python_api_test and just_do_python_api_test: |
| 535 | usage() |
| 536 | |
Johnny Chen | 0896719 | 2011-11-18 00:19:29 +0000 | [diff] [blame^] | 537 | # The simple progress bar is turned on only if verbose == 0 and LLDB_COMMAND_TRACE is not 'YES' |
| 538 | if ("LLDB_COMMAND_TRACE" not in os.environ or os.environ["LLDB_COMMAND_TRACE"]!="YES") and verbose==0: |
| 539 | progress_bar = True |
| 540 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 541 | # Gather all the dirs passed on the command line. |
| 542 | if len(sys.argv) > index: |
| 543 | testdirs = map(os.path.abspath, sys.argv[index:]) |
| 544 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 545 | # If '-r dir' is specified, the tests should be run under the relocated |
| 546 | # directory. Let's copy the testdirs over. |
| 547 | if rdir: |
| 548 | from shutil import copytree, ignore_patterns |
| 549 | |
| 550 | tmpdirs = [] |
| 551 | for srcdir in testdirs: |
| 552 | dstdir = os.path.join(rdir, os.path.basename(srcdir)) |
| 553 | # Don't copy the *.pyc and .svn stuffs. |
| 554 | copytree(srcdir, dstdir, ignore=ignore_patterns('*.pyc', '.svn')) |
| 555 | tmpdirs.append(dstdir) |
| 556 | |
| 557 | # This will be our modified testdirs. |
| 558 | testdirs = tmpdirs |
| 559 | |
| 560 | # With '-r dir' specified, there's no cleanup of intermediate test files. |
| 561 | os.environ["LLDB_DO_CLEANUP"] = 'NO' |
| 562 | |
| 563 | # If testdirs is ['test'], the make directory has already been copied |
| 564 | # recursively and is contained within the rdir/test dir. For anything |
| 565 | # else, we would need to copy over the make directory and its contents, |
| 566 | # so that, os.listdir(rdir) looks like, for example: |
| 567 | # |
| 568 | # array_types conditional_break make |
| 569 | # |
| 570 | # where the make directory contains the Makefile.rules file. |
| 571 | if len(testdirs) != 1 or os.path.basename(testdirs[0]) != 'test': |
| 572 | # Don't copy the .svn stuffs. |
| 573 | copytree('make', os.path.join(rdir, 'make'), |
| 574 | ignore=ignore_patterns('.svn')) |
| 575 | |
| 576 | #print "testdirs:", testdirs |
| 577 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 578 | # Source the configFile if specified. |
| 579 | # The side effect, if any, will be felt from this point on. An example |
| 580 | # config file may be these simple two lines: |
| 581 | # |
| 582 | # sys.stderr = open("/tmp/lldbtest-stderr", "w") |
| 583 | # sys.stdout = open("/tmp/lldbtest-stdout", "w") |
| 584 | # |
| 585 | # which will reassign the two file objects to sys.stderr and sys.stdout, |
| 586 | # respectively. |
| 587 | # |
| 588 | # See also lldb-trunk/example/test/usage-config. |
| 589 | global config |
| 590 | if configFile: |
| 591 | # Pass config (a dictionary) as the locals namespace for side-effect. |
| 592 | execfile(configFile, globals(), config) |
| 593 | #print "config:", config |
| 594 | #print "sys.stderr:", sys.stderr |
| 595 | #print "sys.stdout:", sys.stdout |
| 596 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 597 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 598 | def setupSysPath(): |
Johnny Chen | 8a3c043 | 2011-03-11 20:13:06 +0000 | [diff] [blame] | 599 | """ |
| 600 | Add LLDB.framework/Resources/Python to the search paths for modules. |
| 601 | As a side effect, we also discover the 'lldb' executable and export it here. |
| 602 | """ |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 603 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 604 | global rdir |
| 605 | global testdirs |
Johnny Chen | 50bc638 | 2011-01-29 01:16:52 +0000 | [diff] [blame] | 606 | global dumpSysPath |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 607 | global noHeaders |
Johnny Chen | b5fe80c | 2011-05-17 22:58:50 +0000 | [diff] [blame] | 608 | global svn_info |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 609 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 610 | # Get the directory containing the current script. |
Johnny Chen | 4d162e5 | 2011-08-12 18:54:11 +0000 | [diff] [blame] | 611 | if ("DOTEST_PROFILE" in os.environ or "DOTEST_PDB" in os.environ) and "DOTEST_SCRIPT_DIR" in os.environ: |
Johnny Chen | 0de6ab5 | 2011-01-19 02:10:40 +0000 | [diff] [blame] | 612 | scriptPath = os.environ["DOTEST_SCRIPT_DIR"] |
| 613 | else: |
| 614 | scriptPath = sys.path[0] |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 615 | if not scriptPath.endswith('test'): |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 616 | print "This script expects to reside in lldb's test directory." |
| 617 | sys.exit(-1) |
| 618 | |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 619 | if rdir: |
| 620 | # Set up the LLDB_TEST environment variable appropriately, so that the |
| 621 | # individual tests can be located relatively. |
| 622 | # |
| 623 | # See also lldbtest.TestBase.setUpClass(cls). |
| 624 | if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test': |
| 625 | os.environ["LLDB_TEST"] = os.path.join(rdir, 'test') |
| 626 | else: |
| 627 | os.environ["LLDB_TEST"] = rdir |
| 628 | else: |
| 629 | os.environ["LLDB_TEST"] = scriptPath |
Peter Collingbourne | f6c3de8 | 2011-06-20 19:06:45 +0000 | [diff] [blame] | 630 | |
| 631 | # Set up the LLDB_SRC environment variable, so that the tests can locate |
| 632 | # the LLDB source code. |
| 633 | os.environ["LLDB_SRC"] = os.path.join(sys.path[0], os.pardir) |
| 634 | |
Johnny Chen | 9de4ede | 2010-08-31 17:42:54 +0000 | [diff] [blame] | 635 | pluginPath = os.path.join(scriptPath, 'plugins') |
Johnny Chen | 8a3c043 | 2011-03-11 20:13:06 +0000 | [diff] [blame] | 636 | pexpectPath = os.path.join(scriptPath, 'pexpect-2.4') |
Johnny Chen | 58f9392 | 2010-06-29 23:10:39 +0000 | [diff] [blame] | 637 | |
Johnny Chen | 8a3c043 | 2011-03-11 20:13:06 +0000 | [diff] [blame] | 638 | # Append script dir, plugin dir, and pexpect dir to the sys.path. |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 639 | sys.path.append(scriptPath) |
| 640 | sys.path.append(pluginPath) |
Johnny Chen | 8a3c043 | 2011-03-11 20:13:06 +0000 | [diff] [blame] | 641 | sys.path.append(pexpectPath) |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 642 | |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 643 | # This is our base name component. |
Johnny Chen | a1affab | 2010-07-03 03:41:59 +0000 | [diff] [blame] | 644 | base = os.path.abspath(os.path.join(scriptPath, os.pardir)) |
Johnny Chen | 6a564a4 | 2011-02-15 18:50:19 +0000 | [diff] [blame] | 645 | |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 646 | # These are for xcode build directories. |
Johnny Chen | 6a564a4 | 2011-02-15 18:50:19 +0000 | [diff] [blame] | 647 | xcode3_build_dir = ['build'] |
| 648 | xcode4_build_dir = ['build', 'lldb', 'Build', 'Products'] |
| 649 | dbg = ['Debug'] |
| 650 | rel = ['Release'] |
| 651 | bai = ['BuildAndIntegration'] |
| 652 | python_resource_dir = ['LLDB.framework', 'Resources', 'Python'] |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 653 | |
| 654 | # Some of the tests can invoke the 'lldb' command directly. |
| 655 | # We'll try to locate the appropriate executable right here. |
| 656 | |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 657 | # First, you can define an environment variable LLDB_EXEC specifying the |
| 658 | # full pathname of the lldb executable. |
| 659 | if "LLDB_EXEC" in os.environ and is_exe(os.environ["LLDB_EXEC"]): |
| 660 | lldbExec = os.environ["LLDB_EXEC"] |
| 661 | else: |
| 662 | lldbExec = None |
| 663 | |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 664 | executable = ['lldb'] |
| 665 | dbgExec = os.path.join(base, *(xcode3_build_dir + dbg + executable)) |
| 666 | dbgExec2 = os.path.join(base, *(xcode4_build_dir + dbg + executable)) |
| 667 | relExec = os.path.join(base, *(xcode3_build_dir + rel + executable)) |
| 668 | relExec2 = os.path.join(base, *(xcode4_build_dir + rel + executable)) |
| 669 | baiExec = os.path.join(base, *(xcode3_build_dir + bai + executable)) |
| 670 | baiExec2 = os.path.join(base, *(xcode4_build_dir + bai + executable)) |
| 671 | |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 672 | # The 'lldb' executable built here in the source tree. |
| 673 | lldbHere = None |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 674 | if is_exe(dbgExec): |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 675 | lldbHere = dbgExec |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 676 | elif is_exe(dbgExec2): |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 677 | lldbHere = dbgExec2 |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 678 | elif is_exe(relExec): |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 679 | lldbHere = relExec |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 680 | elif is_exe(relExec2): |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 681 | lldbHere = relExec2 |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 682 | elif is_exe(baiExec): |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 683 | lldbHere = baiExec |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 684 | elif is_exe(baiExec2): |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 685 | lldbHere = baiExec2 |
Daniel Dunbar | 2bd310c | 2011-10-31 23:27:06 +0000 | [diff] [blame] | 686 | elif lldbExec: |
| 687 | lldbHere = lldbExec |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 688 | |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 689 | if lldbHere: |
| 690 | os.environ["LLDB_HERE"] = lldbHere |
Johnny Chen | 0409d99 | 2011-10-25 20:08:03 +0000 | [diff] [blame] | 691 | os.environ["LLDB_BUILD_DIR"] = os.path.split(lldbHere)[0] |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 692 | if not noHeaders: |
| 693 | print "LLDB build dir:", os.environ["LLDB_BUILD_DIR"] |
Johnny Chen | 91da005 | 2011-10-28 17:56:02 +0000 | [diff] [blame] | 694 | os.system('%s -v' % lldbHere) |
Johnny Chen | 62d527e | 2011-08-04 18:17:16 +0000 | [diff] [blame] | 695 | |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 696 | # One last chance to locate the 'lldb' executable. |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 697 | if not lldbExec: |
Johnny Chen | 0409d99 | 2011-10-25 20:08:03 +0000 | [diff] [blame] | 698 | lldbExec = which('lldb') |
| 699 | if lldbHere and not lldbExec: |
Johnny Chen | 6033bed | 2011-08-26 00:00:01 +0000 | [diff] [blame] | 700 | lldbExec = lldbHere |
Johnny Chen | 0409d99 | 2011-10-25 20:08:03 +0000 | [diff] [blame] | 701 | |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 702 | |
| 703 | if not lldbExec: |
| 704 | print "The 'lldb' executable cannot be located. Some of the tests may not be run as a result." |
| 705 | else: |
| 706 | os.environ["LLDB_EXEC"] = lldbExec |
Johnny Chen | 8904eb0 | 2011-10-28 00:59:00 +0000 | [diff] [blame] | 707 | #print "The 'lldb' from PATH env variable", lldbExec |
Johnny Chen | d793146 | 2011-03-17 00:38:22 +0000 | [diff] [blame] | 708 | |
Johnny Chen | b264c9b | 2011-06-24 22:52:05 +0000 | [diff] [blame] | 709 | if os.path.isdir(os.path.join(base, '.svn')): |
| 710 | pipe = subprocess.Popen(["svn", "info", base], stdout = subprocess.PIPE) |
| 711 | svn_info = pipe.stdout.read() |
| 712 | elif os.path.isdir(os.path.join(base, '.git')): |
| 713 | pipe = subprocess.Popen(["git", "svn", "info", base], stdout = subprocess.PIPE) |
| 714 | svn_info = pipe.stdout.read() |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 715 | if not noHeaders: |
| 716 | print svn_info |
Johnny Chen | 26901c8 | 2011-03-11 19:47:23 +0000 | [diff] [blame] | 717 | |
| 718 | global ignore |
| 719 | |
| 720 | # The '-i' option is used to skip looking for lldb.py in the build tree. |
| 721 | if ignore: |
| 722 | return |
| 723 | |
Johnny Chen | 6a564a4 | 2011-02-15 18:50:19 +0000 | [diff] [blame] | 724 | dbgPath = os.path.join(base, *(xcode3_build_dir + dbg + python_resource_dir)) |
| 725 | dbgPath2 = os.path.join(base, *(xcode4_build_dir + dbg + python_resource_dir)) |
| 726 | relPath = os.path.join(base, *(xcode3_build_dir + rel + python_resource_dir)) |
| 727 | relPath2 = os.path.join(base, *(xcode4_build_dir + rel + python_resource_dir)) |
| 728 | baiPath = os.path.join(base, *(xcode3_build_dir + bai + python_resource_dir)) |
| 729 | baiPath2 = os.path.join(base, *(xcode4_build_dir + bai + python_resource_dir)) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 730 | |
| 731 | lldbPath = None |
| 732 | if os.path.isfile(os.path.join(dbgPath, 'lldb.py')): |
| 733 | lldbPath = dbgPath |
Greg Clayton | d9846b0 | 2011-02-14 21:17:06 +0000 | [diff] [blame] | 734 | elif os.path.isfile(os.path.join(dbgPath2, 'lldb.py')): |
| 735 | lldbPath = dbgPath2 |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 736 | elif os.path.isfile(os.path.join(relPath, 'lldb.py')): |
| 737 | lldbPath = relPath |
Greg Clayton | d9846b0 | 2011-02-14 21:17:06 +0000 | [diff] [blame] | 738 | elif os.path.isfile(os.path.join(relPath2, 'lldb.py')): |
| 739 | lldbPath = relPath2 |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 740 | elif os.path.isfile(os.path.join(baiPath, 'lldb.py')): |
| 741 | lldbPath = baiPath |
Greg Clayton | d9846b0 | 2011-02-14 21:17:06 +0000 | [diff] [blame] | 742 | elif os.path.isfile(os.path.join(baiPath2, 'lldb.py')): |
| 743 | lldbPath = baiPath2 |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 744 | |
| 745 | if not lldbPath: |
Johnny Chen | c202c46 | 2010-09-15 18:11:19 +0000 | [diff] [blame] | 746 | print 'This script requires lldb.py to be in either ' + dbgPath + ',', |
| 747 | print relPath + ', or ' + baiPath |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 748 | sys.exit(-1) |
| 749 | |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 750 | # This is to locate the lldb.py module. Insert it right after sys.path[0]. |
| 751 | sys.path[1:1] = [lldbPath] |
Johnny Chen | 50bc638 | 2011-01-29 01:16:52 +0000 | [diff] [blame] | 752 | if dumpSysPath: |
| 753 | print "sys.path:", sys.path |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 754 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 755 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 756 | def doDelay(delta): |
| 757 | """Delaying startup for delta-seconds to facilitate debugger attachment.""" |
| 758 | def alarm_handler(*args): |
| 759 | raise Exception("timeout") |
| 760 | |
| 761 | signal.signal(signal.SIGALRM, alarm_handler) |
| 762 | signal.alarm(delta) |
| 763 | sys.stdout.write("pid=%d\n" % os.getpid()) |
| 764 | sys.stdout.write("Enter RET to proceed (or timeout after %d seconds):" % |
| 765 | delta) |
| 766 | sys.stdout.flush() |
| 767 | try: |
| 768 | text = sys.stdin.readline() |
| 769 | except: |
| 770 | text = "" |
| 771 | signal.alarm(0) |
| 772 | sys.stdout.write("proceeding...\n") |
| 773 | pass |
| 774 | |
| 775 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 776 | def visit(prefix, dir, names): |
| 777 | """Visitor function for os.path.walk(path, visit, arg).""" |
| 778 | |
| 779 | global suite |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 780 | global regexp |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 781 | global filters |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 782 | global fs4all |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 783 | |
| 784 | for name in names: |
| 785 | if os.path.isdir(os.path.join(dir, name)): |
| 786 | continue |
| 787 | |
| 788 | if '.py' == os.path.splitext(name)[1] and name.startswith(prefix): |
Johnny Chen | 7c52ff1 | 2010-09-27 23:29:54 +0000 | [diff] [blame] | 789 | # Try to match the regexp pattern, if specified. |
| 790 | if regexp: |
| 791 | import re |
| 792 | if re.search(regexp, name): |
| 793 | #print "Filename: '%s' matches pattern: '%s'" % (name, regexp) |
| 794 | pass |
| 795 | else: |
| 796 | #print "Filename: '%s' does not match pattern: '%s'" % (name, regexp) |
| 797 | continue |
| 798 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 799 | # We found a match for our test. Add it to the suite. |
Johnny Chen | 7972335 | 2010-10-12 15:53:22 +0000 | [diff] [blame] | 800 | |
| 801 | # Update the sys.path first. |
Johnny Chen | a85d7ee | 2010-06-26 00:19:32 +0000 | [diff] [blame] | 802 | if not sys.path.count(dir): |
Johnny Chen | 548aefd | 2010-10-11 22:25:46 +0000 | [diff] [blame] | 803 | sys.path.insert(0, dir) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 804 | base = os.path.splitext(name)[0] |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 805 | |
| 806 | # Thoroughly check the filterspec against the base module and admit |
| 807 | # the (base, filterspec) combination only when it makes sense. |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 808 | filterspec = None |
| 809 | for filterspec in filters: |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 810 | # Optimistically set the flag to True. |
| 811 | filtered = True |
| 812 | module = __import__(base) |
| 813 | parts = filterspec.split('.') |
| 814 | obj = module |
| 815 | for part in parts: |
| 816 | try: |
| 817 | parent, obj = obj, getattr(obj, part) |
| 818 | except AttributeError: |
| 819 | # The filterspec has failed. |
| 820 | filtered = False |
| 821 | break |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 822 | |
Johnny Chen | db4be60 | 2011-08-12 23:55:07 +0000 | [diff] [blame] | 823 | # If filtered, we have a good filterspec. Add it. |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 824 | if filtered: |
Johnny Chen | db4be60 | 2011-08-12 23:55:07 +0000 | [diff] [blame] | 825 | #print "adding filter spec %s to module %s" % (filterspec, module) |
| 826 | suite.addTests( |
| 827 | unittest2.defaultTestLoader.loadTestsFromName(filterspec, module)) |
| 828 | continue |
Johnny Chen | c5fa005 | 2011-07-29 22:54:56 +0000 | [diff] [blame] | 829 | |
| 830 | # Forgo this module if the (base, filterspec) combo is invalid |
| 831 | # and no '-g' option is specified |
| 832 | if filters and fs4all and not filtered: |
| 833 | continue |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 834 | |
Johnny Chen | db4be60 | 2011-08-12 23:55:07 +0000 | [diff] [blame] | 835 | # Add either the filtered test case(s) (which is done before) or the entire test class. |
| 836 | if not filterspec or not filtered: |
Johnny Chen | b62436b | 2010-10-06 20:40:56 +0000 | [diff] [blame] | 837 | # A simple case of just the module name. Also the failover case |
| 838 | # from the filterspec branch when the (base, filterspec) combo |
| 839 | # doesn't make sense. |
| 840 | suite.addTests(unittest2.defaultTestLoader.loadTestsFromName(base)) |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 841 | |
| 842 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 843 | def lldbLoggings(): |
| 844 | """Check and do lldb loggings if necessary.""" |
| 845 | |
| 846 | # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is |
| 847 | # defined. Use ${LLDB_LOG} to specify the log file. |
| 848 | ci = lldb.DBG.GetCommandInterpreter() |
| 849 | res = lldb.SBCommandReturnObject() |
| 850 | if ("LLDB_LOG" in os.environ): |
| 851 | if ("LLDB_LOG_OPTION" in os.environ): |
| 852 | lldb_log_option = os.environ["LLDB_LOG_OPTION"] |
| 853 | else: |
Johnny Chen | 8fd886c | 2010-12-08 01:25:21 +0000 | [diff] [blame] | 854 | lldb_log_option = "event process expr state api" |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 855 | ci.HandleCommand( |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 856 | "log enable -n -f " + os.environ["LLDB_LOG"] + " lldb " + lldb_log_option, |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 857 | res) |
| 858 | if not res.Succeeded(): |
| 859 | raise Exception('log enable failed (check LLDB_LOG env variable.') |
| 860 | # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined. |
| 861 | # Use ${GDB_REMOTE_LOG} to specify the log file. |
| 862 | if ("GDB_REMOTE_LOG" in os.environ): |
| 863 | if ("GDB_REMOTE_LOG_OPTION" in os.environ): |
| 864 | gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"] |
| 865 | else: |
Johnny Chen | 7ab8c85 | 2010-12-02 18:35:13 +0000 | [diff] [blame] | 866 | gdb_remote_log_option = "packets process" |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 867 | ci.HandleCommand( |
Johnny Chen | c935a89 | 2011-06-21 19:25:45 +0000 | [diff] [blame] | 868 | "log enable -n -f " + os.environ["GDB_REMOTE_LOG"] + " gdb-remote " |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 869 | + gdb_remote_log_option, |
| 870 | res) |
| 871 | if not res.Succeeded(): |
| 872 | raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.') |
| 873 | |
Johnny Chen | 067022b | 2011-01-19 19:31:46 +0000 | [diff] [blame] | 874 | def getMyCommandLine(): |
Johnny Chen | 067022b | 2011-01-19 19:31:46 +0000 | [diff] [blame] | 875 | ps = subprocess.Popen(['ps', '-o', "command=CMD", str(os.getpid())], stdout=subprocess.PIPE).communicate()[0] |
| 876 | lines = ps.split('\n') |
| 877 | cmd_line = lines[1] |
| 878 | return cmd_line |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 879 | |
Johnny Chen | d96b568 | 2010-11-05 17:30:53 +0000 | [diff] [blame] | 880 | # ======================================== # |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 881 | # # |
| 882 | # Execution of the test driver starts here # |
| 883 | # # |
Johnny Chen | d96b568 | 2010-11-05 17:30:53 +0000 | [diff] [blame] | 884 | # ======================================== # |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 885 | |
Johnny Chen | 2891bb0 | 2011-09-16 01:04:26 +0000 | [diff] [blame] | 886 | def checkDsymForUUIDIsNotOn(): |
Johnny Chen | 6a4e087 | 2011-09-16 17:50:44 +0000 | [diff] [blame] | 887 | cmd = ["defaults", "read", "com.apple.DebugSymbols"] |
| 888 | pipe = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) |
| 889 | cmd_output = pipe.stdout.read() |
Johnny Chen | 178c8d9 | 2011-09-16 18:03:19 +0000 | [diff] [blame] | 890 | if cmd_output and "DBGFileMappedPaths = " in cmd_output: |
Johnny Chen | 6a45148 | 2011-09-16 18:09:45 +0000 | [diff] [blame] | 891 | print "%s =>" % ' '.join(cmd) |
Johnny Chen | 6a4e087 | 2011-09-16 17:50:44 +0000 | [diff] [blame] | 892 | print cmd_output |
Johnny Chen | 2891bb0 | 2011-09-16 01:04:26 +0000 | [diff] [blame] | 893 | print "Disable automatic lookup and caching of dSYMs before running the test suite!" |
| 894 | print "Exiting..." |
| 895 | sys.exit(0) |
| 896 | |
| 897 | # On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults |
| 898 | # does not exist before proceeding to running the test suite. |
| 899 | if sys.platform.startswith("darwin"): |
| 900 | checkDsymForUUIDIsNotOn() |
| 901 | |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 902 | # |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 903 | # Start the actions by first parsing the options while setting up the test |
| 904 | # directories, followed by setting up the search paths for lldb utilities; |
| 905 | # 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] | 906 | # |
Johnny Chen | af149a0 | 2010-09-16 17:11:30 +0000 | [diff] [blame] | 907 | parseOptionsAndInitTestdirs() |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 908 | setupSysPath() |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 909 | |
| 910 | # |
| 911 | # If '-d' is specified, do a delay of 10 seconds for the debugger to attach. |
| 912 | # |
| 913 | if delay: |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 914 | doDelay(10) |
Johnny Chen | 91960d3 | 2010-09-08 20:56:16 +0000 | [diff] [blame] | 915 | |
Johnny Chen | 49f2f7a | 2010-09-20 17:25:45 +0000 | [diff] [blame] | 916 | # |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 917 | # If '-l' is specified, do not skip the long running tests. |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 918 | if not skip_long_running_test: |
Johnny Chen | 4199819 | 2010-10-01 22:59:49 +0000 | [diff] [blame] | 919 | os.environ["LLDB_SKIP_LONG_RUNNING_TEST"] = "NO" |
| 920 | |
| 921 | # |
Johnny Chen | 7972335 | 2010-10-12 15:53:22 +0000 | [diff] [blame] | 922 | # Walk through the testdirs while collecting tests. |
Johnny Chen | 49f2f7a | 2010-09-20 17:25:45 +0000 | [diff] [blame] | 923 | # |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 924 | for testdir in testdirs: |
| 925 | os.path.walk(testdir, visit, 'Test') |
| 926 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 927 | # |
Johnny Chen | 9707bb6 | 2010-06-25 21:14:08 +0000 | [diff] [blame] | 928 | # 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] | 929 | # |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 930 | |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 931 | # For the time being, let's bracket the test runner within the |
| 932 | # lldb.SBDebugger.Initialize()/Terminate() pair. |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 933 | import lldb, atexit |
Johnny Chen | 6b6f5ba | 2010-10-14 16:36:49 +0000 | [diff] [blame] | 934 | # Update: the act of importing lldb now executes lldb.SBDebugger.Initialize(), |
| 935 | # there's no need to call it a second time. |
| 936 | #lldb.SBDebugger.Initialize() |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 937 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 938 | |
Johnny Chen | 909e5a6 | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 939 | # Create a singleton SBDebugger in the lldb namespace. |
| 940 | lldb.DBG = lldb.SBDebugger.Create() |
| 941 | |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 942 | # Put the blacklist in the lldb namespace, to be used by lldb.TestBase. |
Johnny Chen | 82e6b1e | 2010-12-01 22:47:54 +0000 | [diff] [blame] | 943 | lldb.blacklist = blacklist |
| 944 | |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 945 | # Put dont/just_do_python_api_test in the lldb namespace. |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 946 | lldb.dont_do_python_api_test = dont_do_python_api_test |
| 947 | lldb.just_do_python_api_test = just_do_python_api_test |
Johnny Chen | 82ccf40 | 2011-07-30 01:39:58 +0000 | [diff] [blame] | 948 | lldb.just_do_benchmarks_test = just_do_benchmarks_test |
Johnny Chen | 4f93bf1 | 2010-12-10 00:51:23 +0000 | [diff] [blame] | 949 | |
Johnny Chen | 028d8eb | 2011-11-17 19:57:27 +0000 | [diff] [blame] | 950 | # Do we need to skip build and cleanup? |
| 951 | lldb.skip_build_and_cleanup = skip_build_and_cleanup |
| 952 | |
Johnny Chen | 5f2ed17 | 2011-10-20 18:43:28 +0000 | [diff] [blame] | 953 | # Put bmExecutable, bmBreakpointSpec, and bmIterationCount into the lldb namespace, too. |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 954 | lldb.bmExecutable = bmExecutable |
| 955 | lldb.bmBreakpointSpec = bmBreakpointSpec |
Johnny Chen | 5f2ed17 | 2011-10-20 18:43:28 +0000 | [diff] [blame] | 956 | lldb.bmIterationCount = bmIterationCount |
Johnny Chen | e00c930 | 2011-10-10 22:03:44 +0000 | [diff] [blame] | 957 | |
Johnny Chen | 38f823c | 2011-10-11 01:30:27 +0000 | [diff] [blame] | 958 | # And don't forget the runHooks! |
| 959 | lldb.runHooks = runHooks |
| 960 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 961 | # Turn on lldb loggings if necessary. |
| 962 | lldbLoggings() |
Johnny Chen | 909e5a6 | 2010-07-01 22:52:57 +0000 | [diff] [blame] | 963 | |
Johnny Chen | 7987ac9 | 2010-08-09 20:40:52 +0000 | [diff] [blame] | 964 | # Install the control-c handler. |
| 965 | unittest2.signals.installHandler() |
| 966 | |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 967 | # If sdir_name is not specified through the '-s sdir_name' option, get a |
| 968 | # timestamp string and export it as LLDB_SESSION_DIR environment var. This will |
| 969 | # be used when/if we want to dump the session info of individual test cases |
| 970 | # later on. |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 971 | # |
| 972 | # See also TestBase.dumpSessionInfo() in lldbtest.py. |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 973 | if not sdir_name: |
| 974 | import datetime |
Johnny Chen | 41fae81 | 2010-10-29 22:26:38 +0000 | [diff] [blame] | 975 | # The windows platforms don't like ':' in the pathname. |
Johnny Chen | 76bd010 | 2010-10-28 16:32:13 +0000 | [diff] [blame] | 976 | timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") |
Johnny Chen | 125fc2b | 2010-10-21 16:55:35 +0000 | [diff] [blame] | 977 | sdir_name = timestamp |
Peter Collingbourne | 132476f | 2011-06-20 23:55:53 +0000 | [diff] [blame] | 978 | os.environ["LLDB_SESSION_DIRNAME"] = os.path.join(os.getcwd(), sdir_name) |
Johnny Chen | 067022b | 2011-01-19 19:31:46 +0000 | [diff] [blame] | 979 | |
Johnny Chen | fe5f1ed | 2011-10-21 18:33:27 +0000 | [diff] [blame] | 980 | if not noHeaders: |
| 981 | sys.stderr.write("\nSession logs for test failures/errors/unexpected successes" |
| 982 | " will go into directory '%s'\n" % sdir_name) |
| 983 | sys.stderr.write("Command invoked: %s\n" % getMyCommandLine()) |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 984 | |
Johnny Chen | b5fe80c | 2011-05-17 22:58:50 +0000 | [diff] [blame] | 985 | if not os.path.isdir(sdir_name): |
| 986 | os.mkdir(sdir_name) |
| 987 | fname = os.path.join(sdir_name, "svn-info") |
| 988 | with open(fname, "w") as f: |
| 989 | print >> f, svn_info |
| 990 | print >> f, "Command invoked: %s\n" % getMyCommandLine() |
| 991 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 992 | # |
| 993 | # Invoke the default TextTestRunner to run the test suite, possibly iterating |
| 994 | # over different configurations. |
| 995 | # |
| 996 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 997 | iterArchs = False |
Johnny Chen | f032d90 | 2010-09-21 00:16:09 +0000 | [diff] [blame] | 998 | iterCompilers = False |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 999 | |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1000 | if not archs and "archs" in config: |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1001 | archs = config["archs"] |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1002 | |
| 1003 | if isinstance(archs, list) and len(archs) >= 1: |
| 1004 | iterArchs = True |
| 1005 | |
| 1006 | if not compilers and "compilers" in config: |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1007 | compilers = config["compilers"] |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1008 | |
| 1009 | if isinstance(compilers, list) and len(compilers) >= 1: |
| 1010 | iterCompilers = True |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1011 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1012 | # Make a shallow copy of sys.path, we need to manipulate the search paths later. |
| 1013 | # This is only necessary if we are relocated and with different configurations. |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1014 | if rdir: |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1015 | old_sys_path = sys.path[:] |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1016 | # If we iterate on archs or compilers, there is a chance we want to split stderr/stdout. |
| 1017 | if iterArchs or iterCompilers: |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1018 | old_stderr = sys.stderr |
| 1019 | old_stdout = sys.stdout |
| 1020 | new_stderr = None |
| 1021 | new_stdout = None |
| 1022 | |
Johnny Chen | d96b568 | 2010-11-05 17:30:53 +0000 | [diff] [blame] | 1023 | # Iterating over all possible architecture and compiler combinations. |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1024 | for ia in range(len(archs) if iterArchs else 1): |
| 1025 | archConfig = "" |
| 1026 | if iterArchs: |
Johnny Chen | 18a921f | 2010-09-30 17:11:58 +0000 | [diff] [blame] | 1027 | os.environ["ARCH"] = archs[ia] |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1028 | archConfig = "arch=%s" % archs[ia] |
| 1029 | for ic in range(len(compilers) if iterCompilers else 1): |
| 1030 | if iterCompilers: |
Johnny Chen | 18a921f | 2010-09-30 17:11:58 +0000 | [diff] [blame] | 1031 | os.environ["CC"] = compilers[ic] |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1032 | configString = "%s compiler=%s" % (archConfig, compilers[ic]) |
| 1033 | else: |
| 1034 | configString = archConfig |
| 1035 | |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1036 | if iterArchs or iterCompilers: |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1037 | # Translate ' ' to '-' for pathname component. |
| 1038 | from string import maketrans |
| 1039 | tbl = maketrans(' ', '-') |
| 1040 | configPostfix = configString.translate(tbl) |
| 1041 | |
| 1042 | # Check whether we need to split stderr/stdout into configuration |
| 1043 | # specific files. |
| 1044 | if old_stderr.name != '<stderr>' and config.get('split_stderr'): |
| 1045 | if new_stderr: |
| 1046 | new_stderr.close() |
| 1047 | new_stderr = open("%s.%s" % (old_stderr.name, configPostfix), "w") |
| 1048 | sys.stderr = new_stderr |
| 1049 | if old_stdout.name != '<stdout>' and config.get('split_stdout'): |
| 1050 | if new_stdout: |
| 1051 | new_stdout.close() |
| 1052 | new_stdout = open("%s.%s" % (old_stdout.name, configPostfix), "w") |
| 1053 | sys.stdout = new_stdout |
| 1054 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1055 | # If we specified a relocated directory to run the test suite, do |
| 1056 | # the extra housekeeping to copy the testdirs to a configStringified |
| 1057 | # directory and to update sys.path before invoking the test runner. |
| 1058 | # The purpose is to separate the configuration-specific directories |
| 1059 | # from each other. |
| 1060 | if rdir: |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1061 | from shutil import copytree, ignore_patterns |
| 1062 | |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1063 | newrdir = "%s.%s" % (rdir, configPostfix) |
| 1064 | |
| 1065 | # Copy the tree to a new directory with postfix name configPostfix. |
| 1066 | copytree(rdir, newrdir, ignore=ignore_patterns('*.pyc', '*.o', '*.d')) |
| 1067 | |
Johnny Chen | 1a4d5e7 | 2011-03-04 01:35:22 +0000 | [diff] [blame] | 1068 | # Update the LLDB_TEST environment variable to reflect new top |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1069 | # level test directory. |
| 1070 | # |
| 1071 | # See also lldbtest.TestBase.setUpClass(cls). |
| 1072 | if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test': |
| 1073 | os.environ["LLDB_TEST"] = os.path.join(newrdir, 'test') |
| 1074 | else: |
| 1075 | os.environ["LLDB_TEST"] = newrdir |
| 1076 | |
| 1077 | # And update the Python search paths for modules. |
| 1078 | sys.path = [x.replace(rdir, newrdir, 1) for x in old_sys_path] |
| 1079 | |
| 1080 | # Output the configuration. |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1081 | sys.stderr.write("\nConfiguration: " + configString + "\n") |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1082 | |
| 1083 | #print "sys.stderr name is", sys.stderr.name |
| 1084 | #print "sys.stdout name is", sys.stdout.name |
| 1085 | |
| 1086 | # First, write out the number of collected test cases. |
Johnny Chen | 0896719 | 2011-11-18 00:19:29 +0000 | [diff] [blame^] | 1087 | sys.stderr.write(separator + "\n") |
| 1088 | sys.stderr.write("Collected %d test%s\n\n" |
| 1089 | % (suite.countTestCases(), |
| 1090 | suite.countTestCases() != 1 and "s" or "")) |
Johnny Chen | 953864a | 2010-10-12 21:35:54 +0000 | [diff] [blame] | 1091 | |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1092 | class LLDBTestResult(unittest2.TextTestResult): |
| 1093 | """ |
Johnny Chen | 26be453 | 2010-11-09 23:56:14 +0000 | [diff] [blame] | 1094 | Enforce a singleton pattern to allow introspection of test progress. |
| 1095 | |
| 1096 | Overwrite addError(), addFailure(), and addExpectedFailure() methods |
| 1097 | to enable each test instance to track its failure/error status. It |
| 1098 | is used in the LLDB test framework to emit detailed trace messages |
| 1099 | to a log file for easier human inspection of test failres/errors. |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1100 | """ |
| 1101 | __singleton__ = None |
Johnny Chen | 360dd37 | 2010-11-29 17:50:10 +0000 | [diff] [blame] | 1102 | __ignore_singleton__ = False |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1103 | |
| 1104 | def __init__(self, *args): |
Johnny Chen | 360dd37 | 2010-11-29 17:50:10 +0000 | [diff] [blame] | 1105 | if not LLDBTestResult.__ignore_singleton__ and LLDBTestResult.__singleton__: |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 1106 | raise Exception("LLDBTestResult instantiated more than once") |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1107 | super(LLDBTestResult, self).__init__(*args) |
| 1108 | LLDBTestResult.__singleton__ = self |
| 1109 | # Now put this singleton into the lldb module namespace. |
| 1110 | lldb.test_result = self |
Johnny Chen | 810042e | 2011-01-05 20:24:11 +0000 | [diff] [blame] | 1111 | # Computes the format string for displaying the counter. |
| 1112 | global suite |
| 1113 | counterWidth = len(str(suite.countTestCases())) |
| 1114 | self.fmt = "%" + str(counterWidth) + "d: " |
Johnny Chen | c87fd49 | 2011-01-05 22:50:11 +0000 | [diff] [blame] | 1115 | self.indentation = ' ' * (counterWidth + 2) |
Johnny Chen | 810042e | 2011-01-05 20:24:11 +0000 | [diff] [blame] | 1116 | # This counts from 1 .. suite.countTestCases(). |
| 1117 | self.counter = 0 |
| 1118 | |
Johnny Chen | c87fd49 | 2011-01-05 22:50:11 +0000 | [diff] [blame] | 1119 | def getDescription(self, test): |
| 1120 | doc_first_line = test.shortDescription() |
| 1121 | if self.descriptions and doc_first_line: |
| 1122 | return '\n'.join((str(test), self.indentation + doc_first_line)) |
| 1123 | else: |
| 1124 | return str(test) |
| 1125 | |
Johnny Chen | 810042e | 2011-01-05 20:24:11 +0000 | [diff] [blame] | 1126 | def startTest(self, test): |
| 1127 | self.counter += 1 |
| 1128 | if self.showAll: |
| 1129 | self.stream.write(self.fmt % self.counter) |
| 1130 | super(LLDBTestResult, self).startTest(test) |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1131 | |
Johnny Chen | 0896719 | 2011-11-18 00:19:29 +0000 | [diff] [blame^] | 1132 | def stopTest(self, test): |
| 1133 | """Called when the given test has been run""" |
| 1134 | if progress_bar: |
| 1135 | sys.__stdout__.write('.') |
| 1136 | sys.__stdout__.flush() |
| 1137 | if self.counter == suite.countTestCases(): |
| 1138 | sys.__stdout__.write('\n') |
| 1139 | |
| 1140 | super(LLDBTestResult, self).stopTest(test) |
| 1141 | |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 1142 | def addError(self, test, err): |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 1143 | global sdir_has_content |
| 1144 | sdir_has_content = True |
Johnny Chen | ce68146 | 2010-10-19 00:25:01 +0000 | [diff] [blame] | 1145 | super(LLDBTestResult, self).addError(test, err) |
| 1146 | method = getattr(test, "markError", None) |
| 1147 | if method: |
| 1148 | method() |
| 1149 | |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1150 | def addFailure(self, test, err): |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 1151 | global sdir_has_content |
| 1152 | sdir_has_content = True |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1153 | super(LLDBTestResult, self).addFailure(test, err) |
| 1154 | method = getattr(test, "markFailure", None) |
| 1155 | if method: |
| 1156 | method() |
Johnny Chen | 84a6d6f | 2010-10-15 01:18:29 +0000 | [diff] [blame] | 1157 | |
Johnny Chen | dd2bb2c | 2010-11-03 18:17:03 +0000 | [diff] [blame] | 1158 | def addExpectedFailure(self, test, err): |
| 1159 | global sdir_has_content |
| 1160 | sdir_has_content = True |
| 1161 | super(LLDBTestResult, self).addExpectedFailure(test, err) |
| 1162 | method = getattr(test, "markExpectedFailure", None) |
| 1163 | if method: |
| 1164 | method() |
| 1165 | |
Johnny Chen | f5b8909 | 2011-08-15 23:09:08 +0000 | [diff] [blame] | 1166 | def addSkip(self, test, reason): |
| 1167 | global sdir_has_content |
| 1168 | sdir_has_content = True |
| 1169 | super(LLDBTestResult, self).addSkip(test, reason) |
| 1170 | method = getattr(test, "markSkippedTest", None) |
| 1171 | if method: |
| 1172 | method() |
| 1173 | |
Johnny Chen | ab2f066 | 2011-05-06 20:30:22 +0000 | [diff] [blame] | 1174 | def addUnexpectedSuccess(self, test): |
| 1175 | global sdir_has_content |
| 1176 | sdir_has_content = True |
| 1177 | super(LLDBTestResult, self).addUnexpectedSuccess(test) |
| 1178 | method = getattr(test, "markUnexpectedSuccess", None) |
| 1179 | if method: |
| 1180 | method() |
| 1181 | |
Johnny Chen | 26be453 | 2010-11-09 23:56:14 +0000 | [diff] [blame] | 1182 | # Invoke the test runner. |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 1183 | if count == 1: |
Johnny Chen | 7d6d844 | 2010-12-03 19:59:35 +0000 | [diff] [blame] | 1184 | result = unittest2.TextTestRunner(stream=sys.stderr, |
| 1185 | verbosity=verbose, |
| 1186 | failfast=failfast, |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 1187 | resultclass=LLDBTestResult).run(suite) |
| 1188 | else: |
Johnny Chen | d6e7ca2 | 2010-11-29 17:52:43 +0000 | [diff] [blame] | 1189 | # We are invoking the same test suite more than once. In this case, |
| 1190 | # mark __ignore_singleton__ flag as True so the signleton pattern is |
| 1191 | # not enforced. |
Johnny Chen | 360dd37 | 2010-11-29 17:50:10 +0000 | [diff] [blame] | 1192 | LLDBTestResult.__ignore_singleton__ = True |
Johnny Chen | d2acdb3 | 2010-11-16 22:42:58 +0000 | [diff] [blame] | 1193 | for i in range(count): |
Johnny Chen | 7d6d844 | 2010-12-03 19:59:35 +0000 | [diff] [blame] | 1194 | result = unittest2.TextTestRunner(stream=sys.stderr, |
| 1195 | verbosity=verbose, |
| 1196 | failfast=failfast, |
Johnny Chen | 360dd37 | 2010-11-29 17:50:10 +0000 | [diff] [blame] | 1197 | resultclass=LLDBTestResult).run(suite) |
Johnny Chen | b40056b | 2010-09-21 00:09:27 +0000 | [diff] [blame] | 1198 | |
Johnny Chen | 1bfbd41 | 2010-06-29 19:44:16 +0000 | [diff] [blame] | 1199 | |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 1200 | if sdir_has_content: |
Johnny Chen | ab2f066 | 2011-05-06 20:30:22 +0000 | [diff] [blame] | 1201 | sys.stderr.write("Session logs for test failures/errors/unexpected successes" |
| 1202 | " can be found in directory '%s'\n" % sdir_name) |
Johnny Chen | 63c2cba | 2010-10-29 22:20:36 +0000 | [diff] [blame] | 1203 | |
Johnny Chen | cd0279d | 2010-09-20 18:07:50 +0000 | [diff] [blame] | 1204 | # Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined. |
| 1205 | # This should not be necessary now. |
Johnny Chen | 83f6e51 | 2010-08-13 22:58:44 +0000 | [diff] [blame] | 1206 | if ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ): |
Johnny Chen | 83f6e51 | 2010-08-13 22:58:44 +0000 | [diff] [blame] | 1207 | print "Terminating Test suite..." |
| 1208 | subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())]) |
| 1209 | |
Johnny Chen | 01f2a6a | 2010-08-10 20:23:55 +0000 | [diff] [blame] | 1210 | # Exiting. |
| 1211 | sys.exit(not result.wasSuccessful) |