Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 1 | from __future__ import print_function |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 2 | from __future__ import absolute_import |
Zachary Turner | ff890da | 2015-10-19 23:45:41 +0000 | [diff] [blame] | 3 | |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 4 | # System modules |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 5 | import argparse |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 6 | import sys |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 7 | import multiprocessing |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 8 | import os |
| 9 | import textwrap |
| 10 | |
Zachary Turner | c1b7cd7 | 2015-11-05 19:22:28 +0000 | [diff] [blame] | 11 | # Third-party modules |
| 12 | |
| 13 | # LLDB modules |
| 14 | |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 15 | class ArgParseNamespace(object): |
| 16 | pass |
| 17 | |
| 18 | def parse_args(parser, argv): |
| 19 | """ Returns an argument object. LLDB_TEST_ARGUMENTS environment variable can |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 20 | be used to pass additional arguments. |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 21 | """ |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 22 | args = ArgParseNamespace() |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 23 | |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 24 | if ('LLDB_TEST_ARGUMENTS' in os.environ): |
| 25 | print("Arguments passed through environment: '%s'" % os.environ['LLDB_TEST_ARGUMENTS']) |
| 26 | args = parser.parse_args([sys.argv[0]].__add__(os.environ['LLDB_TEST_ARGUMENTS'].split()),namespace=args) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 27 | |
Zachary Turner | 3ad3874 | 2015-10-23 17:53:30 +0000 | [diff] [blame] | 28 | return parser.parse_args(args=argv, namespace=args) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 29 | |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 30 | |
| 31 | def default_thread_count(): |
| 32 | # Check if specified in the environment |
| 33 | num_threads_str = os.environ.get("LLDB_TEST_THREADS") |
| 34 | if num_threads_str: |
| 35 | return int(num_threads_str) |
| 36 | else: |
| 37 | return multiprocessing.cpu_count() |
| 38 | |
| 39 | |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 40 | def create_parser(): |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 41 | parser = argparse.ArgumentParser(description='description', prefix_chars='+-', add_help=False) |
| 42 | group = None |
| 43 | |
| 44 | # Helper function for boolean options (group will point to the current group when executing X) |
| 45 | X = lambda optstr, helpstr, **kwargs: group.add_argument(optstr, help=helpstr, action='store_true', **kwargs) |
| 46 | |
| 47 | group = parser.add_argument_group('Help') |
| 48 | group.add_argument('-h', '--help', dest='h', action='store_true', help="Print this help message and exit. Add '-v' for more detailed help.") |
| 49 | |
| 50 | # C and Python toolchain options |
| 51 | group = parser.add_argument_group('Toolchain options') |
| 52 | group.add_argument('-A', '--arch', metavar='arch', action='append', dest='archs', help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once''')) |
| 53 | group.add_argument('-C', '--compiler', metavar='compiler', dest='compilers', action='append', help=textwrap.dedent('''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.''')) |
| 54 | if sys.platform == 'darwin': |
| 55 | group.add_argument('--apple-sdk', metavar='apple_sdk', dest='apple_sdk', help=textwrap.dedent('''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.''')) |
| 56 | # FIXME? This won't work for different extra flags according to each arch. |
| 57 | group.add_argument('-E', metavar='extra-flags', help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged |
| 58 | suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures''')) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 59 | |
| 60 | # Test filtering options |
| 61 | group = parser.add_argument_group('Test filtering options') |
Tamas Berghammer | 4c0c7a7 | 2015-10-07 10:02:17 +0000 | [diff] [blame] | 62 | group.add_argument('-N', choices=['dwarf', 'dwo', 'dsym'], help="Don't do test cases marked with the @dsym_test/@dwarf_test/@dwo_test decorator by passing dsym/dwarf/dwo as the option arg") |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 63 | group.add_argument('-f', metavar='filterspec', action='append', help='Specify a filter, which consists of the test class name, a dot, followed by the test method, to only admit such test into the test suite') # FIXME: Example? |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 64 | X('-l', "Don't skip long running tests") |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 65 | group.add_argument('-p', metavar='pattern', help='Specify a regexp filename pattern for inclusion in the test suite') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 66 | group.add_argument('-G', '--category', metavar='category', action='append', dest='categoriesList', help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.''')) |
| 67 | group.add_argument('--skip-category', metavar='category', action='append', dest='skipCategories', help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.''')) |
| 68 | |
| 69 | # Configuration options |
| 70 | group = parser.add_argument_group('Configuration options') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 71 | group.add_argument('--framework', metavar='framework-path', help='The path to LLDB.framework') |
| 72 | group.add_argument('--executable', metavar='executable-path', help='The path to the lldb executable') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 73 | group.add_argument('-s', metavar='name', help='Specify the name of the dir created to store the session files of tests with errored or failed status. If not specified, the test driver uses the timestamp as the session dir name') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 74 | group.add_argument('-y', type=int, metavar='count', 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.") |
| 75 | group.add_argument('-#', type=int, metavar='sharp', dest='sharp', help='Repeat the test suite for a specified number of times') |
| 76 | group.add_argument('--channel', metavar='channel', dest='channels', action='append', help=textwrap.dedent("Specify the log channels (and optional categories) e.g. 'lldb all' or 'gdb-remote packets' if no categories are specified, 'default' is used")) |
| 77 | group.add_argument('--log-success', dest='log_success', action='store_true', help="Leave logs/traces even for successful test runs (useful for creating reference log files during debugging.)") |
| 78 | |
| 79 | # Configuration options |
| 80 | group = parser.add_argument_group('Remote platform options') |
| 81 | group.add_argument('--platform-name', dest='lldb_platform_name', metavar='platform-name', help='The name of a remote platform to use') |
| 82 | group.add_argument('--platform-url', dest='lldb_platform_url', metavar='platform-url', help='A LLDB platform URL to use when connecting to a remote platform to run the test suite') |
| 83 | group.add_argument('--platform-working-dir', dest='lldb_platform_working_dir', metavar='platform-working-dir', help='The directory to use on the remote platform.') |
| 84 | |
| 85 | # Test-suite behaviour |
| 86 | group = parser.add_argument_group('Runtime behaviour options') |
| 87 | X('-d', 'Suspend the process after launch to wait indefinitely for a debugger to attach') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 88 | X('-q', "Don't print extra output from this script.") |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 89 | X('-t', 'Turn on tracing of lldb command and other detailed test executions') |
| 90 | group.add_argument('-u', dest='unset_env_varnames', metavar='variable', action='append', help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble') |
| 91 | group.add_argument('--env', dest='set_env_vars', metavar='variable', action='append', 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') |
| 92 | X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 93 | group.add_argument('--enable-crash-dialog', dest='disable_crash_dialog', action='store_false', help='(Windows only) When LLDB crashes, display the Windows crash dialog.') |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 94 | group.set_defaults(disable_crash_dialog=True) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 95 | |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 96 | group = parser.add_argument_group('Parallel execution options') |
| 97 | group.add_argument( |
| 98 | '--inferior', |
| 99 | action='store_true', |
| 100 | help=('specify this invocation is a multiprocess inferior, ' |
| 101 | 'used internally')) |
| 102 | group.add_argument( |
| 103 | '--no-multiprocess', |
| 104 | action='store_true', |
| 105 | help='skip running the multiprocess test runner') |
| 106 | group.add_argument( |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 107 | '--threads', |
| 108 | type=int, |
| 109 | dest='num_threads', |
Todd Fiala | e83f140 | 2015-09-18 22:45:31 +0000 | [diff] [blame] | 110 | default=default_thread_count(), |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 111 | help=('The number of threads/processes to use when running tests ' |
| 112 | 'separately, defaults to the number of CPU cores available')) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 113 | group.add_argument( |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 114 | '--test-subdir', |
| 115 | action='store', |
| 116 | help='Specify a test subdirectory to use relative to the test root dir' |
| 117 | ) |
Todd Fiala | 8cbeed3 | 2015-09-08 22:22:33 +0000 | [diff] [blame] | 118 | group.add_argument( |
| 119 | '--test-runner-name', |
| 120 | action='store', |
| 121 | help=('Specify a test runner strategy. Valid values: multiprocessing,' |
| 122 | ' multiprocessing-pool, serial, threading, threading-pool') |
| 123 | ) |
Todd Fiala | fed9566 | 2015-09-03 18:58:44 +0000 | [diff] [blame] | 124 | |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 125 | # Test results support. |
| 126 | group = parser.add_argument_group('Test results options') |
| 127 | group.add_argument( |
Todd Fiala | cee6a6a | 2015-11-09 18:51:04 +0000 | [diff] [blame] | 128 | '--curses', |
| 129 | action='store_true', |
| 130 | help='Shortcut for specifying test results using the curses formatter') |
| 131 | group.add_argument( |
Todd Fiala | 68615ce | 2015-09-15 21:38:04 +0000 | [diff] [blame] | 132 | '--results-file', |
| 133 | action='store', |
| 134 | help=('Specifies the file where test results will be written ' |
| 135 | 'according to the results-formatter class used')) |
| 136 | group.add_argument( |
| 137 | '--results-port', |
| 138 | action='store', |
| 139 | type=int, |
| 140 | help=('Specifies the localhost port to which the results ' |
| 141 | 'formatted output should be sent')) |
| 142 | group.add_argument( |
| 143 | '--results-formatter', |
| 144 | action='store', |
| 145 | help=('Specifies the full package/module/class name used to translate ' |
| 146 | 'test events into some kind of meaningful report, written to ' |
| 147 | 'the designated output results file-like object')) |
| 148 | group.add_argument( |
Todd Fiala | ea73624 | 2015-09-23 15:21:28 +0000 | [diff] [blame] | 149 | '--results-formatter-option', |
| 150 | '-O', |
| 151 | action='append', |
| 152 | dest='results_formatter_options', |
| 153 | help=('Specify an option to pass to the formatter. ' |
| 154 | 'Use --results-formatter-option="--option1=val1" ' |
| 155 | 'syntax. Note the "=" is critical, don\'t include whitespace.')) |
Todd Fiala | 33896a9 | 2015-09-18 21:01:13 +0000 | [diff] [blame] | 156 | group.add_argument( |
| 157 | '--event-add-entries', |
| 158 | action='store', |
| 159 | help=('Specify comma-separated KEY=VAL entries to add key and value ' |
Todd Fiala | 40b180e | 2015-09-18 23:46:30 +0000 | [diff] [blame] | 160 | 'pairs to all test events generated by this test run. VAL may ' |
| 161 | 'be specified as VAL:TYPE, where TYPE may be int to convert ' |
| 162 | 'the value to an int')) |
Vince Harron | f8b9a1d | 2015-05-18 19:40:54 +0000 | [diff] [blame] | 163 | # Remove the reference to our helper function |
| 164 | del X |
| 165 | |
| 166 | group = parser.add_argument_group('Test directories') |
| 167 | group.add_argument('args', metavar='test-dir', nargs='*', 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.') |
| 168 | |
Vince Harron | 8994fed | 2015-05-22 19:49:23 +0000 | [diff] [blame] | 169 | return parser |