Skip to content

Commit 5db506b

Browse files
tests: Add option --valgrind to run nodes under valgrind in the functional tests
1 parent 19698ac commit 5db506b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def parse_args(self):
157157
help="use bitcoin-cli instead of RPC for all commands")
158158
parser.add_argument("--perf", dest="perf", default=False, action="store_true",
159159
help="profile running nodes with perf for the duration of the test")
160+
parser.add_argument("--valgrind", dest="valgrind", default=False, action="store_true",
161+
help="run nodes under the valgrind memory error detector: expect at least a ~10x slowdown, valgrind 3.14 or later required")
160162
parser.add_argument("--randomseed", type=int,
161163
help="set a random seed for deterministically reproducing a previous test run")
162164
self.add_options(parser)
@@ -394,6 +396,7 @@ def add_nodes(self, num_nodes, extra_args=None, *, rpchost=None, binary=None):
394396
extra_args=extra_args[i],
395397
use_cli=self.options.usecli,
396398
start_perf=self.options.perf,
399+
use_valgrind=self.options.valgrind,
397400
))
398401

399402
def start_node(self, i, *args, **kwargs):

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class TestNode():
5959
To make things easier for the test writer, any unrecognised messages will
6060
be dispatched to the RPC connection."""
6161

62-
def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False):
62+
def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False):
6363
"""
6464
Kwargs:
6565
start_perf (bool): If True, begin profiling the node with `perf` as soon as
@@ -96,6 +96,15 @@ def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cl
9696
"-debugexclude=leveldb",
9797
"-uacomment=testnode%d" % i,
9898
]
99+
if use_valgrind:
100+
default_suppressions_file = os.path.join(
101+
os.path.dirname(os.path.realpath(__file__)),
102+
"..", "..", "..", "contrib", "valgrind.supp")
103+
suppressions_file = os.getenv("VALGRIND_SUPPRESSIONS_FILE",
104+
default_suppressions_file)
105+
self.args = ["valgrind", "--suppressions={}".format(suppressions_file),
106+
"--gen-suppressions=all", "--exit-on-first-error=yes",
107+
"--error-exitcode=1", "--quiet"] + self.args
99108

100109
self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
101110
self.use_cli = use_cli

0 commit comments

Comments
 (0)