Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add ability to run pg_probackup using valgrind#263

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
demonolock merged 1 commit intomasterfromadd-valgrind
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
87 changes: 65 additions & 22 deletionstestgres/plugins/pg_probackup2/pg_probackup2/app.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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_sup_path = init_params.valgrind_sup_path

def form_daemon_process(self, cmdline, env):
def stream_output(stream: subprocess.PIPE) -> None:
Expand DownExpand Up@@ -88,6 +89,7 @@ def stream_output(stream: subprocess.PIPE) -> None:

return self.process.pid

# ---- Start run function ---- #
def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Я перестала понимать что происходит в run, поэтому немного попилила

skip_log_directory=False, expect_error=False, use_backup_dir=True, daemonize=False):
"""
Expand All@@ -98,53 +100,93 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
gdb: when True it returns GDBObj(), when tuple('suspend', port) it runs probackup
in suspended gdb mode with attachable gdb port, for local debugging
"""
command = self._add_backup_dir_to_cmd(command, use_backup_dir)
# Old bin or regular one
binary_path = self._get_binary_path(old_binary)

if not env:
env = self.test_env
# Add additional options if needed
command, strcommand = self._add_options(command, skip_log_directory)

self.test_class.cmd = f"{binary_path} {strcommand}"
if self.verbose:
print(self.test_class.cmd)

cmdline = self._form_cmdline(binary_path, command)

if gdb is True:
# general test flow for using GDBObj
return GDBobj(cmdline, self.test_class)

return self._execute_command(cmdline, env, command, gdb, expect_error, return_id, daemonize)

def _add_backup_dir_to_cmd(self, command: list, use_backup_dir: TestBackupDir):
if isinstance(use_backup_dir, TestBackupDir):
command = [command[0], *use_backup_dir.pb_args, *command[1:]]
return [command[0], *use_backup_dir.pb_args, *command[1:]]
elif use_backup_dir:
command = [command[0], *self.backup_dir.pb_args, *command[1:]]
return [command[0], *self.backup_dir.pb_args, *command[1:]]
else:
command = [command[0], *self.backup_dir.pb_args[2:], *command[1:]]

if not self.probackup_old_path and old_binary:
logging.error('PGPROBACKUPBIN_OLD is not set')
exit(1)
return [command[0], *self.backup_dir.pb_args[2:], *command[1:]]

def _get_binary_path(self, old_binary):
if old_binary:
binary_path = self.probackup_old_path
else:
binary_path = self.probackup_path

if not env:
env = self.test_env
if not self.probackup_old_path:
logging.error('PGPROBACKUPBIN_OLD is not set')
exit(1)
return self.probackup_old_path
return self.probackup_path

def _add_options(self, command: list, skip_log_directory: bool):
strcommand = ' '.join(str(p) for p in command)

if '--log-level-file' in strcommand and \
'--log-directory' not in strcommand and \
not skip_log_directory:
command += ['--log-directory=' + self.pb_log_path]
strcommand += ' ' + command[-1]

if 'pglz' in strcommand and \
' -j' not in strcommand and '--thread' not in strcommand:
' -j' not in strcommand and \
'--thread' not in strcommand:
command += ['-j', '1']
strcommand += ' -j 1'

self.test_class.cmd = binary_path + ' ' + strcommand
if self.verbose:
print(self.test_class.cmd)
return command, strcommand

def _form_cmdline(self, binary_path, command):
cmdline = [binary_path, *command]
if gdb is True:
# general test flow for using GDBObj
return GDBobj(cmdline, self.test_class)

if 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 = [
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Отличие по сути только тут

"valgrind",
"--gen-suppressions=all",
"--leak-check=full",
"--show-reachable=yes",
"--error-limit=no",
"--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}",
"--"
]
cmdline = valgrind_cmd + cmdline

return cmdline

def _execute_command(self, cmdline, env, command, gdb, expect_error, return_id, daemonize):
try:
if type(gdb) is tuple and gdb[0] == 'suspend':
# special test flow for manually debug probackup
if isinstance(gdb, tuple) and gdb[0] == 'suspend':
gdb_port = gdb[1]
cmdline = ['gdbserver'] + ['localhost:' + str(gdb_port)] + cmdline
logging.warning("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))

# Execute command
start_time = time.time()
if daemonize:
return self.form_daemon_process(cmdline, env)
Expand DownExpand Up@@ -174,6 +216,7 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
return self.test_class.output
else:
raise ProbackupException(self.test_class.output, self.test_class.cmd)
# ---- End run function ---- #

def get_backup_id(self):
if init_params.major_version > 2:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -214,6 +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)

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

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp