Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1 | from __future__ import print_function |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 2 | from __future__ import absolute_import |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 3 | |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 4 | # System modules |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 5 | import argparse |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 6 | import sys |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 7 | import multiprocessing |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 8 | import os |
| 9 | import textwrap |
| 10 | |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 11 | # Third-party modules |
| 12 | |
| 13 | # LLDB modules |
Zachary Turner | 8d4d151 | 2016-05-17 18:02:34 +0000 | [diff] [blame] | 14 | from . import configuration |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 15 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 17 | class ArgParseNamespace(object): |
| 18 | pass |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 21 | def parse_args(parser, argv): |
| 22 | """ Returns an argument object. LLDB_TEST_ARGUMENTS environment variable can |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 23 | be used to pass additional arguments. |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 24 | """ |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 25 | args = ArgParseNamespace() |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 26 | |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 27 | if ('LLDB_TEST_ARGUMENTS' in os.environ): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | print( |
| 29 | "Arguments passed through environment: '%s'" % |
| 30 | os.environ['LLDB_TEST_ARGUMENTS']) |
| 31 | args = parser.parse_args([sys.argv[0]].__add__( |
| 32 | os.environ['LLDB_TEST_ARGUMENTS'].split()), namespace=args) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 33 | |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 34 | return parser.parse_args(args=argv, namespace=args) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 35 | |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 36 | |
| 37 | def default_thread_count(): |
| 38 | # Check if specified in the environment |
| 39 | num_threads_str = os.environ.get("LLDB_TEST_THREADS") |
| 40 | if num_threads_str: |
| 41 | return int(num_threads_str) |
| 42 | else: |
| 43 | return multiprocessing.cpu_count() |
| 44 | |
| 45 | |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 46 | def create_parser(): |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | parser = argparse.ArgumentParser( |
| 48 | description='description', |
| 49 | prefix_chars='+-', |
| 50 | add_help=False) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 51 | group = None |
| 52 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | # Helper function for boolean options (group will point to the current |
| 54 | # group when executing X) |
| 55 | X = lambda optstr, helpstr, **kwargs: group.add_argument( |
| 56 | optstr, help=helpstr, action='store_true', **kwargs) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 57 | |
| 58 | group = parser.add_argument_group('Help') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | group.add_argument( |
| 60 | '-h', |
| 61 | '--help', |
| 62 | dest='h', |
| 63 | action='store_true', |
| 64 | help="Print this help message and exit. Add '-v' for more detailed help.") |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 65 | |
| 66 | # C and Python toolchain options |
| 67 | group = parser.add_argument_group('Toolchain options') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | group.add_argument( |
| 69 | '-A', |
| 70 | '--arch', |
| 71 | metavar='arch', |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame] | 72 | dest='arch', |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 73 | help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once''')) |
Pavel Labath | 6de25ec | 2017-03-15 08:51:59 +0000 | [diff] [blame] | 74 | group.add_argument('-C', '--compiler', metavar='compiler', dest='compiler', help=textwrap.dedent( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | '''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.''')) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 76 | if sys.platform == 'darwin': |
Chris Bieneman | 4c63acc | 2016-10-12 20:19:19 +0000 | [diff] [blame] | 77 | group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="macosx", help=textwrap.dedent( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | '''Specify the name of the Apple SDK (macosx, macosx.internal, iphoneos, iphoneos.internal, or path to SDK) and use the appropriate tools from that SDK's toolchain.''')) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 79 | # FIXME? This won't work for different extra flags according to each arch. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | group.add_argument( |
| 81 | '-E', |
| 82 | metavar='extra-flags', |
| 83 | help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 84 | suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures''')) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 85 | |
Jonas Devlieghere | 4955c77 | 2018-04-12 09:35:17 +0000 | [diff] [blame] | 86 | group.add_argument('--dsymutil', metavar='dsymutil', dest='dsymutil', help=textwrap.dedent('Specify which dsymutil to use.')) |
Jonas Devlieghere | 1bf22e7 | 2018-04-12 09:25:32 +0000 | [diff] [blame] | 87 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 88 | # Test filtering options |
| 89 | group = parser.add_argument_group('Test filtering options') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | group.add_argument( |
| 91 | '-f', |
| 92 | metavar='filterspec', |
| 93 | action='append', |
| 94 | 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? |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 95 | X('-l', "Don't skip long running tests") |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | group.add_argument( |
| 97 | '-p', |
| 98 | metavar='pattern', |
| 99 | help='Specify a regexp filename pattern for inclusion in the test suite') |
Francis Ricci | f833f17 | 2016-10-04 18:48:00 +0000 | [diff] [blame] | 100 | group.add_argument('--excluded', metavar='exclusion-file', action='append', help=textwrap.dedent( |
Francis Ricci | 6951707 | 2016-09-23 21:32:47 +0000 | [diff] [blame] | 101 | '''Specify a file for tests to exclude. File should contain lists of regular expressions for test files or methods, |
| 102 | with each list under a matching header (xfail files, xfail methods, skip files, skip methods)''')) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | group.add_argument( |
| 104 | '-G', |
| 105 | '--category', |
| 106 | metavar='category', |
| 107 | action='append', |
| 108 | dest='categoriesList', |
| 109 | help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.''')) |
| 110 | group.add_argument( |
| 111 | '--skip-category', |
| 112 | metavar='category', |
| 113 | action='append', |
| 114 | dest='skipCategories', |
| 115 | help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.''')) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 116 | |
| 117 | # Configuration options |
| 118 | group = parser.add_argument_group('Configuration options') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | group.add_argument( |
| 120 | '--framework', |
| 121 | metavar='framework-path', |
| 122 | help='The path to LLDB.framework') |
| 123 | group.add_argument( |
| 124 | '--executable', |
| 125 | metavar='executable-path', |
| 126 | help='The path to the lldb executable') |
| 127 | group.add_argument( |
Chris Bieneman | 265ca53 | 2017-03-14 20:04:46 +0000 | [diff] [blame] | 128 | '--server', |
| 129 | metavar='server-path', |
| 130 | help='The path to the debug server executable to use') |
| 131 | group.add_argument( |
Vedant Kumar | 45ae11c | 2018-03-08 19:46:39 +0000 | [diff] [blame] | 132 | '--out-of-tree-debugserver', |
| 133 | dest='out_of_tree_debugserver', |
| 134 | action='store_true', |
| 135 | help='A flag to indicate an out-of-tree debug server is being used') |
| 136 | group.add_argument( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | '-s', |
| 138 | metavar='name', |
| 139 | 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') |
| 140 | group.add_argument( |
| 141 | '-S', |
| 142 | '--session-file-format', |
| 143 | default=configuration.session_file_format, |
| 144 | metavar='format', |
| 145 | help='Specify session file name format. See configuration.py for a description.') |
| 146 | group.add_argument( |
| 147 | '-y', |
| 148 | type=int, |
| 149 | metavar='count', |
| 150 | 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.") |
| 151 | group.add_argument( |
| 152 | '-#', |
| 153 | type=int, |
| 154 | metavar='sharp', |
| 155 | dest='sharp', |
| 156 | help='Repeat the test suite for a specified number of times') |
| 157 | group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent( |
| 158 | "Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used")) |
| 159 | group.add_argument( |
| 160 | '--log-success', |
| 161 | dest='log_success', |
| 162 | action='store_true', |
| 163 | help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)") |
Chris Bieneman | 7ba5581 | 2016-10-21 22:13:55 +0000 | [diff] [blame] | 164 | group.add_argument( |
| 165 | '--codesign-identity', |
| 166 | metavar='Codesigning identity', |
| 167 | default='lldb_codesign', |
| 168 | help='The codesigning identity to use') |
Adrian Prantl | 5ec76fe | 2018-01-30 18:29:16 +0000 | [diff] [blame] | 169 | group.add_argument( |
| 170 | '--build-dir', |
| 171 | dest='test_build_dir', |
| 172 | metavar='Test build directory', |
Adrian Prantl | 34769d8 | 2018-02-02 18:32:29 +0000 | [diff] [blame] | 173 | default='lldb-test-build.noindex', |
Adrian Prantl | 5ec76fe | 2018-01-30 18:29:16 +0000 | [diff] [blame] | 174 | help='The root build directory for the tests. It will be removed before running.') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 175 | |
| 176 | # Configuration options |
| 177 | group = parser.add_argument_group('Remote platform options') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | group.add_argument( |
| 179 | '--platform-name', |
| 180 | dest='lldb_platform_name', |
| 181 | metavar='platform-name', |
| 182 | help='The name of a remote platform to use') |
| 183 | group.add_argument( |
| 184 | '--platform-url', |
| 185 | dest='lldb_platform_url', |
| 186 | metavar='platform-url', |
| 187 | help='A LLDB platform URL to use when connecting to a remote platform to run the test suite') |
| 188 | group.add_argument( |
| 189 | '--platform-working-dir', |
| 190 | dest='lldb_platform_working_dir', |
| 191 | metavar='platform-working-dir', |
| 192 | help='The directory to use on the remote platform.') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 193 | |
| 194 | # Test-suite behaviour |
| 195 | group = parser.add_argument_group('Runtime behaviour options') |
| 196 | X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 197 | X('-q', "Don't print extra output from this script.") |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 198 | X('-t', 'Turn on tracing of lldb command and other detailed test executions') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 199 | group.add_argument( |
| 200 | '-u', |
| 201 | dest='unset_env_varnames', |
| 202 | metavar='variable', |
| 203 | action='append', |
| 204 | help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble') |
| 205 | group.add_argument( |
| 206 | '--env', |
| 207 | dest='set_env_vars', |
| 208 | metavar='variable', |
| 209 | action='append', |
| 210 | help='Specify an environment variable to set to the given value before running the test cases e.g.: --env CXXFLAGS=-O3 --env DYLD_INSERT_LIBRARIES') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 211 | X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 212 | group.add_argument( |
| 213 | '--enable-crash-dialog', |
| 214 | dest='disable_crash_dialog', |
| 215 | action='store_false', |
| 216 | help='(Windows only) When LLDB crashes, display the Windows crash dialog.') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 217 | group.set_defaults(disable_crash_dialog=True) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 218 | |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 219 | group = parser.add_argument_group('Parallel execution options') |
| 220 | group.add_argument( |
| 221 | '--inferior', |
| 222 | action='store_true', |
| 223 | help=('specify this invocation is a multiprocess inferior, ' |
| 224 | 'used internally')) |
| 225 | group.add_argument( |
| 226 | '--no-multiprocess', |
| 227 | action='store_true', |
| 228 | help='skip running the multiprocess test runner') |
| 229 | group.add_argument( |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 230 | '--threads', |
| 231 | type=int, |
| 232 | dest='num_threads', |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 233 | default=default_thread_count(), |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 234 | help=('The number of threads/processes to use when running tests ' |
| 235 | 'separately, defaults to the number of CPU cores available')) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 236 | group.add_argument( |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 237 | '--test-subdir', |
| 238 | action='store', |
| 239 | help='Specify a test subdirectory to use relative to the test root dir' |
| 240 | ) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 241 | group.add_argument( |
| 242 | '--test-runner-name', |
| 243 | action='store', |
| 244 | help=('Specify a test runner strategy. Valid values: multiprocessing,' |
| 245 | ' multiprocessing-pool, serial, threading, threading-pool') |
| 246 | ) |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 247 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 248 | # Test results support. |
| 249 | group = parser.add_argument_group('Test results options') |
| 250 | group.add_argument( |
Todd Fiala | cee6a6a | 2015-11-09 18:51:04 +0000 | [diff] [blame] | 251 | '--curses', |
| 252 | action='store_true', |
| 253 | help='Shortcut for specifying test results using the curses formatter') |
| 254 | group.add_argument( |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 255 | '--results-file', |
| 256 | action='store', |
| 257 | help=('Specifies the file where test results will be written ' |
| 258 | 'according to the results-formatter class used')) |
| 259 | group.add_argument( |
| 260 | '--results-port', |
| 261 | action='store', |
| 262 | type=int, |
| 263 | help=('Specifies the localhost port to which the results ' |
| 264 | 'formatted output should be sent')) |
| 265 | group.add_argument( |
| 266 | '--results-formatter', |
| 267 | action='store', |
| 268 | help=('Specifies the full package/module/class name used to translate ' |
| 269 | 'test events into some kind of meaningful report, written to ' |
| 270 | 'the designated output results file-like object')) |
| 271 | group.add_argument( |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 272 | '--results-formatter-option', |
| 273 | '-O', |
| 274 | action='append', |
| 275 | dest='results_formatter_options', |
| 276 | help=('Specify an option to pass to the formatter. ' |
| 277 | 'Use --results-formatter-option="--option1=val1" ' |
| 278 | 'syntax. Note the "=" is critical, don\'t include whitespace.')) |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 279 | group.add_argument( |
| 280 | '--event-add-entries', |
| 281 | action='store', |
| 282 | help=('Specify comma-separated KEY=VAL entries to add key and value ' |
Todd Fiala | 40b180e | 2015-09-18 23:46:30 +0000 | [diff] [blame] | 283 | 'pairs to all test events generated by this test run. VAL may ' |
| 284 | 'be specified as VAL:TYPE, where TYPE may be int to convert ' |
| 285 | 'the value to an int')) |
Todd Fiala | 9315392 | 2015-12-12 19:26:56 +0000 | [diff] [blame] | 286 | |
Todd Fiala | 685a757 | 2015-12-14 21:28:46 +0000 | [diff] [blame] | 287 | # Re-run related arguments |
Todd Fiala | 9315392 | 2015-12-12 19:26:56 +0000 | [diff] [blame] | 288 | group = parser.add_argument_group('Test Re-run Options') |
| 289 | group.add_argument( |
| 290 | '--rerun-all-issues', |
| 291 | action='store_true', |
| 292 | help=('Re-run all issues that occurred during the test run ' |
| 293 | 'irrespective of the test method\'s marking as flakey. ' |
| 294 | 'Default behavior is to apply re-runs only to flakey ' |
| 295 | 'tests that generate issues.')) |
Todd Fiala | 685a757 | 2015-12-14 21:28:46 +0000 | [diff] [blame] | 296 | group.add_argument( |
| 297 | '--rerun-max-file-threshold', |
| 298 | action='store', |
| 299 | type=int, |
| 300 | default=50, |
| 301 | help=('Maximum number of files requiring a rerun beyond ' |
| 302 | 'which the rerun will not occur. This is meant to ' |
| 303 | 'stop a catastrophically failing test suite from forcing ' |
| 304 | 'all tests to be rerun in the single-worker phase.')) |
| 305 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 306 | # Remove the reference to our helper function |
| 307 | del X |
| 308 | |
| 309 | group = parser.add_argument_group('Test directories') |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 310 | group.add_argument( |
| 311 | 'args', |
| 312 | metavar='test-dir', |
| 313 | nargs='*', |
| 314 | 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.') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 315 | |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 316 | return parser |