diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -33,7 +33,7 @@ sys.path.append("qa/pull-tester/") from tests_config import * -BOLD = ("","") +BOLD = ("", "") if os.name == 'posix': # primitive formatting on supported # terminal via ANSI escape sequences: @@ -41,19 +41,19 @@ RPC_TESTS_DIR = SRCDIR + '/qa/rpc-tests/' -#If imported values are not defined then set to zero (or disabled) +# If imported values are not defined then set to zero (or disabled) if 'ENABLE_WALLET' not in vars(): - ENABLE_WALLET=0 + ENABLE_WALLET = 0 if 'ENABLE_BITCOIND' not in vars(): - ENABLE_BITCOIND=0 + ENABLE_BITCOIND = 0 if 'ENABLE_UTILS' not in vars(): - ENABLE_UTILS=0 + ENABLE_UTILS = 0 if 'ENABLE_ZMQ' not in vars(): - ENABLE_ZMQ=0 + ENABLE_ZMQ = 0 -ENABLE_COVERAGE=0 +ENABLE_COVERAGE = 0 -#Create a set to store arguments and create the passon string +# Create a set to store arguments and create the passon string opts = set() passon_args = [] PASSON_REGEX = re.compile("^--") @@ -75,21 +75,24 @@ else: opts.add(arg) -#Set env vars +# Set env vars if "BITCOIND" not in os.environ: os.environ["BITCOIND"] = BUILDDIR + '/src/bitcoind' + EXEEXT if EXEEXT == ".exe" and "-win" not in opts: # https://github.com/bitcoin/bitcoin/commit/d52802551752140cf41f0d9a225a43e84404d3e9 # https://github.com/bitcoin/bitcoin/pull/5677#issuecomment-136646964 - print("Win tests currently disabled by default. Use -win option to enable") + print( + "Win tests currently disabled by default. Use -win option to enable") sys.exit(0) if not (ENABLE_WALLET == 1 and ENABLE_UTILS == 1 and ENABLE_BITCOIND == 1): - print("No rpc tests to run. Wallet, utils, and bitcoind must all be enabled") + print( + "No rpc tests to run. Wallet, utils, and bitcoind must all be enabled") sys.exit(0) -# python3-zmq may not be installed. Handle this gracefully and with some helpful info +# python3-zmq may not be installed. Handle this gracefully and with some +# helpful info if ENABLE_ZMQ: try: import zmq @@ -221,12 +224,13 @@ # Populate cache subprocess.check_output([RPC_TESTS_DIR + 'create_cache.py'] + flags) - #Run Tests + # Run Tests 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] + 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() @@ -236,9 +240,12 @@ print('\n' + BOLD[1] + name + BOLD[0] + ":") print('' if passed else stdout + '\n', end='') print('' if stderr == '' else 'stderr:\n' + stderr + '\n', end='') - 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] + 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))) @@ -252,6 +259,7 @@ class RPCTestHandler: + """ Trigger the testscrips passed in via the list. """ @@ -273,12 +281,15 @@ # Add tests self.num_running += 1 t = self.test_list.pop(0) - port_seed = ["--portseed={}".format(len(self.test_list) + self.portseed_offset)] + port_seed = ["--portseed={}".format( + len(self.test_list) + self.portseed_offset)] log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16) log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16) self.jobs.append((t, time.time(), - subprocess.Popen((RPC_TESTS_DIR + t).split() + self.flags + port_seed, + subprocess.Popen( + (RPC_TESTS_DIR + t).split() + + self.flags + port_seed, universal_newlines=True, stdout=log_stdout, stderr=log_stderr), @@ -293,7 +304,8 @@ (name, time0, proc, log_out, log_err) = j if proc.poll() is not None: log_out.seek(0), log_err.seek(0) - [stdout, stderr] = [l.read().decode('utf-8') for l in (log_out, log_err)] + [stdout, stderr] = [l.read().decode('utf-8') + for l in (log_out, log_err)] log_out.close(), log_err.close() passed = stderr == "" and proc.returncode == 0 self.num_running -= 1 @@ -303,6 +315,7 @@ class RPCCoverage(object): + """ Coverage reporting utilities for pull-tester. @@ -317,6 +330,7 @@ See also: qa/rpc-tests/test_framework/coverage.py """ + def __init__(self): self.dir = tempfile.mkdtemp(prefix="coverage") self.flag = '--coveragedir=%s' % self.dir