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