1from __future__ import absolute_import 2 3# System modules 4import argparse 5import sys 6import os 7import textwrap 8 9# LLDB modules 10from . import configuration 11 12 13def create_parser(): 14 parser = argparse.ArgumentParser( 15 description='description', 16 prefix_chars='+-', 17 add_help=False) 18 group = None 19 20 # Helper function for boolean options (group will point to the current 21 # group when executing X) 22 X = lambda optstr, helpstr, **kwargs: group.add_argument( 23 optstr, help=helpstr, action='store_true', **kwargs) 24 25 group = parser.add_argument_group('Help') 26 group.add_argument( 27 '-h', 28 '--help', 29 dest='h', 30 action='store_true', 31 help="Print this help message and exit. Add '-v' for more detailed help.") 32 33 # C and Python toolchain options 34 group = parser.add_argument_group('Toolchain options') 35 group.add_argument( 36 '-A', 37 '--arch', 38 metavar='arch', 39 dest='arch', 40 help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once''')) 41 group.add_argument('-C', '--compiler', metavar='compiler', dest='compiler', help=textwrap.dedent( 42 '''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.''')) 43 if sys.platform == 'darwin': 44 group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', default="", help=textwrap.dedent( 45 '''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 group.add_argument('--libcxx-include-dir', help=textwrap.dedent( 47 'Specify the path to a custom libc++ include directory. Must be used in conjunction with --libcxx-library-dir.')) 48 group.add_argument('--libcxx-include-target-dir', help=textwrap.dedent( 49 'Specify the path to a custom libc++ include target directory to use in addition to --libcxx-include-dir. Optional.')) 50 group.add_argument('--libcxx-library-dir', help=textwrap.dedent( 51 'Specify the path to a custom libc++ library directory. Must be used in conjunction with --libcxx-include-dir.')) 52 # FIXME? This won't work for different extra flags according to each arch. 53 group.add_argument( 54 '-E', 55 metavar='extra-flags', 56 help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged 57 suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures''')) 58 59 group.add_argument('--dsymutil', metavar='dsymutil', dest='dsymutil', help=textwrap.dedent('Specify which dsymutil to use.')) 60 group.add_argument('--llvm-tools-dir', metavar='dir', dest='llvm_tools_dir', 61 help=textwrap.dedent('The location of llvm tools used for testing (yaml2obj, FileCheck, etc.).')) 62 63 # Test filtering options 64 group = parser.add_argument_group('Test filtering options') 65 group.add_argument( 66 '-f', 67 metavar='filterspec', 68 action='append', 69 help=('Specify a filter, which looks like "TestModule.TestClass.test_name". '+ 70 'You may also use shortened filters, such as '+ 71 '"TestModule.TestClass", "TestClass.test_name", or just "test_name".')) 72 group.add_argument( 73 '-p', 74 metavar='pattern', 75 help='Specify a regexp filename pattern for inclusion in the test suite') 76 group.add_argument('--excluded', metavar='exclusion-file', action='append', help=textwrap.dedent( 77 '''Specify a file for tests to exclude. File should contain lists of regular expressions for test files or methods, 78 with each list under a matching header (xfail files, xfail methods, skip files, skip methods)''')) 79 group.add_argument( 80 '-G', 81 '--category', 82 metavar='category', 83 action='append', 84 dest='categories_list', 85 help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.''')) 86 group.add_argument( 87 '--skip-category', 88 metavar='category', 89 action='append', 90 dest='skip_categories', 91 help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.''')) 92 group.add_argument( 93 '--xfail-category', 94 metavar='category', 95 action='append', 96 dest='xfail_categories', 97 help=textwrap.dedent('''Specify categories of test cases that are expected to fail. Can be specified more than once.''')) 98 99 # Configuration options 100 group = parser.add_argument_group('Configuration options') 101 group.add_argument( 102 '--framework', 103 metavar='framework-path', 104 help='The path to LLDB.framework') 105 group.add_argument( 106 '--executable', 107 metavar='executable-path', 108 help='The path to the lldb executable') 109 group.add_argument( 110 '--out-of-tree-debugserver', 111 dest='out_of_tree_debugserver', 112 action='store_true', 113 help='A flag to indicate an out-of-tree debug server is being used') 114 group.add_argument( 115 '--dwarf-version', 116 metavar='dwarf_version', 117 dest='dwarf_version', 118 type=int, 119 help='Override the DWARF version.') 120 group.add_argument( 121 '--setting', 122 metavar='SETTING=VALUE', 123 dest='settings', 124 type=str, 125 nargs=1, 126 action='append', 127 help='Run "setting set SETTING VALUE" before executing any test.') 128 group.add_argument( 129 '-y', 130 type=int, 131 metavar='count', 132 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.") 133 group.add_argument( 134 '-#', 135 type=int, 136 metavar='sharp', 137 dest='sharp', 138 help='Repeat the test suite for a specified number of times') 139 group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent( 140 "Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used")) 141 group.add_argument( 142 '--log-success', 143 dest='log_success', 144 action='store_true', 145 help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)") 146 group.add_argument( 147 '--codesign-identity', 148 metavar='Codesigning identity', 149 default='lldb_codesign', 150 help='The codesigning identity to use') 151 group.add_argument( 152 '--build-dir', 153 dest='test_build_dir', 154 metavar='Test build directory', 155 default='lldb-test-build.noindex', 156 help='The root build directory for the tests. It will be removed before running.') 157 group.add_argument( 158 '--lldb-module-cache-dir', 159 dest='lldb_module_cache_dir', 160 metavar='The clang module cache directory used by LLDB', 161 help='The clang module cache directory used by LLDB. Defaults to <test build directory>/module-cache-lldb.') 162 group.add_argument( 163 '--clang-module-cache-dir', 164 dest='clang_module_cache_dir', 165 metavar='The clang module cache directory used by Clang', 166 help='The clang module cache directory used in the Make files by Clang while building tests. Defaults to <test build directory>/module-cache-clang.') 167 group.add_argument( 168 '--lldb-libs-dir', 169 dest='lldb_libs_dir', 170 metavar='path', 171 help='The path to LLDB library directory (containing liblldb)') 172 group.add_argument( 173 '--enable-plugin', 174 dest='enabled_plugins', 175 action='append', 176 type=str, 177 metavar='A plugin whose tests will be enabled', 178 help='A plugin whose tests will be enabled. The only currently supported plugin is intel-pt.') 179 180 # Configuration options 181 group = parser.add_argument_group('Remote platform options') 182 group.add_argument( 183 '--platform-name', 184 dest='lldb_platform_name', 185 metavar='platform-name', 186 help='The name of a remote platform to use') 187 group.add_argument( 188 '--platform-url', 189 dest='lldb_platform_url', 190 metavar='platform-url', 191 help='A LLDB platform URL to use when connecting to a remote platform to run the test suite') 192 group.add_argument( 193 '--platform-working-dir', 194 dest='lldb_platform_working_dir', 195 metavar='platform-working-dir', 196 help='The directory to use on the remote platform.') 197 198 # Test-suite behaviour 199 group = parser.add_argument_group('Runtime behaviour options') 200 X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach') 201 X('-t', 'Turn on tracing of lldb command and other detailed test executions') 202 group.add_argument( 203 '-u', 204 dest='unset_env_varnames', 205 metavar='variable', 206 action='append', 207 help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble') 208 group.add_argument( 209 '--env', 210 dest='set_env_vars', 211 metavar='variable', 212 action='append', 213 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') 214 group.add_argument( 215 '--inferior-env', 216 dest='set_inferior_env_vars', 217 metavar='variable', 218 action='append', 219 help='Specify an environment variable to set to the given value for the inferior.') 220 X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)') 221 group.add_argument( 222 '--enable-crash-dialog', 223 dest='disable_crash_dialog', 224 action='store_false', 225 help='(Windows only) When LLDB crashes, display the Windows crash dialog.') 226 group.set_defaults(disable_crash_dialog=True) 227 228 # Remove the reference to our helper function 229 del X 230 231 group = parser.add_argument_group('Test directories') 232 group.add_argument( 233 'args', 234 metavar='test-dir', 235 nargs='*', 236 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.') 237 238 return parser 239