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