Skip to content
Open
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
21 changes: 18 additions & 3 deletions pytests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,29 @@ def _skip_if_valgrind_disabled(self):
if not self.config['valgrind_enabled']:
pytest.skip(self.config['valgrind_disabled_reason'])

def run_memcheck(self, cmd):
def run_memcheck(self, cmd, assertOnLeak=True):
self._skip_if_valgrind_disabled()
self._decorate_tdnf_cmd_for_test(cmd)

log_file = '/tmp/valgrind_memcheck.log'

memcheck_cmd = ['valgrind',
'--leak-check=full',
'--exit-on-first-error=yes',
'--show-leak-kinds=all',
f'--log-file={log_file}',
'--error-exitcode=1']
return self._run(memcheck_cmd + cmd, retvalonly=True)

ret = self._run(memcheck_cmd + cmd, retvalonly=True)
rc = ret['retval']

if assertOnLeak:
if rc and os.path.exists(log_file):
with open(log_file, 'r') as f:
print(f.read(), file=sys.stderr)
assert False, "valgrind memory leak check failed"

ret['valgrind_logfile'] = log_file
return ret

def run(self, cmd, cwd=None, noconfig=False):
if isinstance(cmd, str):
Expand Down
Loading