aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2016-04-29 12:51:15 +0200
committerMarcoFalke <falke.marco@gmail.com>2016-05-09 19:56:16 +0200
commitfa494dec79b9d469b7eb38d2f0b8cf9832cdc398 (patch)
tree351e0224a788a8f1c3ec201675029edc96b25f83
parent4e14afe42fdd468d5de11df8cc13defdcb8e83f8 (diff)
downloadbitcoin-fa494dec79b9d469b7eb38d2f0b8cf9832cdc398.tar.xz
[qa] pull-tester: Run rpc test in parallel
-rw-r--r--qa/README.md3
-rwxr-xr-xqa/pull-tester/rpc-tests.py92
-rwxr-xr-xqa/rpc-tests/create_cache.py23
3 files changed, 105 insertions, 13 deletions
diff --git a/qa/README.md b/qa/README.md
index c7e574ff70..7489eb5130 100644
--- a/qa/README.md
+++ b/qa/README.md
@@ -35,6 +35,9 @@ Run all possible tests with
qa/pull-tester/rpc-tests.py -extended
+By default, tests will be run in parallel if you want to specify how many
+tests should be run in parallel, append `-paralell=n` (default n=4).
+
If you want to create a basic coverage report for the rpc test suite, append `--coverage`.
Possible options, which apply to each individual test run:
diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py
index 10c3799b86..f926398d58 100755
--- a/qa/pull-tester/rpc-tests.py
+++ b/qa/pull-tester/rpc-tests.py
@@ -53,10 +53,12 @@ ENABLE_COVERAGE=0
#Create a set to store arguments and create the passon string
opts = set()
-passon_args = ""
+passon_args = []
PASSON_REGEX = re.compile("^--")
+PARALLEL_REGEX = re.compile('^-parallel=')
print_help = False
+run_parallel = 4
for arg in sys.argv[1:]:
if arg == "--help" or arg == "-h" or arg == "-?":
@@ -65,7 +67,9 @@ for arg in sys.argv[1:]:
if arg == '--coverage':
ENABLE_COVERAGE = 1
elif PASSON_REGEX.match(arg):
- passon_args += " " + arg
+ passon_args.append(arg)
+ elif PARALLEL_REGEX.match(arg):
+ run_parallel = int(arg.split(sep='=', maxsplit=1)[1])
else:
opts.add(arg)
@@ -96,6 +100,7 @@ if ENABLE_ZMQ:
#Tests
testScripts = [
+ 'walletbackup.py',
'bip68-112-113-p2p.py',
'wallet.py',
'listtransactions.py',
@@ -116,7 +121,6 @@ testScripts = [
'merkle_blocks.py',
'fundrawtransaction.py',
'signrawtransactions.py',
- 'walletbackup.py',
'nodehandling.py',
'reindex.py',
'decodescript.py',
@@ -131,7 +135,7 @@ testScripts = [
'abandonconflict.py',
'p2p-versionbits-warning.py',
'importprunedfunds.py',
- 'signmessages.py'
+ 'signmessages.py',
]
if ENABLE_ZMQ:
testScripts.append('zmq_test.py')
@@ -160,6 +164,7 @@ testScriptsExt = [
'pruning.py', # leave pruning last as it takes a REALLY long time
]
+
def runtests():
test_list = []
if '-extended' in opts:
@@ -173,7 +178,7 @@ def runtests():
if print_help:
# Only print help of the first script and exit
- subprocess.check_call(RPC_TESTS_DIR + test_list[0] + ' -h', shell=True)
+ subprocess.check_call((RPC_TESTS_DIR + test_list[0]).split() + ['-h'])
sys.exit(0)
coverage = None
@@ -181,15 +186,34 @@ def runtests():
if ENABLE_COVERAGE:
coverage = RPCCoverage()
print("Initializing coverage directory at %s\n" % coverage.dir)
- flags = " --srcdir %s/src %s %s" % (BUILDDIR, coverage.flag if coverage else '', passon_args)
+ flags = ["--srcdir=%s/src" % BUILDDIR] + passon_args
+ if coverage:
+ flags.append(coverage.flag)
+
+ if len(test_list) > 1:
+ # Populate cache
+ subprocess.check_output([RPC_TESTS_DIR + 'create_cache.py'] + flags)
#Run Tests
- for t in test_list:
- print("Running testscript %s%s%s ..." % (BOLD[1], t, BOLD[0]))
- time0 = time.time()
- subprocess.check_call(
- RPC_TESTS_DIR + t + flags, shell=True)
- print("Duration: %s s\n" % (int(time.time() - time0)))
+ max_len_name = len(max(test_list, key=len))
+ time_sum = 0
+ time0 = time.time()
+ job_queue = RPCTestHandler(run_parallel, test_list, flags)
+ results = BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), "PASSED", "DURATION") + BOLD[0]
+ all_passed = True
+ for _ in range(len(test_list)):
+ (name, stdout, stderr, passed, duration) = job_queue.get_next()
+ all_passed = all_passed and passed
+ time_sum += duration
+
+ print('\n' + BOLD[1] + name + BOLD[0] + ":")
+ print(stdout)
+ print('stderr:\n' if not stderr == '' else '', stderr)
+ results += "%s | %s | %s s\n" % (name.ljust(max_len_name), str(passed).ljust(6), duration)
+ print("Pass: %s%s%s, Duration: %s s\n" % (BOLD[1], passed, BOLD[0], duration))
+ results += BOLD[1] + "\n%s | %s | %s s (accumulated)" % ("ALL".ljust(max_len_name), str(all_passed).ljust(6), time_sum) + BOLD[0]
+ print(results)
+ print("\nRuntime: %s s" % (int(time.time() - time0)))
if coverage:
coverage.report_rpc_coverage()
@@ -197,6 +221,48 @@ def runtests():
print("Cleaning up coverage data")
coverage.cleanup()
+ sys.exit(not all_passed)
+
+
+class RPCTestHandler:
+ """
+ Trigger the testscrips passed in via the list.
+ """
+
+ def __init__(self, num_tests_parallel, test_list=None, flags=None):
+ assert(num_tests_parallel >= 1)
+ self.num_jobs = num_tests_parallel
+ self.test_list = test_list
+ self.flags = flags
+ self.num_running = 0
+ self.jobs = []
+
+ def get_next(self):
+ while self.num_running < self.num_jobs and self.test_list:
+ # Add tests
+ self.num_running += 1
+ t = self.test_list.pop(0)
+ self.jobs.append((t,
+ time.time(),
+ subprocess.Popen((RPC_TESTS_DIR + t).split() + self.flags,
+ universal_newlines=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)))
+ if not self.jobs:
+ raise IndexError('%s from empty list' % __name__)
+ while True:
+ # Return first proc that finishes
+ time.sleep(.5)
+ for j in self.jobs:
+ (name, time0, proc) = j
+ if proc.poll() is not None:
+ (stdout, stderr) = proc.communicate(timeout=3)
+ passed = stderr == "" and proc.returncode == 0
+ self.num_running -= 1
+ self.jobs.remove(j)
+ return name, stdout, stderr, passed, int(time.time() - time0)
+ print('.', end='', flush=True)
+
class RPCCoverage(object):
"""
@@ -215,7 +281,7 @@ class RPCCoverage(object):
"""
def __init__(self):
self.dir = tempfile.mkdtemp(prefix="coverage")
- self.flag = '--coveragedir %s' % self.dir
+ self.flag = '--coveragedir=%s' % self.dir
def report_rpc_coverage(self):
"""
diff --git a/qa/rpc-tests/create_cache.py b/qa/rpc-tests/create_cache.py
new file mode 100755
index 0000000000..b6161e0917
--- /dev/null
+++ b/qa/rpc-tests/create_cache.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+# Copyright (c) 2016 The Bitcoin Core developers
+# Distributed under the MIT software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#
+# Helper script to create the cache
+# (see BitcoinTestFramework.setup_chain)
+#
+
+from test_framework.test_framework import BitcoinTestFramework
+
+class CreateCache(BitcoinTestFramework):
+
+ def setup_network(self):
+ # Don't setup any test nodes
+ self.options.noshutdown = True
+
+ def run_test(self):
+ pass
+
+if __name__ == '__main__':
+ CreateCache().main()