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 28eabc8
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions test/functional/test_framework/test_node.py
Expand Up @@ -34,7 +34,8 @@
)

BITCOIND_PROC_WAIT_TIMEOUT = 60

VALGRIND_VERSION_MAJOR = 3
VALGRIND_VERSION_MINOR = 14

class FailedToStartError(Exception):
"""Raised when a node fails to start correctly."""
Expand Down Expand Up @@ -97,15 +98,23 @@ def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cl
"-debugexclude=leveldb",
"-uacomment=testnode%d" % i,
]
valgrind_version = self.get_valgrind_version()
exit_on_first_error_flag = ""
if valgrind_version and valgrind_version >= (VALGRIND_VERSION_MAJOR,
VALGRIND_VERSION_MINOR):
exit_on_first_error_flag = "--exit-on-first-error=yes"
if use_valgrind:
default_suppressions_file = os.path.join(
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
self.args = ["valgrind",
"--suppressions={}".format(suppressions_file),
"--gen-suppressions=all",
exit_on_first_error_flag,
"--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,23 @@ def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cl
AddressKeyPair('mzRe8QZMfGi58KyWCse2exxEFry2sfF2Y7', 'cPiRWE8KMjTRxH1MWkPerhfoHFn5iHPWVK5aPqjW8NxmdwenFinJ'),
]

def get_valgrind_version(self):
"""Returns valgrind version (major, minor) in a tuple"""
try:
rc = subprocess.call(['which', 'valgrind'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if rc == 0:
version_regex = re.compile('[.bv]')
version_info = subprocess.run(["valgrind", "--version"],
stdout=subprocess.PIPE).stdout.decode("utf-8").rstrip().split("valgrind-")[1:][0]
version_array = re.split(version_regex, version_info)
return (int(version_array[0]), int(version_array[1]))
else:
return None
except:
return None

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 28eabc8

Please sign in to comment.