Skip to content

Commit ca20923

Browse files
author
MarcoFalke
committed
Merge #10053: [test] Allow functional test cases to be skipped
0c1ade6 Skip rpcbind_test if OS/network requirements are not met. (John Newbery) 232b666 Allow test cases to be skipped (John Newbery) Tree-SHA512: d90c956ba6e27e53f422cba6267bdcc60faef9370a7e66b7f6480137f84d9a813442ac477b20fbbc540be2b4636928be910c46e221570ab3b9a5b9f0f11f7fc8
2 parents a230b05 + 0c1ade6 commit ca20923

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

test/functional/rpcbind_test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test running bitcoind with the -rpcbind and -rpcallowip options."""
66

7+
import socket
8+
import sys
9+
710
from test_framework.test_framework import BitcoinTestFramework
811
from test_framework.util import *
912
from test_framework.netutil import *
@@ -52,15 +55,26 @@ def run_allowip_test(self, allow_ips, rpchost, rpcport):
5255

5356
def run_test(self):
5457
# due to OS-specific network stats queries, this test works only on Linux
55-
assert(sys.platform.startswith('linux'))
58+
if not sys.platform.startswith('linux'):
59+
self.log.warning("This test can only be run on linux. Skipping test.")
60+
sys.exit(self.TEST_EXIT_SKIPPED)
5661
# find the first non-loopback interface for testing
5762
non_loopback_ip = None
5863
for name,ip in all_interfaces():
5964
if ip != '127.0.0.1':
6065
non_loopback_ip = ip
6166
break
6267
if non_loopback_ip is None:
63-
assert(not 'This test requires at least one non-loopback IPv4 interface')
68+
self.log.warning("This test requires at least one non-loopback IPv4 interface. Skipping test.")
69+
sys.exit(self.TEST_EXIT_SKIPPED)
70+
try:
71+
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
72+
s.connect(("::1",1))
73+
s.close
74+
except OSError:
75+
self.log.warning("This test requires IPv6 support. Skipping test.")
76+
sys.exit(self.TEST_EXIT_SKIPPED)
77+
6478
self.log.info("Using interface %s for testing" % non_loopback_ip)
6579

6680
defaultport = rpc_port(0)

test/functional/test_framework/test_framework.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
)
2828
from .authproxy import JSONRPCException
2929

30-
3130
class BitcoinTestFramework(object):
3231

32+
TEST_EXIT_PASSED = 0
33+
TEST_EXIT_FAILED = 1
34+
TEST_EXIT_SKIPPED = 77
35+
3336
def __init__(self):
3437
self.num_nodes = 4
3538
self.setup_clean_chain = False
@@ -182,11 +185,11 @@ def main(self):
182185
print("".join(deque(open(f), MAX_LINES_TO_PRINT)))
183186
if success:
184187
self.log.info("Tests successful")
185-
sys.exit(0)
188+
sys.exit(self.TEST_EXIT_PASSED)
186189
else:
187190
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
188191
logging.shutdown()
189-
sys.exit(1)
192+
sys.exit(self.TEST_EXIT_FAILED)
190193

191194
def _start_logging(self):
192195
# Add logger and logging handlers

test/functional/test_runner.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import tempfile
2525
import re
2626

27+
TEST_EXIT_PASSED = 0
28+
TEST_EXIT_SKIPPED = 77
29+
2730
BASE_SCRIPTS= [
2831
# Scripts that are run by the travis build process.
2932
# Longest test should go first, to favor running tests in parallel
@@ -245,20 +248,20 @@ def run_tests(test_list, src_dir, build_dir, exeext, jobs=1, enable_coverage=Fal
245248
job_queue = TestHandler(jobs, tests_dir, test_list, flags)
246249

247250
max_len_name = len(max(test_list, key=len))
248-
results = BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), "PASSED", "DURATION") + BOLD[0]
251+
results = BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), "STATUS ", "DURATION") + BOLD[0]
249252
for _ in range(len(test_list)):
250-
(name, stdout, stderr, passed, duration) = job_queue.get_next()
251-
all_passed = all_passed and passed
253+
(name, stdout, stderr, status, duration) = job_queue.get_next()
254+
all_passed = all_passed and status != "Failed"
252255
time_sum += duration
253256

254257
print('\n' + BOLD[1] + name + BOLD[0] + ":")
255-
print('' if passed else stdout + '\n', end='')
258+
print('' if status == "Passed" else stdout + '\n', end='')
256259
print('' if stderr == '' else 'stderr:\n' + stderr + '\n', end='')
257-
print("Pass: %s%s%s, Duration: %s s\n" % (BOLD[1], passed, BOLD[0], duration))
260+
print("Status: %s%s%s, Duration: %s s\n" % (BOLD[1], status, BOLD[0], duration))
258261

259-
results += "%s | %s | %s s\n" % (name.ljust(max_len_name), str(passed).ljust(6), duration)
262+
results += "%s | %s | %s s\n" % (name.ljust(max_len_name), status.ljust(7), duration)
260263

261-
results += BOLD[1] + "\n%s | %s | %s s (accumulated)" % ("ALL".ljust(max_len_name), str(all_passed).ljust(6), time_sum) + BOLD[0]
264+
results += BOLD[1] + "\n%s | %s | %s s (accumulated)" % ("ALL".ljust(max_len_name), str(all_passed).ljust(7), time_sum) + BOLD[0]
262265
print(results)
263266
print("\nRuntime: %s s" % (int(time.time() - time0)))
264267

@@ -315,10 +318,15 @@ def get_next(self):
315318
log_out.seek(0), log_err.seek(0)
316319
[stdout, stderr] = [l.read().decode('utf-8') for l in (log_out, log_err)]
317320
log_out.close(), log_err.close()
318-
passed = stderr == "" and proc.returncode == 0
321+
if proc.returncode == TEST_EXIT_PASSED and stderr == "":
322+
status = "Passed"
323+
elif proc.returncode == TEST_EXIT_SKIPPED:
324+
status = "Skipped"
325+
else:
326+
status = "Failed"
319327
self.num_running -= 1
320328
self.jobs.remove(j)
321-
return name, stdout, stderr, passed, int(time.time() - time0)
329+
return name, stdout, stderr, status, int(time.time() - time0)
322330
print('.', end='', flush=True)
323331

324332

0 commit comments

Comments
 (0)