Skip to content

Commit

Permalink
test: check for valgrind presence and set appropriate exit flags
Browse files Browse the repository at this point in the history
  • Loading branch information
brakmic committed Dec 12, 2019
1 parent 3914e87 commit 9a61f78
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions test/functional/test_framework/test_node.py
Expand Up @@ -19,6 +19,7 @@
import urllib.parse
import collections
import shlex
import shutil
import sys

from .authproxy import JSONRPCException
Expand All @@ -34,7 +35,7 @@
)

BITCOIND_PROC_WAIT_TIMEOUT = 60

MIN_VALGRIND_VERSION_EARLY_EXIT = (3, 14)

class FailedToStartError(Exception):
"""Raised when a node fails to start correctly."""
Expand Down Expand Up @@ -98,14 +99,22 @@ def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cl
"-uacomment=testnode%d" % i,
]
if use_valgrind:
valgrind_version = self.get_valgrind_version()
if not valgrind_version:
raise Exception('Valgrind not present')
default_suppressions_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"..", "..", "..", "contrib", "valgrind.supp")
os.path.dirname(os.path.realpath(__file__)),
"..", "..", "..", "contrib", "valgrind.supp")
suppressions_file = os.getenv("VALGRIND_SUPPRESSIONS_FILE",
default_suppressions_file)
self.args = ["valgrind", "--suppressions={}".format(suppressions_file),
"--gen-suppressions=all", "--exit-on-first-error=yes",
"--error-exitcode=1", "--quiet"] + self.args
default_suppressions_file)
self.args = [
"valgrind",
"--suppressions={}".format(suppressions_file),
"--gen-suppressions=all",
self.valgrind_early_exit(valgrind_version),
"--error-exitcode=1",
"--quiet"
] + self.args

self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
self.use_cli = use_cli
Expand Down Expand Up @@ -140,6 +149,20 @@ def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cl
AddressKeyPair('mzRe8QZMfGi58KyWCse2exxEFry2sfF2Y7', 'cPiRWE8KMjTRxH1MWkPerhfoHFn5iHPWVK5aPqjW8NxmdwenFinJ'),
]

def get_valgrind_version(self):
"""Return valgrind version (major, minor) in a tuple or None if not found"""
if not shutil.which("valgrind"):
return None
version = (
subprocess.run(["valgrind", "--version"], stdout=subprocess.PIPE)
.stdout.decode("utf-8")
.rstrip()
.split("valgrind-")[1:][0])
return tuple(int(i) for i in version.split(".")[:2])

def valgrind_early_exit(self, version):
return "--exit-on-first-error=yes" if version >= MIN_VALGRIND_VERSION_EARLY_EXIT else ""

def get_deterministic_priv_key(self):
"""Return a deterministic priv key in base58, that only depends on the node's index"""
assert len(self.PRIV_KEYS) == MAX_NODES
Expand Down

0 comments on commit 9a61f78

Please sign in to comment.