test: Fix broken --valgrind handling after bitcoin wrapper

Prior to this commit, tool_bitcoin.py was failing:

```sh
$ ./bld-cmake/test/functional/tool_bitcoin.py --valgrind
TestFramework (ERROR): Unexpected exception
Traceback (most recent call last):
  File "./test/functional/test_framework/test_framework.py", line 138, in main
    self.setup()
    ~~~~~~~~~~^^
  File "./test/functional/test_framework/test_framework.py", line 269, in setup
    self.setup_network()
    ~~~~~~~~~~~~~~~~~~^^
  File "./test/functional/tool_bitcoin.py", line 38, in setup_network
    assert all(node.args[:len(node_argv)] == node_argv for node in self.nodes)
           ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
```

This commit fixes this issue by running `bitcoin` under valgrind. Also,
it comes with other improvements:

* Drop the outdated valgrind 3.14 requirement, because there is no
  distro that ships a version that old anymore.
* Drop the VALGRIND_SUPPRESSIONS_FILE env var handling, because it was
  presumably never used since it was introduced. Also, the use-case
  seems limited.

Review note:

The set_cmd_args was ignoring the --valgrind test option.

In theory, this could be fixed by refactoring Binaries::node_argv() to
be used here. However, for now, just re-implement the node_argv logic in
set_cmd_args to prepend the valgrind cmd.
This commit is contained in:
MarcoFalke
2026-02-17 21:32:17 +01:00
parent a7c29df0e5
commit fa03fbf7e3
4 changed files with 47 additions and 20 deletions

View File

@@ -248,9 +248,18 @@ class Binaries:
binaries, which takes precedence over the paths above, if specified.
This is used by tests calling binaries from previous releases.
"""
def __init__(self, paths, bin_dir):
def __init__(self, paths, bin_dir, *, use_valgrind=False):
self.paths = paths
self.bin_dir = bin_dir
suppressions_file = pathlib.Path(__file__).parents[3] / "contrib" / "valgrind.supp"
self.valgrind_cmd = [
"valgrind",
f"--suppressions={suppressions_file}",
"--gen-suppressions=all",
"--exit-on-first-error=yes",
"--error-exitcode=1",
"--quiet",
] if use_valgrind else []
def node_argv(self, **kwargs):
"Return argv array that should be used to invoke bitcoind"
@@ -282,20 +291,26 @@ class Binaries:
return self._argv("chainstate", self.paths.bitcoinchainstate)
def _argv(self, command, bin_path, need_ipc=False):
"""Return argv array that should be used to invoke the command. It
either uses the bitcoin wrapper executable (if BITCOIN_CMD is set or
"""Return argv array that should be used to invoke the command.
It either uses the bitcoin wrapper executable (if BITCOIN_CMD is set or
need_ipc is True), or the direct binary path (bitcoind, etc). When
bin_dir is set (by tests calling binaries from previous releases) it
always uses the direct path."""
always uses the direct path.
The returned args include valgrind, except when bin_dir is set
(previous releases). Also, valgrind will only apply to the bitcoin
wrapper executable directly, not to the commands that `bitcoin` calls.
"""
if self.bin_dir is not None:
return [os.path.join(self.bin_dir, os.path.basename(bin_path))]
elif self.paths.bitcoin_cmd is not None or need_ipc:
# If the current test needs IPC functionality, use the bitcoin
# wrapper binary and append -m so it calls multiprocess binaries.
bitcoin_cmd = self.paths.bitcoin_cmd or [self.paths.bitcoin_bin]
return bitcoin_cmd + (["-m"] if need_ipc else []) + [command]
return self.valgrind_cmd + bitcoin_cmd + (["-m"] if need_ipc else []) + [command]
else:
return [bin_path]
return self.valgrind_cmd + [bin_path]
def get_binary_paths(config):