Skip to content

Turn on valgrind by a boolean variable #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The package requires testgres~=1.9.3.
| - | - | - | - |
| PGPROBACKUP_TMP_DIR | No | tests/tmp_dirs | The root of the temporary directory hierarchy where tests store data and logs. Relative paths start from the current working directory. |
| PG_PROBACKUP_TEST_BACKUP_DIR_PREFIX | No | Temporary test hierarchy | Prefix of the test backup directories. Must be an absolute path. Use this variable to store test backups in a location other than the temporary test hierarchy. |
| PG_PROBACKUP_VALGRIND | No | Not set | Run pg_probackup through valgrind if the variable is set to 'y'. Setting PG_PROBACKUP_VALGRIND_SUP (see below) to any value enables valgrind just like setting `PG_PROBACKUP_VALGRIND=y` would do. |
| PG_PROBACKUP_VALGRIND_SUP | No | Not set | Specify the path to a valgrind suppression file. If the variable is not set then a file named "valgrind.supp" is searched for in the current working directory (normally the root of pg_probackup repository). Setting PG_PROBACKUP_VALGRIND_SUP to any value enables valgrind just like setting `PG_PROBACKUP_VALGRIND=y` (see above) would do. |

See [Testgres](https://github.com/postgrespro/testgres/tree/master#environment) on how to configure a custom Postgres installation using `PG_CONFIG` and `PG_BIN` environment variables.

Expand Down
20 changes: 13 additions & 7 deletions pg_probackup2/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, test_class: unittest.TestCase,
self.archive_compress = init_params.archive_compress
self.test_class.output = None
self.execution_time = None
self.valgrind = init_params.valgrind
self.valgrind_sup_path = init_params.valgrind_sup_path

def form_daemon_process(self, cmdline, env):
Expand Down Expand Up @@ -157,11 +158,8 @@ def _add_options(self, command: list, skip_log_directory: bool):
def _form_cmdline(self, binary_path, command):
cmdline = [binary_path, *command]

if self.valgrind_sup_path and command[0] != "--version":
if (self.valgrind == 'y' or self.valgrind_sup_path) and command[0] != "--version":
os.makedirs(self.pb_log_path, exist_ok=True)
if self.valgrind_sup_path and not os.path.isfile(self.valgrind_sup_path):
raise FileNotFoundError(f"PG_PROBACKUP_VALGRIND_SUP should contain path to valgrind suppression file, "
f"but found: {self.valgrind_sup_path}")
valgrind_cmd = [
"valgrind",
"--gen-suppressions=all",
Expand All @@ -171,10 +169,18 @@ def _form_cmdline(self, binary_path, command):
"--show-leak-kinds=all",
"--errors-for-leak-kinds=all",
"--error-exitcode=0",
f"--log-file={os.path.join(self.pb_log_path, f'valgrind-{command[0]}-%p.log')}",
f"--suppressions={self.valgrind_sup_path}",
"--"
f"--log-file={os.path.join(self.pb_log_path, f'valgrind-{command[0]}-%p.log')}"
]
if self.valgrind_sup_path:
if os.path.isfile(self.valgrind_sup_path):
valgrind_cmd += [f"--suppressions={self.valgrind_sup_path}"]
else:
raise FileNotFoundError(f"PG_PROBACKUP_VALGRIND_SUP must be the path to a valgrind suppression file, "
f"but found: {self.valgrind_sup_path}")
else:
# Assume the tests are started from the root of pg_probackup repository
valgrind_cmd += [f"--suppressions=.valgrind.supp"]

cmdline = valgrind_cmd + cmdline

return cmdline
Expand Down
3 changes: 2 additions & 1 deletion pg_probackup2/init_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def __init__(self):
else:
raise Exception('Can\'t process pg_probackup version \"{}\": the major version is expected to be a number'.format(self.probackup_version))

self.valgrind_sup_path = test_env.get('PG_PROBACKUP_VALGRIND_SUP', None)
self.valgrind = test_env.get('PG_PROBACKUP_VALGRIND')
self.valgrind_sup_path = test_env.get('PG_PROBACKUP_VALGRIND_SUP')

def test_env(self):
return self._test_env.copy()
Expand Down