7 Run Regression Test Suite 9 This module calls down into individual test cases via subprocess. It will 10 forward all unrecognized arguments onto the individual test scripts, other 13 - `-extended`: run the "extended" test suite in addition to the basic one. 14 - `-win`: signal that this is running in a Windows environment, and we 16 - `--coverage`: this generates a basic coverage report for the RPC 19 For a description of arguments recognized by test scripts, see 20 `qa/pull-tester/test_framework/test_framework.py:BitcoinTestFramework.main`. 32 from tests_config
import *
35 if 'ENABLE_WALLET' not in vars():
37 if 'ENABLE_BITCOIND' not in vars():
39 if 'ENABLE_UTILS' not in vars():
41 if 'ENABLE_ZMQ' not in vars():
52 if (os.name ==
'posix'):
53 bold = (
'\033[0m',
'\033[1m')
55 for arg
in sys.argv[1:]:
56 if arg ==
'--coverage':
58 elif (p.match(arg)
or arg ==
"-h"):
65 if "DASHD" not in os.environ:
66 os.environ[
"DASHD"] = buildDir +
'/src/dashd' + EXEEXT
67 if "DASHCLI" not in os.environ:
68 os.environ[
"DASHCLI"] = buildDir +
'/src/dash-cli' + EXEEXT
70 if EXEEXT ==
".exe" and "-win" not in opts:
73 print "Win tests currently disabled by default. Use -win option to enable" 76 if not (ENABLE_WALLET == 1
and ENABLE_UTILS == 1
and ENABLE_BITCOIND == 1):
77 print "No rpc tests to run. Wallet, utils, and bitcoind must all be enabled" 84 except ImportError
as e:
85 print(
"ERROR: \"import zmq\" failed. Set ENABLE_ZMQ=0 or " \
86 "to run zmq tests, see dependency info in /qa/README.md.")
91 'bip68-112-113-p2p.py',
94 'listtransactions.py',
96 'mempool_resurrect_test.py',
97 'txn_doublespend.py --mineblock',
100 'rawtransactions.py',
102 'mempool_spendcoinbase.py',
110 'fundrawtransaction.py',
111 'fundrawtransaction-hd.py',
112 'signrawtransactions.py',
120 'p2p-fullblocktest.py',
126 'prioritise_transaction.py',
127 'invalidblockrequest.py',
128 'invalidtxrequest.py',
129 'abandonconflict.py',
130 'p2p-versionbits-warning.py',
133 testScripts.append(
'zmq_test.py')
142 'getblocktemplate_longpoll.py',
143 'getblocktemplate_proposals.py',
144 'txn_doublespend.py',
145 'txn_clone.py --mineblock',
148 'invalidateblock.py',
151 'maxblocksinflight.py',
152 'p2p-acceptblock.py',
153 'mempool_packages.py',
154 'maxuploadtarget.py',
163 print(
"Initializing coverage directory at %s\n" % coverage.dir)
165 rpcTestDir = buildDir +
'/qa/rpc-tests/' 166 run_extended =
'-extended' in opts
167 cov_flag = coverage.flag
if coverage
else '' 168 flags =
" --srcdir %s/src %s %s" % (buildDir, cov_flag, passOn)
171 for i
in range(len(testScripts)):
173 or (len(opts) == 1
and "-win" in opts )
175 or testScripts[i]
in opts
176 or re.sub(
".py$",
"", testScripts[i])
in opts ):
178 print(
"Running testscript %s%s%s ..." % (bold[1], testScripts[i], bold[0]))
180 subprocess.check_call(
181 rpcTestDir + testScripts[i] + flags, shell=
True)
182 print(
"Duration: %s s\n" % (int(time.time() - time0)))
186 p = re.compile(
" -h| --help")
191 for i
in range(len(testScriptsExt)):
192 if (run_extended
or testScriptsExt[i]
in opts
193 or re.sub(
".py$",
"", testScriptsExt[i])
in opts):
196 "Running 2nd level testscript " 197 +
"%s%s%s ..." % (bold[1], testScriptsExt[i], bold[0]))
199 subprocess.check_call(
200 rpcTestDir + testScriptsExt[i] + flags, shell=
True)
201 print(
"Duration: %s s\n" % (int(time.time() - time0)))
204 coverage.report_rpc_coverage()
206 print(
"Cleaning up coverage data")
212 Coverage reporting utilities for pull-tester. 214 Coverage calculation works by having each test script subprocess write 215 coverage files into a particular directory. These files contain the RPC 216 commands invoked during testing, as well as a complete listing of RPC 217 commands per `bitcoin-cli help` (`rpc_interface.txt`). 219 After all tests complete, the commands run are combined and diff'd against 220 the complete list to calculate uncovered RPC commands. 222 See also: qa/rpc-tests/test_framework/coverage.py 226 self.
dir = tempfile.mkdtemp(prefix=
"coverage")
231 Print out RPC commands that were unexercised by tests. 237 print(
"Uncovered RPC commands:")
238 print(
"".join((
" - %s\n" % i)
for i
in sorted(uncovered)))
240 print(
"All RPC commands covered.")
243 return shutil.rmtree(self.
dir)
247 Return a set of currently untested RPC commands. 251 REFERENCE_FILENAME =
'rpc_interface.txt' 252 COVERAGE_FILE_PREFIX =
'coverage.' 254 coverage_ref_filename = os.path.join(self.
dir, REFERENCE_FILENAME)
255 coverage_filenames = set()
259 if not os.path.isfile(coverage_ref_filename):
260 raise RuntimeError(
"No coverage reference found")
262 with open(coverage_ref_filename,
'r') as f: 263 all_cmds.update([i.strip() for i
in f.readlines()])
265 for root, dirs, files
in os.walk(self.
dir):
266 for filename
in files:
267 if filename.startswith(COVERAGE_FILE_PREFIX):
268 coverage_filenames.add(os.path.join(root, filename))
270 for filename
in coverage_filenames:
271 with open(filename,
'r') as f: 272 covered_cmds.update([i.strip() for i
in f.readlines()])
274 return all_cmds - covered_cmds
277 if __name__ ==
'__main__':
def report_rpc_coverage(self)
def _get_uncovered_rpc_commands(self)