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