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