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