blob: 29150562d6daa58f6df807ae72f57c19a78389c7 [file] [log] [blame]
Zachary Turnerff890da2015-10-19 23:45:41 +00001from __future__ import print_function
Zachary Turnerc1b7cd72015-11-05 19:22:28 +00002from __future__ import absolute_import
Zachary Turnerff890da2015-10-19 23:45:41 +00003
Zachary Turnerc1b7cd72015-11-05 19:22:28 +00004# System modules
Zachary Turner3ad38742015-10-23 17:53:30 +00005import argparse
Vince Harronf8b9a1d2015-05-18 19:40:54 +00006import sys
Todd Fialae83f1402015-09-18 22:45:31 +00007import multiprocessing
Vince Harronf8b9a1d2015-05-18 19:40:54 +00008import os
9import textwrap
10
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000011# Third-party modules
12
13# LLDB modules
Zachary Turner8d4d1512016-05-17 18:02:34 +000014from . import configuration
Zachary Turnerc1b7cd72015-11-05 19:22:28 +000015
Kate Stoneb9c1b512016-09-06 20:57:50 +000016
Vince Harronf8b9a1d2015-05-18 19:40:54 +000017class ArgParseNamespace(object):
18 pass
19
Kate Stoneb9c1b512016-09-06 20:57:50 +000020
Vince Harronf8b9a1d2015-05-18 19:40:54 +000021def parse_args(parser, argv):
22 """ Returns an argument object. LLDB_TEST_ARGUMENTS environment variable can
Zachary Turner3ad38742015-10-23 17:53:30 +000023 be used to pass additional arguments.
Vince Harronf8b9a1d2015-05-18 19:40:54 +000024 """
Zachary Turner3ad38742015-10-23 17:53:30 +000025 args = ArgParseNamespace()
Vince Harronf8b9a1d2015-05-18 19:40:54 +000026
Zachary Turner3ad38742015-10-23 17:53:30 +000027 if ('LLDB_TEST_ARGUMENTS' in os.environ):
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 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 Harronf8b9a1d2015-05-18 19:40:54 +000033
Zachary Turner3ad38742015-10-23 17:53:30 +000034 return parser.parse_args(args=argv, namespace=args)
Vince Harronf8b9a1d2015-05-18 19:40:54 +000035
Todd Fialae83f1402015-09-18 22:45:31 +000036
37def 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 Harron8994fed2015-05-22 19:49:23 +000046def create_parser():
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 parser = argparse.ArgumentParser(
48 description='description',
49 prefix_chars='+-',
50 add_help=False)
Vince Harronf8b9a1d2015-05-18 19:40:54 +000051 group = None
52
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 # 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 Harronf8b9a1d2015-05-18 19:40:54 +000057
58 group = parser.add_argument_group('Help')
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 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 Harronf8b9a1d2015-05-18 19:40:54 +000065
66 # C and Python toolchain options
67 group = parser.add_argument_group('Toolchain options')
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 group.add_argument(
69 '-A',
70 '--arch',
71 metavar='arch',
72 action='append',
73 dest='archs',
74 help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once'''))
75 group.add_argument('-C', '--compiler', metavar='compiler', dest='compilers', action='append', help=textwrap.dedent(
76 '''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 Harronf8b9a1d2015-05-18 19:40:54 +000077 if sys.platform == 'darwin':
Chris Bieneman4c63acc2016-10-12 20:19:19 +000078 group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="macosx", help=textwrap.dedent(
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 '''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 Harronf8b9a1d2015-05-18 19:40:54 +000080 # FIXME? This won't work for different extra flags according to each arch.
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 group.add_argument(
82 '-E',
83 metavar='extra-flags',
84 help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged
Vince Harronf8b9a1d2015-05-18 19:40:54 +000085 suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures'''))
Vince Harronf8b9a1d2015-05-18 19:40:54 +000086
87 # Test filtering options
88 group = parser.add_argument_group('Test filtering options')
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 group.add_argument(
90 '-f',
91 metavar='filterspec',
92 action='append',
93 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 Harronf8b9a1d2015-05-18 19:40:54 +000094 X('-l', "Don't skip long running tests")
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 group.add_argument(
96 '-p',
97 metavar='pattern',
98 help='Specify a regexp filename pattern for inclusion in the test suite')
Francis Riccif833f172016-10-04 18:48:00 +000099 group.add_argument('--excluded', metavar='exclusion-file', action='append', help=textwrap.dedent(
Francis Ricci69517072016-09-23 21:32:47 +0000100 '''Specify a file for tests to exclude. File should contain lists of regular expressions for test files or methods,
101 with each list under a matching header (xfail files, xfail methods, skip files, skip methods)'''))
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 group.add_argument(
103 '-G',
104 '--category',
105 metavar='category',
106 action='append',
107 dest='categoriesList',
108 help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.'''))
109 group.add_argument(
110 '--skip-category',
111 metavar='category',
112 action='append',
113 dest='skipCategories',
114 help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.'''))
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000115
116 # Configuration options
117 group = parser.add_argument_group('Configuration options')
Kate Stoneb9c1b512016-09-06 20:57:50 +0000118 group.add_argument(
119 '--framework',
120 metavar='framework-path',
121 help='The path to LLDB.framework')
122 group.add_argument(
123 '--executable',
124 metavar='executable-path',
125 help='The path to the lldb executable')
126 group.add_argument(
Chris Bieneman265ca532017-03-14 20:04:46 +0000127 '--server',
128 metavar='server-path',
129 help='The path to the debug server executable to use')
130 group.add_argument(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131 '-s',
132 metavar='name',
133 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')
134 group.add_argument(
135 '-S',
136 '--session-file-format',
137 default=configuration.session_file_format,
138 metavar='format',
139 help='Specify session file name format. See configuration.py for a description.')
140 group.add_argument(
141 '-y',
142 type=int,
143 metavar='count',
144 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.")
145 group.add_argument(
146 '-#',
147 type=int,
148 metavar='sharp',
149 dest='sharp',
150 help='Repeat the test suite for a specified number of times')
151 group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent(
152 "Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used"))
153 group.add_argument(
154 '--log-success',
155 dest='log_success',
156 action='store_true',
157 help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)")
Chris Bieneman7ba55812016-10-21 22:13:55 +0000158 group.add_argument(
159 '--codesign-identity',
160 metavar='Codesigning identity',
161 default='lldb_codesign',
162 help='The codesigning identity to use')
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000163
164 # Configuration options
165 group = parser.add_argument_group('Remote platform options')
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 group.add_argument(
167 '--platform-name',
168 dest='lldb_platform_name',
169 metavar='platform-name',
170 help='The name of a remote platform to use')
171 group.add_argument(
172 '--platform-url',
173 dest='lldb_platform_url',
174 metavar='platform-url',
175 help='A LLDB platform URL to use when connecting to a remote platform to run the test suite')
176 group.add_argument(
177 '--platform-working-dir',
178 dest='lldb_platform_working_dir',
179 metavar='platform-working-dir',
180 help='The directory to use on the remote platform.')
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000181
182 # Test-suite behaviour
183 group = parser.add_argument_group('Runtime behaviour options')
184 X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach')
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000185 X('-q', "Don't print extra output from this script.")
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000186 X('-t', 'Turn on tracing of lldb command and other detailed test executions')
Kate Stoneb9c1b512016-09-06 20:57:50 +0000187 group.add_argument(
188 '-u',
189 dest='unset_env_varnames',
190 metavar='variable',
191 action='append',
192 help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble')
193 group.add_argument(
194 '--env',
195 dest='set_env_vars',
196 metavar='variable',
197 action='append',
198 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 Harronf8b9a1d2015-05-18 19:40:54 +0000199 X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)')
Kate Stoneb9c1b512016-09-06 20:57:50 +0000200 group.add_argument(
201 '--enable-crash-dialog',
202 dest='disable_crash_dialog',
203 action='store_false',
204 help='(Windows only) When LLDB crashes, display the Windows crash dialog.')
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000205 group.set_defaults(disable_crash_dialog=True)
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000206
Todd Fialafed95662015-09-03 18:58:44 +0000207 group = parser.add_argument_group('Parallel execution options')
208 group.add_argument(
209 '--inferior',
210 action='store_true',
211 help=('specify this invocation is a multiprocess inferior, '
212 'used internally'))
213 group.add_argument(
214 '--no-multiprocess',
215 action='store_true',
216 help='skip running the multiprocess test runner')
217 group.add_argument(
Todd Fialafed95662015-09-03 18:58:44 +0000218 '--threads',
219 type=int,
220 dest='num_threads',
Todd Fialae83f1402015-09-18 22:45:31 +0000221 default=default_thread_count(),
Todd Fialafed95662015-09-03 18:58:44 +0000222 help=('The number of threads/processes to use when running tests '
223 'separately, defaults to the number of CPU cores available'))
Todd Fiala8cbeed32015-09-08 22:22:33 +0000224 group.add_argument(
Todd Fialafed95662015-09-03 18:58:44 +0000225 '--test-subdir',
226 action='store',
227 help='Specify a test subdirectory to use relative to the test root dir'
228 )
Todd Fiala8cbeed32015-09-08 22:22:33 +0000229 group.add_argument(
230 '--test-runner-name',
231 action='store',
232 help=('Specify a test runner strategy. Valid values: multiprocessing,'
233 ' multiprocessing-pool, serial, threading, threading-pool')
234 )
Todd Fialafed95662015-09-03 18:58:44 +0000235
Todd Fiala68615ce2015-09-15 21:38:04 +0000236 # Test results support.
237 group = parser.add_argument_group('Test results options')
238 group.add_argument(
Todd Fialacee6a6a2015-11-09 18:51:04 +0000239 '--curses',
240 action='store_true',
241 help='Shortcut for specifying test results using the curses formatter')
242 group.add_argument(
Todd Fiala68615ce2015-09-15 21:38:04 +0000243 '--results-file',
244 action='store',
245 help=('Specifies the file where test results will be written '
246 'according to the results-formatter class used'))
247 group.add_argument(
248 '--results-port',
249 action='store',
250 type=int,
251 help=('Specifies the localhost port to which the results '
252 'formatted output should be sent'))
253 group.add_argument(
254 '--results-formatter',
255 action='store',
256 help=('Specifies the full package/module/class name used to translate '
257 'test events into some kind of meaningful report, written to '
258 'the designated output results file-like object'))
259 group.add_argument(
Todd Fialaea736242015-09-23 15:21:28 +0000260 '--results-formatter-option',
261 '-O',
262 action='append',
263 dest='results_formatter_options',
264 help=('Specify an option to pass to the formatter. '
265 'Use --results-formatter-option="--option1=val1" '
266 'syntax. Note the "=" is critical, don\'t include whitespace.'))
Todd Fiala33896a92015-09-18 21:01:13 +0000267 group.add_argument(
268 '--event-add-entries',
269 action='store',
270 help=('Specify comma-separated KEY=VAL entries to add key and value '
Todd Fiala40b180e2015-09-18 23:46:30 +0000271 'pairs to all test events generated by this test run. VAL may '
272 'be specified as VAL:TYPE, where TYPE may be int to convert '
273 'the value to an int'))
Todd Fiala93153922015-12-12 19:26:56 +0000274
Todd Fiala685a7572015-12-14 21:28:46 +0000275 # Re-run related arguments
Todd Fiala93153922015-12-12 19:26:56 +0000276 group = parser.add_argument_group('Test Re-run Options')
277 group.add_argument(
278 '--rerun-all-issues',
279 action='store_true',
280 help=('Re-run all issues that occurred during the test run '
281 'irrespective of the test method\'s marking as flakey. '
282 'Default behavior is to apply re-runs only to flakey '
283 'tests that generate issues.'))
Todd Fiala685a7572015-12-14 21:28:46 +0000284 group.add_argument(
285 '--rerun-max-file-threshold',
286 action='store',
287 type=int,
288 default=50,
289 help=('Maximum number of files requiring a rerun beyond '
290 'which the rerun will not occur. This is meant to '
291 'stop a catastrophically failing test suite from forcing '
292 'all tests to be rerun in the single-worker phase.'))
293
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000294 # Remove the reference to our helper function
295 del X
296
297 group = parser.add_argument_group('Test directories')
Kate Stoneb9c1b512016-09-06 20:57:50 +0000298 group.add_argument(
299 'args',
300 metavar='test-dir',
301 nargs='*',
302 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 Harronf8b9a1d2015-05-18 19:40:54 +0000303
Vince Harron8994fed2015-05-22 19:49:23 +0000304 return parser