|
| 1 | +import argparse |
| 2 | +import os |
| 3 | +import shlex |
| 4 | +import sys |
| 5 | + |
| 6 | +import lit.util |
| 7 | + |
| 8 | +def parse_args(): |
| 9 | + parser = argparse.ArgumentParser() |
| 10 | + parser.add_argument('test_paths', |
| 11 | + nargs='*', |
| 12 | + help='Files or paths to include in the test suite') |
| 13 | + |
| 14 | + parser.add_argument("--version", |
| 15 | + dest="show_version", |
| 16 | + help="Show version and exit", |
| 17 | + action="store_true", |
| 18 | + default=False) |
| 19 | + parser.add_argument("-j", "--workers", |
| 20 | + dest="numWorkers", |
| 21 | + metavar="N", |
| 22 | + help="Number of workers used for testing", |
| 23 | + type=int, |
| 24 | + default=None) |
| 25 | + parser.add_argument("--config-prefix", |
| 26 | + dest="configPrefix", |
| 27 | + metavar="NAME", |
| 28 | + help="Prefix for 'lit' config files", |
| 29 | + action="store", |
| 30 | + default=None) |
| 31 | + parser.add_argument("-D", "--param", |
| 32 | + dest="userParameters", |
| 33 | + metavar="NAME=VAL", |
| 34 | + help="Add 'NAME' = 'VAL' to the user defined parameters", |
| 35 | + type=str, |
| 36 | + action="append", |
| 37 | + default=[]) |
| 38 | + |
| 39 | + format_group = parser.add_argument_group("Output Format") |
| 40 | + # FIXME: I find these names very confusing, although I like the |
| 41 | + # functionality. |
| 42 | + format_group.add_argument("-q", "--quiet", |
| 43 | + help="Suppress no error output", |
| 44 | + action="store_true", |
| 45 | + default=False) |
| 46 | + format_group.add_argument("-s", "--succinct", |
| 47 | + help="Reduce amount of output", |
| 48 | + action="store_true", |
| 49 | + default=False) |
| 50 | + format_group.add_argument("-v", "--verbose", |
| 51 | + dest="showOutput", |
| 52 | + help="Show test output for failures", |
| 53 | + action="store_true", |
| 54 | + default=False) |
| 55 | + format_group.add_argument("-vv", "--echo-all-commands", |
| 56 | + dest="echoAllCommands", |
| 57 | + action="store_true", |
| 58 | + default=False, |
| 59 | + help="Echo all commands as they are executed to stdout. In case of " |
| 60 | + "failure, last command shown will be the failing one.") |
| 61 | + format_group.add_argument("-a", "--show-all", |
| 62 | + dest="showAllOutput", |
| 63 | + help="Display all commandlines and output", |
| 64 | + action="store_true", |
| 65 | + default=False) |
| 66 | + format_group.add_argument("-o", "--output", |
| 67 | + dest="output_path", |
| 68 | + help="Write test results to the provided path", |
| 69 | + action="store", |
| 70 | + metavar="PATH") |
| 71 | + format_group.add_argument("--no-progress-bar", |
| 72 | + dest="useProgressBar", |
| 73 | + help="Do not use curses based progress bar", |
| 74 | + action="store_false", |
| 75 | + default=True) |
| 76 | + format_group.add_argument("--show-unsupported", |
| 77 | + help="Show unsupported tests", |
| 78 | + action="store_true", |
| 79 | + default=False) |
| 80 | + format_group.add_argument("--show-xfail", |
| 81 | + help="Show tests that were expected to fail", |
| 82 | + action="store_true", |
| 83 | + default=False) |
| 84 | + |
| 85 | + execution_group = parser.add_argument_group("Test Execution") |
| 86 | + execution_group.add_argument("--path", |
| 87 | + help="Additional paths to add to testing environment", |
| 88 | + action="append", |
| 89 | + type=str, |
| 90 | + default=[]) |
| 91 | + execution_group.add_argument("--vg", |
| 92 | + dest="useValgrind", |
| 93 | + help="Run tests under valgrind", |
| 94 | + action="store_true", |
| 95 | + default=False) |
| 96 | + execution_group.add_argument("--vg-leak", |
| 97 | + dest="valgrindLeakCheck", |
| 98 | + help="Check for memory leaks under valgrind", |
| 99 | + action="store_true", |
| 100 | + default=False) |
| 101 | + execution_group.add_argument("--vg-arg", |
| 102 | + dest="valgrindArgs", |
| 103 | + metavar="ARG", |
| 104 | + help="Specify an extra argument for valgrind", |
| 105 | + type=str, |
| 106 | + action="append", |
| 107 | + default=[]) |
| 108 | + execution_group.add_argument("--time-tests", |
| 109 | + dest="timeTests", |
| 110 | + help="Track elapsed wall time for each test", |
| 111 | + action="store_true", |
| 112 | + default=False) |
| 113 | + execution_group.add_argument("--no-execute", |
| 114 | + dest="noExecute", |
| 115 | + help="Don't execute any tests (assume PASS)", |
| 116 | + action="store_true", |
| 117 | + default=False) |
| 118 | + execution_group.add_argument("--xunit-xml-output", |
| 119 | + dest="xunit_output_file", |
| 120 | + help="Write XUnit-compatible XML test reports to the specified file", |
| 121 | + default=None) |
| 122 | + execution_group.add_argument("--timeout", |
| 123 | + dest="maxIndividualTestTime", |
| 124 | + help="Maximum time to spend running a single test (in seconds). " |
| 125 | + "0 means no time limit. [Default: 0]", |
| 126 | + type=int, |
| 127 | + default=None) |
| 128 | + execution_group.add_argument("--max-failures", |
| 129 | + dest="maxFailures", |
| 130 | + help="Stop execution after the given number of failures.", |
| 131 | + action="store", |
| 132 | + type=int, |
| 133 | + default=None) |
| 134 | + |
| 135 | + selection_group = parser.add_argument_group("Test Selection") |
| 136 | + selection_group.add_argument("--max-tests", |
| 137 | + dest="maxTests", |
| 138 | + metavar="N", |
| 139 | + help="Maximum number of tests to run", |
| 140 | + action="store", |
| 141 | + type=int, |
| 142 | + default=None) |
| 143 | + selection_group.add_argument("--max-time", |
| 144 | + dest="maxTime", |
| 145 | + metavar="N", |
| 146 | + help="Maximum time to spend testing (in seconds)", |
| 147 | + action="store", |
| 148 | + type=float, |
| 149 | + default=None) |
| 150 | + selection_group.add_argument("--shuffle", |
| 151 | + help="Run tests in random order", |
| 152 | + action="store_true", |
| 153 | + default=False) |
| 154 | + selection_group.add_argument("-i", "--incremental", |
| 155 | + help="Run modified and failing tests first (updates mtimes)", |
| 156 | + action="store_true", |
| 157 | + default=False) |
| 158 | + selection_group.add_argument("--filter", |
| 159 | + metavar="REGEX", |
| 160 | + help="Only run tests with paths matching the given regular expression", |
| 161 | + action="store", |
| 162 | + default=os.environ.get("LIT_FILTER")) |
| 163 | + selection_group.add_argument("--num-shards", dest="numShards", metavar="M", |
| 164 | + help="Split testsuite into M pieces and only run one", |
| 165 | + action="store", |
| 166 | + type=int, |
| 167 | + default=os.environ.get("LIT_NUM_SHARDS")) |
| 168 | + selection_group.add_argument("--run-shard", |
| 169 | + dest="runShard", |
| 170 | + metavar="N", |
| 171 | + help="Run shard #N of the testsuite", |
| 172 | + action="store", |
| 173 | + type=int, |
| 174 | + default=os.environ.get("LIT_RUN_SHARD")) |
| 175 | + |
| 176 | + debug_group = parser.add_argument_group("Debug and Experimental Options") |
| 177 | + debug_group.add_argument("--debug", |
| 178 | + help="Enable debugging (for 'lit' development)", |
| 179 | + action="store_true", |
| 180 | + default=False) |
| 181 | + debug_group.add_argument("--show-suites", |
| 182 | + dest="showSuites", |
| 183 | + help="Show discovered test suites", |
| 184 | + action="store_true", |
| 185 | + default=False) |
| 186 | + debug_group.add_argument("--show-tests", |
| 187 | + dest="showTests", |
| 188 | + help="Show all discovered tests", |
| 189 | + action="store_true", |
| 190 | + default=False) |
| 191 | + |
| 192 | + opts = parser.parse_args(sys.argv[1:] + |
| 193 | + shlex.split(os.environ.get("LIT_OPTS", ""))) |
| 194 | + |
| 195 | + # Validate options |
| 196 | + if not opts.test_paths: |
| 197 | + parser.error('No inputs specified') |
| 198 | + |
| 199 | + if opts.numWorkers is None: |
| 200 | + opts.numWorkers = lit.util.detectCPUs() |
| 201 | + elif opts.numWorkers <= 0: |
| 202 | + parser.error("Option '--workers' or '-j' requires positive integer") |
| 203 | + |
| 204 | + if opts.maxFailures is not None and opts.maxFailures <= 0: |
| 205 | + parser.error("Option '--max-failures' requires positive integer") |
| 206 | + |
| 207 | + if opts.echoAllCommands: |
| 208 | + opts.showOutput = True |
| 209 | + |
| 210 | + if (opts.numShards is not None) or (opts.runShard is not None): |
| 211 | + if (opts.numShards is None) or (opts.runShard is None): |
| 212 | + parser.error("--num-shards and --run-shard must be used together") |
| 213 | + if opts.numShards <= 0: |
| 214 | + parser.error("--num-shards must be positive") |
| 215 | + if (opts.runShard < 1) or (opts.runShard > opts.numShards): |
| 216 | + parser.error("--run-shard must be between 1 and --num-shards (inclusive)") |
| 217 | + |
| 218 | + return opts |
0 commit comments