blob: ba79600f1ec4df057e90b871aec08489b30081a4 [file] [log] [blame]
Vince Harronf8b9a1d2015-05-18 19:40:54 +00001import sys
Todd Fialae83f1402015-09-18 22:45:31 +00002import multiprocessing
Vince Harronf8b9a1d2015-05-18 19:40:54 +00003import os
4import textwrap
5
6if sys.version_info >= (2, 7):
7 argparse = __import__('argparse')
8else:
9 argparse = __import__('argparse_compat')
10
11class ArgParseNamespace(object):
12 pass
13
14def parse_args(parser, argv):
15 """ Returns an argument object. LLDB_TEST_ARGUMENTS environment variable can
16 be used to pass additional arguments if a compatible (>=2.7) argparse
17 library is available.
18 """
19 if sys.version_info >= (2, 7):
20 args = ArgParseNamespace()
21
22 if ('LLDB_TEST_ARGUMENTS' in os.environ):
23 print "Arguments passed through environment: '%s'" % os.environ['LLDB_TEST_ARGUMENTS']
24 args = parser.parse_args([sys.argv[0]].__add__(os.environ['LLDB_TEST_ARGUMENTS'].split()),namespace=args)
25
26 return parser.parse_args(args=argv, namespace=args)
27 else:
28 return parser.parse_args(args=argv)
29
Todd Fialae83f1402015-09-18 22:45:31 +000030
31def default_thread_count():
32 # Check if specified in the environment
33 num_threads_str = os.environ.get("LLDB_TEST_THREADS")
34 if num_threads_str:
35 return int(num_threads_str)
36 else:
37 return multiprocessing.cpu_count()
38
39
Vince Harron8994fed2015-05-22 19:49:23 +000040def create_parser():
Vince Harronf8b9a1d2015-05-18 19:40:54 +000041 parser = argparse.ArgumentParser(description='description', prefix_chars='+-', add_help=False)
42 group = None
43
44 # Helper function for boolean options (group will point to the current group when executing X)
45 X = lambda optstr, helpstr, **kwargs: group.add_argument(optstr, help=helpstr, action='store_true', **kwargs)
46
47 group = parser.add_argument_group('Help')
48 group.add_argument('-h', '--help', dest='h', action='store_true', help="Print this help message and exit. Add '-v' for more detailed help.")
49
50 # C and Python toolchain options
51 group = parser.add_argument_group('Toolchain options')
52 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'''))
53 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.'''))
54 if sys.platform == 'darwin':
55 group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', help=textwrap.dedent('''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.'''))
56 # FIXME? This won't work for different extra flags according to each arch.
57 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
58 suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures'''))
59 X('-D', 'Dump the Python sys.path variable')
60
61 # Test filtering options
62 group = parser.add_argument_group('Test filtering options')
63 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")
64 X('-a', "Don't do lldb Python API tests")
65 X('+a', "Just do lldb Python API tests. Do not specify along with '-a'", dest='plus_a')
66 X('+b', 'Just do benchmark tests', dest='plus_b')
67 group.add_argument('-b', metavar='blacklist', help='Read a blacklist file specified after this option')
68 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?
69 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')
70 X('-l', "Don't skip long running tests")
71 X('-m', "Don't do lldb-mi tests")
72 X('+m', "Just do lldb-mi tests. Do not specify along with '-m'", dest='plus_m')
73 group.add_argument('-p', metavar='pattern', help='Specify a regexp filename pattern for inclusion in the test suite')
74 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")
75 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.'''))
76 group.add_argument('--skip-category', metavar='category', action='append', dest='skipCategories', help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.'''))
77
78 # Configuration options
79 group = parser.add_argument_group('Configuration options')
80 group.add_argument('-c', metavar='config-file', help='Read a config file specified after this option') # FIXME: additional doc.
81 group.add_argument('--framework', metavar='framework-path', help='The path to LLDB.framework')
82 group.add_argument('--executable', metavar='executable-path', help='The path to the lldb executable')
83 group.add_argument('--libcxx', metavar='directory', help='The path to custom libc++ library')
84 group.add_argument('-e', metavar='benchmark-exe', help='Specify the full path of an executable used for benchmark purposes (see also: -x)')
85 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")
86 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')
87 group.add_argument('-r', metavar='dir', help="Similar to '-R', except that the directory must not exist before running this test driver")
88 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')
89 group.add_argument('-x', metavar='breakpoint-spec', help='Specify the breakpoint specification for the benchmark executable')
90 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.")
91 group.add_argument('-#', type=int, metavar='sharp', dest='sharp', help='Repeat the test suite for a specified number of times')
92 group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent("Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used"))
93 group.add_argument('--log-success', dest='log_success', action='store_true', help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)")
94
95 # Configuration options
96 group = parser.add_argument_group('Remote platform options')
97 group.add_argument('--platform-name', dest='lldb_platform_name', metavar='platform-name', help='The name of a remote platform to use')
98 group.add_argument('--platform-url', dest='lldb_platform_url', metavar='platform-url', help='A LLDB platform URL to use when connecting to a remote platform to run the test suite')
99 group.add_argument('--platform-working-dir', dest='lldb_platform_working_dir', metavar='platform-working-dir', help='The directory to use on the remote platform.')
100
101 # Test-suite behaviour
102 group = parser.add_argument_group('Runtime behaviour options')
103 X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach')
104 X('-F', 'Fail fast. Stop the test suite on the first error/failure')
105 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")
106 X('-n', "Don't print the headers like build dir, lldb version, and svn info at all")
107 X('-P', "Use the graphic progress bar.")
108 X('-q', "Don't print extra output from this script.")
109 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")
110 X('-t', 'Turn on tracing of lldb command and other detailed test executions')
111 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')
112 group.add_argument('--env', dest='set_env_vars', metavar='variable', action='append', 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')
113 X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)')
114 X('-w', 'Insert some wait time (currently 0.5 sec) between consecutive test cases')
115 X('-T', 'Obtain and dump svn information for this checkout of LLDB (off by default)')
116 group.add_argument('--enable-crash-dialog', dest='disable_crash_dialog', action='store_false', help='(Windows only) When LLDB crashes, display the Windows crash dialog.')
117 group.add_argument('--show-inferior-console', dest='hide_inferior_console', action='store_false', help='(Windows only) When launching an inferior, dont hide its console window.')
118 group.set_defaults(disable_crash_dialog=True)
119 group.set_defaults(hide_inferior_console=True)
120
Todd Fialafed95662015-09-03 18:58:44 +0000121 group = parser.add_argument_group('Parallel execution options')
122 group.add_argument(
123 '--inferior',
124 action='store_true',
125 help=('specify this invocation is a multiprocess inferior, '
126 'used internally'))
127 group.add_argument(
128 '--no-multiprocess',
129 action='store_true',
130 help='skip running the multiprocess test runner')
131 group.add_argument(
132 '--output-on-success',
133 action='store_true',
134 help=('print full output of the dotest.py inferior, '
135 'even when all tests succeed'))
136 group.add_argument(
137 '--threads',
138 type=int,
139 dest='num_threads',
Todd Fialae83f1402015-09-18 22:45:31 +0000140 default=default_thread_count(),
Todd Fialafed95662015-09-03 18:58:44 +0000141 help=('The number of threads/processes to use when running tests '
142 'separately, defaults to the number of CPU cores available'))
Todd Fiala8cbeed32015-09-08 22:22:33 +0000143 group.add_argument(
Todd Fialafed95662015-09-03 18:58:44 +0000144 '--test-subdir',
145 action='store',
146 help='Specify a test subdirectory to use relative to the test root dir'
147 )
Todd Fiala8cbeed32015-09-08 22:22:33 +0000148 group.add_argument(
149 '--test-runner-name',
150 action='store',
151 help=('Specify a test runner strategy. Valid values: multiprocessing,'
152 ' multiprocessing-pool, serial, threading, threading-pool')
153 )
Todd Fialafed95662015-09-03 18:58:44 +0000154
Todd Fiala68615ce2015-09-15 21:38:04 +0000155 # Test results support.
156 group = parser.add_argument_group('Test results options')
157 group.add_argument(
158 '--results-file',
159 action='store',
160 help=('Specifies the file where test results will be written '
161 'according to the results-formatter class used'))
162 group.add_argument(
163 '--results-port',
164 action='store',
165 type=int,
166 help=('Specifies the localhost port to which the results '
167 'formatted output should be sent'))
168 group.add_argument(
169 '--results-formatter',
170 action='store',
171 help=('Specifies the full package/module/class name used to translate '
172 'test events into some kind of meaningful report, written to '
173 'the designated output results file-like object'))
174 group.add_argument(
Todd Fialaea736242015-09-23 15:21:28 +0000175 '--results-formatter-option',
176 '-O',
177 action='append',
178 dest='results_formatter_options',
179 help=('Specify an option to pass to the formatter. '
180 'Use --results-formatter-option="--option1=val1" '
181 'syntax. Note the "=" is critical, don\'t include whitespace.'))
Todd Fiala33896a92015-09-18 21:01:13 +0000182 group.add_argument(
183 '--event-add-entries',
184 action='store',
185 help=('Specify comma-separated KEY=VAL entries to add key and value '
Todd Fiala40b180e2015-09-18 23:46:30 +0000186 'pairs to all test events generated by this test run. VAL may '
187 'be specified as VAL:TYPE, where TYPE may be int to convert '
188 'the value to an int'))
Vince Harronf8b9a1d2015-05-18 19:40:54 +0000189 # Remove the reference to our helper function
190 del X
191
192 group = parser.add_argument_group('Test directories')
193 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.')
194
Vince Harron8994fed2015-05-22 19:49:23 +0000195 return parser