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('--hermetic-libcxx', action='store_true', help=textwrap.dedent( 47 '''Force the just-built libcxx to be used for the libc++ formatter tests.''')) 48 # FIXME? This won't work for different extra flags according to each arch. 49 group.add_argument( 50 '-E', 51 metavar='extra-flags', 52 help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged 53 suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures''')) 54 55 group.add_argument('--dsymutil', metavar='dsymutil', dest='dsymutil', help=textwrap.dedent('Specify which dsymutil to use.')) 56 group.add_argument('--llvm-tools-dir', metavar='dir', dest='llvm_tools_dir', 57 help=textwrap.dedent('The location of llvm tools used for testing (yaml2obj, FileCheck, etc.).')) 58 59 # Test filtering options 60 group = parser.add_argument_group('Test filtering options') 61 group.add_argument( 62 '-f', 63 metavar='filterspec', 64 action='append', 65 help=('Specify a filter, which looks like "TestModule.TestClass.test_name". '+ 66 'You may also use shortened filters, such as '+ 67 '"TestModule.TestClass", "TestClass.test_name", or just "test_name".')) 68 group.add_argument( 69 '-p', 70 metavar='pattern', 71 help='Specify a regexp filename pattern for inclusion in the test suite') 72 group.add_argument('--excluded', metavar='exclusion-file', action='append', help=textwrap.dedent( 73 '''Specify a file for tests to exclude. File should contain lists of regular expressions for test files or methods, 74 with each list under a matching header (xfail files, xfail methods, skip files, skip methods)''')) 75 group.add_argument( 76 '-G', 77 '--category', 78 metavar='category', 79 action='append', 80 dest='categories_list', 81 help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.''')) 82 group.add_argument( 83 '--skip-category', 84 metavar='category', 85 action='append', 86 dest='skip_categories', 87 help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.''')) 88 group.add_argument( 89 '--xfail-category', 90 metavar='category', 91 action='append', 92 dest='xfail_categories', 93 help=textwrap.dedent('''Specify categories of test cases that are expected to fail. Can be specified more than once.''')) 94 95 # Configuration options 96 group = parser.add_argument_group('Configuration options') 97 group.add_argument( 98 '--framework', 99 metavar='framework-path', 100 help='The path to LLDB.framework') 101 group.add_argument( 102 '--executable', 103 metavar='executable-path', 104 help='The path to the lldb executable') 105 group.add_argument( 106 '--out-of-tree-debugserver', 107 dest='out_of_tree_debugserver', 108 action='store_true', 109 help='A flag to indicate an out-of-tree debug server is being used') 110 group.add_argument( 111 '--dwarf-version', 112 metavar='dwarf_version', 113 dest='dwarf_version', 114 type=int, 115 help='Override the DWARF version.') 116 group.add_argument( 117 '--setting', 118 metavar='SETTING=VALUE', 119 dest='settings', 120 type=str, 121 nargs=1, 122 action='append', 123 help='Run "setting set SETTING VALUE" before executing any test.') 124 group.add_argument( 125 '-y', 126 type=int, 127 metavar='count', 128 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.") 129 group.add_argument( 130 '-#', 131 type=int, 132 metavar='sharp', 133 dest='sharp', 134 help='Repeat the test suite for a specified number of times') 135 group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent( 136 "Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used")) 137 group.add_argument( 138 '--log-success', 139 dest='log_success', 140 action='store_true', 141 help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)") 142 group.add_argument( 143 '--codesign-identity', 144 metavar='Codesigning identity', 145 default='lldb_codesign', 146 help='The codesigning identity to use') 147 group.add_argument( 148 '--build-dir', 149 dest='test_build_dir', 150 metavar='Test build directory', 151 default='lldb-test-build.noindex', 152 help='The root build directory for the tests. It will be removed before running.') 153 group.add_argument( 154 '--lldb-module-cache-dir', 155 dest='lldb_module_cache_dir', 156 metavar='The clang module cache directory used by LLDB', 157 help='The clang module cache directory used by LLDB. Defaults to <test build directory>/module-cache-lldb.') 158 group.add_argument( 159 '--clang-module-cache-dir', 160 dest='clang_module_cache_dir', 161 metavar='The clang module cache directory used by Clang', 162 help='The clang module cache directory used in the Make files by Clang while building tests. Defaults to <test build directory>/module-cache-clang.') 163 group.add_argument( 164 '--lldb-libs-dir', 165 dest='lldb_libs_dir', 166 metavar='path', 167 help='The path to LLDB library directory (containing liblldb)') 168 group.add_argument( 169 '--enable-plugin', 170 dest='enabled_plugins', 171 action='append', 172 type=str, 173 metavar='A plugin whose tests will be enabled', 174 help='A plugin whose tests will be enabled. The only currently supported plugin is intel-pt.') 175 176 # Configuration options 177 group = parser.add_argument_group('Remote platform options') 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.') 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') 197 X('-t', 'Turn on tracing of lldb command and other detailed test executions') 198 group.add_argument( 199 '-u', 200 dest='unset_env_varnames', 201 metavar='variable', 202 action='append', 203 help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble') 204 group.add_argument( 205 '--env', 206 dest='set_env_vars', 207 metavar='variable', 208 action='append', 209 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') 210 group.add_argument( 211 '--inferior-env', 212 dest='set_inferior_env_vars', 213 metavar='variable', 214 action='append', 215 help='Specify an environment variable to set to the given value for the inferior.') 216 X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)') 217 group.add_argument( 218 '--enable-crash-dialog', 219 dest='disable_crash_dialog', 220 action='store_false', 221 help='(Windows only) When LLDB crashes, display the Windows crash dialog.') 222 group.set_defaults(disable_crash_dialog=True) 223 224 # Remove the reference to our helper function 225 del X 226 227 group = parser.add_argument_group('Test directories') 228 group.add_argument( 229 'args', 230 metavar='test-dir', 231 nargs='*', 232 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.') 233 234 return parser 235