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