|
21 | 21 |
|
22 | 22 | """
|
23 | 23 |
|
| 24 | +import argparse |
24 | 25 | import configparser
|
25 | 26 | import os
|
26 | 27 | import time
|
|
30 | 31 | import tempfile
|
31 | 32 | import re
|
32 | 33 |
|
| 34 | +# Parse arguments and pass through unrecognised args |
| 35 | +parser = argparse.ArgumentParser(add_help=False) |
| 36 | +parser.add_argument('--coverage', action='store_true') |
| 37 | +parser.add_argument('-extended', action='store_true') |
| 38 | +parser.add_argument('--help', '-h', '-?', action='store_true') |
| 39 | +parser.add_argument('--parallel', type=int, default=4) |
| 40 | +parser.add_argument('-win', action='store_true') |
| 41 | +(args, unknown_args) = parser.parse_known_args() |
| 42 | + |
| 43 | +#Create a set to store arguments and create the passon string |
| 44 | +tests = set(arg for arg in unknown_args if arg[:2] != "--") |
| 45 | +passon_args = [arg for arg in unknown_args if arg[:2] == "--"] |
| 46 | + |
33 | 47 | BOLD = ("","")
|
34 | 48 | if os.name == 'posix':
|
35 | 49 | # primitive formatting on supported
|
|
47 | 61 |
|
48 | 62 | RPC_TESTS_DIR = config["environment"]["SRCDIR"] + '/qa/rpc-tests/'
|
49 | 63 |
|
50 |
| -ENABLE_COVERAGE=0 |
51 |
| - |
52 |
| -#Create a set to store arguments and create the passon string |
53 |
| -opts = set() |
54 |
| -passon_args = [] |
55 |
| -PASSON_REGEX = re.compile("^--") |
56 |
| -PARALLEL_REGEX = re.compile('^-parallel=') |
57 |
| - |
58 |
| -print_help = False |
59 |
| -run_parallel = 4 |
60 |
| - |
61 |
| -for arg in sys.argv[1:]: |
62 |
| - if arg == "--help" or arg == "-h" or arg == "-?": |
63 |
| - print_help = True |
64 |
| - break |
65 |
| - if arg == '--coverage': |
66 |
| - ENABLE_COVERAGE = 1 |
67 |
| - elif PASSON_REGEX.match(arg): |
68 |
| - passon_args.append(arg) |
69 |
| - elif PARALLEL_REGEX.match(arg): |
70 |
| - run_parallel = int(arg.split(sep='=', maxsplit=1)[1]) |
71 |
| - else: |
72 |
| - opts.add(arg) |
| 64 | +print_help = args.help |
| 65 | +run_parallel = args.parallel |
73 | 66 |
|
74 | 67 | #Set env vars
|
75 | 68 | if "BITCOIND" not in os.environ:
|
76 | 69 | os.environ["BITCOIND"] = config["environment"]["BUILDDIR"] + '/src/bitcoind' + config["environment"]["EXEEXT"]
|
77 | 70 |
|
78 |
| -if config["environment"]["EXEEXT"] == ".exe" and "-win" not in opts: |
| 71 | +if config["environment"]["EXEEXT"] == ".exe" and not args.win: |
79 | 72 | # https://github.com/bitcoin/bitcoin/commit/d52802551752140cf41f0d9a225a43e84404d3e9
|
80 | 73 | # https://github.com/bitcoin/bitcoin/pull/5677#issuecomment-136646964
|
81 | 74 | print("Win tests currently disabled by default. Use -win option to enable")
|
|
95 | 88 | # ENABLE_ZMQ=0
|
96 | 89 | raise
|
97 | 90 |
|
98 |
| -testScripts = [ |
| 91 | +BASE_SCRIPTS= [ |
99 | 92 | # longest test should go first, to favor running tests in parallel
|
100 | 93 | 'wallet-hd.py',
|
101 | 94 | 'walletbackup.py',
|
|
152 | 145 | 'rpcnamedargs.py',
|
153 | 146 | 'listsinceblock.py',
|
154 | 147 | ]
|
155 |
| -if ENABLE_ZMQ: |
156 |
| - testScripts.append('zmq_test.py') |
| 148 | +ZMQ_SCRIPTS = ["zmq_test.py"] |
157 | 149 |
|
158 |
| -testScriptsExt = [ |
| 150 | +EXTENDED_SCRIPTS = [ |
159 | 151 | 'pruning.py',
|
160 | 152 | # vv Tests less than 20m vv
|
161 | 153 | 'smartfees.py',
|
|
184 | 176 | 'replace-by-fee.py',
|
185 | 177 | ]
|
186 | 178 |
|
| 179 | +ALL_SCRIPTS = BASE_SCRIPTS + ZMQ_SCRIPTS + EXTENDED_SCRIPTS |
187 | 180 |
|
188 | 181 | def runtests():
|
189 |
| - test_list = [] |
190 |
| - if '-extended' in opts: |
191 |
| - test_list = testScripts + testScriptsExt |
192 |
| - elif len(opts) == 0 or (len(opts) == 1 and "-win" in opts): |
193 |
| - test_list = testScripts |
| 182 | + # Build list of tests |
| 183 | + if len(tests) != 0: |
| 184 | + # Individual tests have been specified. Run specified tests that exist |
| 185 | + # in the ALL_SCRIPTS list. Accept the name with or without .py extension. |
| 186 | + test_list = [t for t in ALL_SCRIPTS if |
| 187 | + (t in tests or re.sub(".py$", "", t) in tests)] |
| 188 | + if len(test_list) == 0: |
| 189 | + print("No valid test scripts specified. Check that your test is in one " |
| 190 | + "of the test lists in rpc-tests.py or run rpc-tests.py with no arguments to run all tests") |
| 191 | + sys.exit(0) |
194 | 192 | else:
|
195 |
| - for t in testScripts + testScriptsExt: |
196 |
| - if t in opts or re.sub(".py$", "", t) in opts: |
197 |
| - test_list.append(t) |
198 |
| - |
199 |
| - if print_help: |
| 193 | + # No individual tests have been specified. Run base tests, and |
| 194 | + # optionally ZMQ tests and extended tests. |
| 195 | + test_list = BASE_SCRIPTS |
| 196 | + if ENABLE_ZMQ: |
| 197 | + test_list += ZMQ_SCRIPTS |
| 198 | + if args.extended: |
| 199 | + test_list += EXTENDED_SCRIPTS |
| 200 | + # TODO: BASE_SCRIPTS and EXTENDED_SCRIPTS are sorted by runtime |
| 201 | + # (for parallel running efficiency). This combined list will is no |
| 202 | + # longer sorted. |
| 203 | + |
| 204 | + if args.help: |
200 | 205 | # Only print help of the first script and exit
|
201 | 206 | subprocess.check_call((RPC_TESTS_DIR + test_list[0]).split() + ['-h'])
|
202 | 207 | sys.exit(0)
|
203 | 208 |
|
204 | 209 | coverage = None
|
205 | 210 |
|
206 |
| - if ENABLE_COVERAGE: |
| 211 | + if args.coverage: |
207 | 212 | coverage = RPCCoverage()
|
208 | 213 | print("Initializing coverage directory at %s\n" % coverage.dir)
|
209 | 214 | flags = ["--srcdir=%s/src" % config["environment"]["BUILDDIR"]] + passon_args
|
|
0 commit comments