xref: /openbsd-src/gnu/llvm/lldb/packages/Python/lldbsuite/test/dotest_args.py (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1061da546Spatrickfrom __future__ import absolute_import
2061da546Spatrick
3061da546Spatrick# System modules
4061da546Spatrickimport argparse
5061da546Spatrickimport sys
6061da546Spatrickimport os
7061da546Spatrickimport textwrap
8061da546Spatrick
9061da546Spatrick# LLDB modules
10061da546Spatrickfrom . import configuration
11061da546Spatrick
12061da546Spatrick
13061da546Spatrickdef create_parser():
14061da546Spatrick    parser = argparse.ArgumentParser(
15061da546Spatrick        description='description',
16061da546Spatrick        prefix_chars='+-',
17061da546Spatrick        add_help=False)
18061da546Spatrick    group = None
19061da546Spatrick
20061da546Spatrick    # Helper function for boolean options (group will point to the current
21061da546Spatrick    # group when executing X)
22061da546Spatrick    X = lambda optstr, helpstr, **kwargs: group.add_argument(
23061da546Spatrick        optstr, help=helpstr, action='store_true', **kwargs)
24061da546Spatrick
25061da546Spatrick    group = parser.add_argument_group('Help')
26061da546Spatrick    group.add_argument(
27061da546Spatrick        '-h',
28061da546Spatrick        '--help',
29061da546Spatrick        dest='h',
30061da546Spatrick        action='store_true',
31061da546Spatrick        help="Print this help message and exit.  Add '-v' for more detailed help.")
32061da546Spatrick
33061da546Spatrick    # C and Python toolchain options
34061da546Spatrick    group = parser.add_argument_group('Toolchain options')
35061da546Spatrick    group.add_argument(
36061da546Spatrick        '-A',
37061da546Spatrick        '--arch',
38061da546Spatrick        metavar='arch',
39061da546Spatrick        dest='arch',
40061da546Spatrick        help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once'''))
41061da546Spatrick    group.add_argument('-C', '--compiler', metavar='compiler', dest='compiler', help=textwrap.dedent(
42061da546Spatrick        '''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.'''))
43061da546Spatrick    if sys.platform == 'darwin':
44dda28197Spatrick        group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent(
45061da546Spatrick            '''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.'''))
46*f6aab3d8Srobert    group.add_argument('--libcxx-include-dir', help=textwrap.dedent(
47*f6aab3d8Srobert        'Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.'))
48*f6aab3d8Srobert    group.add_argument('--libcxx-include-target-dir', help=textwrap.dedent(
49*f6aab3d8Srobert        'Specify the path to a custom libc++ include target directory to use in addition to --libcxx-include-dir. Optional.'))
50*f6aab3d8Srobert    group.add_argument('--libcxx-library-dir', help=textwrap.dedent(
51*f6aab3d8Srobert        'Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.'))
52061da546Spatrick    # FIXME? This won't work for different extra flags according to each arch.
53061da546Spatrick    group.add_argument(
54061da546Spatrick        '-E',
55061da546Spatrick        metavar='extra-flags',
56061da546Spatrick        help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged
57061da546Spatrick                                                           suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures'''))
58061da546Spatrick
59061da546Spatrick    group.add_argument('--dsymutil', metavar='dsymutil', dest='dsymutil', help=textwrap.dedent('Specify which dsymutil to use.'))
60be691f3bSpatrick    group.add_argument('--llvm-tools-dir', metavar='dir', dest='llvm_tools_dir',
61be691f3bSpatrick            help=textwrap.dedent('The location of llvm tools used for testing (yaml2obj, FileCheck, etc.).'))
62061da546Spatrick
63061da546Spatrick    # Test filtering options
64061da546Spatrick    group = parser.add_argument_group('Test filtering options')
65061da546Spatrick    group.add_argument(
66061da546Spatrick        '-f',
67061da546Spatrick        metavar='filterspec',
68061da546Spatrick        action='append',
69061da546Spatrick        help=('Specify a filter, which looks like "TestModule.TestClass.test_name".  '+
70061da546Spatrick            'You may also use shortened filters, such as '+
71061da546Spatrick            '"TestModule.TestClass", "TestClass.test_name", or just "test_name".'))
72061da546Spatrick    group.add_argument(
73061da546Spatrick        '-p',
74061da546Spatrick        metavar='pattern',
75061da546Spatrick        help='Specify a regexp filename pattern for inclusion in the test suite')
76061da546Spatrick    group.add_argument('--excluded', metavar='exclusion-file', action='append', help=textwrap.dedent(
77061da546Spatrick        '''Specify a file for tests to exclude. File should contain lists of regular expressions for test files or methods,
78061da546Spatrick                                with each list under a matching header (xfail files, xfail methods, skip files, skip methods)'''))
79061da546Spatrick    group.add_argument(
80061da546Spatrick        '-G',
81061da546Spatrick        '--category',
82061da546Spatrick        metavar='category',
83061da546Spatrick        action='append',
84061da546Spatrick        dest='categories_list',
85061da546Spatrick        help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.'''))
86061da546Spatrick    group.add_argument(
87061da546Spatrick        '--skip-category',
88061da546Spatrick        metavar='category',
89061da546Spatrick        action='append',
90061da546Spatrick        dest='skip_categories',
91061da546Spatrick        help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.'''))
92061da546Spatrick    group.add_argument(
93061da546Spatrick        '--xfail-category',
94061da546Spatrick        metavar='category',
95061da546Spatrick        action='append',
96061da546Spatrick        dest='xfail_categories',
97061da546Spatrick        help=textwrap.dedent('''Specify categories of test cases that are expected to fail. Can be specified more than once.'''))
98061da546Spatrick
99061da546Spatrick    # Configuration options
100061da546Spatrick    group = parser.add_argument_group('Configuration options')
101061da546Spatrick    group.add_argument(
102061da546Spatrick        '--framework',
103061da546Spatrick        metavar='framework-path',
104061da546Spatrick        help='The path to LLDB.framework')
105061da546Spatrick    group.add_argument(
106061da546Spatrick        '--executable',
107061da546Spatrick        metavar='executable-path',
108061da546Spatrick        help='The path to the lldb executable')
109061da546Spatrick    group.add_argument(
110061da546Spatrick        '--out-of-tree-debugserver',
111061da546Spatrick        dest='out_of_tree_debugserver',
112061da546Spatrick        action='store_true',
113061da546Spatrick        help='A flag to indicate an out-of-tree debug server is being used')
114061da546Spatrick    group.add_argument(
115061da546Spatrick        '--dwarf-version',
116061da546Spatrick        metavar='dwarf_version',
117061da546Spatrick        dest='dwarf_version',
118061da546Spatrick        type=int,
119061da546Spatrick        help='Override the DWARF version.')
120061da546Spatrick    group.add_argument(
121061da546Spatrick        '--setting',
122061da546Spatrick        metavar='SETTING=VALUE',
123061da546Spatrick        dest='settings',
124061da546Spatrick        type=str,
125061da546Spatrick        nargs=1,
126061da546Spatrick        action='append',
127061da546Spatrick        help='Run "setting set SETTING VALUE" before executing any test.')
128061da546Spatrick    group.add_argument(
129061da546Spatrick        '-y',
130061da546Spatrick        type=int,
131061da546Spatrick        metavar='count',
132061da546Spatrick        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.")
133061da546Spatrick    group.add_argument(
134061da546Spatrick        '-#',
135061da546Spatrick        type=int,
136061da546Spatrick        metavar='sharp',
137061da546Spatrick        dest='sharp',
138061da546Spatrick        help='Repeat the test suite for a specified number of times')
139061da546Spatrick    group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent(
140061da546Spatrick        "Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used"))
141061da546Spatrick    group.add_argument(
142061da546Spatrick        '--log-success',
143061da546Spatrick        dest='log_success',
144061da546Spatrick        action='store_true',
145061da546Spatrick        help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)")
146061da546Spatrick    group.add_argument(
147061da546Spatrick        '--codesign-identity',
148061da546Spatrick        metavar='Codesigning identity',
149061da546Spatrick        default='lldb_codesign',
150061da546Spatrick        help='The codesigning identity to use')
151061da546Spatrick    group.add_argument(
152061da546Spatrick        '--build-dir',
153061da546Spatrick        dest='test_build_dir',
154061da546Spatrick        metavar='Test build directory',
155061da546Spatrick        default='lldb-test-build.noindex',
156061da546Spatrick        help='The root build directory for the tests. It will be removed before running.')
157061da546Spatrick    group.add_argument(
158061da546Spatrick        '--lldb-module-cache-dir',
159061da546Spatrick        dest='lldb_module_cache_dir',
160061da546Spatrick        metavar='The clang module cache directory used by LLDB',
161061da546Spatrick        help='The clang module cache directory used by LLDB. Defaults to <test build directory>/module-cache-lldb.')
162061da546Spatrick    group.add_argument(
163061da546Spatrick        '--clang-module-cache-dir',
164061da546Spatrick        dest='clang_module_cache_dir',
165061da546Spatrick        metavar='The clang module cache directory used by Clang',
166061da546Spatrick        help='The clang module cache directory used in the Make files by Clang while building tests. Defaults to <test build directory>/module-cache-clang.')
167dda28197Spatrick    group.add_argument(
168dda28197Spatrick        '--lldb-libs-dir',
169dda28197Spatrick        dest='lldb_libs_dir',
170dda28197Spatrick        metavar='path',
171dda28197Spatrick        help='The path to LLDB library directory (containing liblldb)')
172dda28197Spatrick    group.add_argument(
173dda28197Spatrick        '--enable-plugin',
174dda28197Spatrick        dest='enabled_plugins',
175dda28197Spatrick        action='append',
176dda28197Spatrick        type=str,
177dda28197Spatrick        metavar='A plugin whose tests will be enabled',
178dda28197Spatrick        help='A plugin whose tests will be enabled. The only currently supported plugin is intel-pt.')
179061da546Spatrick
180061da546Spatrick    # Configuration options
181061da546Spatrick    group = parser.add_argument_group('Remote platform options')
182061da546Spatrick    group.add_argument(
183061da546Spatrick        '--platform-name',
184061da546Spatrick        dest='lldb_platform_name',
185061da546Spatrick        metavar='platform-name',
186061da546Spatrick        help='The name of a remote platform to use')
187061da546Spatrick    group.add_argument(
188061da546Spatrick        '--platform-url',
189061da546Spatrick        dest='lldb_platform_url',
190061da546Spatrick        metavar='platform-url',
191061da546Spatrick        help='A LLDB platform URL to use when connecting to a remote platform to run the test suite')
192061da546Spatrick    group.add_argument(
193061da546Spatrick        '--platform-working-dir',
194061da546Spatrick        dest='lldb_platform_working_dir',
195061da546Spatrick        metavar='platform-working-dir',
196061da546Spatrick        help='The directory to use on the remote platform.')
197061da546Spatrick
198061da546Spatrick    # Test-suite behaviour
199061da546Spatrick    group = parser.add_argument_group('Runtime behaviour options')
200061da546Spatrick    X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach')
201061da546Spatrick    X('-t', 'Turn on tracing of lldb command and other detailed test executions')
202061da546Spatrick    group.add_argument(
203061da546Spatrick        '-u',
204061da546Spatrick        dest='unset_env_varnames',
205061da546Spatrick        metavar='variable',
206061da546Spatrick        action='append',
207061da546Spatrick        help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble')
208061da546Spatrick    group.add_argument(
209061da546Spatrick        '--env',
210061da546Spatrick        dest='set_env_vars',
211061da546Spatrick        metavar='variable',
212061da546Spatrick        action='append',
213061da546Spatrick        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')
214061da546Spatrick    group.add_argument(
215061da546Spatrick        '--inferior-env',
216061da546Spatrick        dest='set_inferior_env_vars',
217061da546Spatrick        metavar='variable',
218061da546Spatrick        action='append',
219061da546Spatrick        help='Specify an environment variable to set to the given value for the inferior.')
220061da546Spatrick    X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)')
221061da546Spatrick    group.add_argument(
222061da546Spatrick        '--enable-crash-dialog',
223061da546Spatrick        dest='disable_crash_dialog',
224061da546Spatrick        action='store_false',
225061da546Spatrick        help='(Windows only) When LLDB crashes, display the Windows crash dialog.')
226061da546Spatrick    group.set_defaults(disable_crash_dialog=True)
227061da546Spatrick
228061da546Spatrick    # Remove the reference to our helper function
229061da546Spatrick    del X
230061da546Spatrick
231061da546Spatrick    group = parser.add_argument_group('Test directories')
232061da546Spatrick    group.add_argument(
233061da546Spatrick        'args',
234061da546Spatrick        metavar='test-dir',
235061da546Spatrick        nargs='*',
236061da546Spatrick        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.')
237061da546Spatrick
238061da546Spatrick    return parser
239