Skip to content

Commit

Permalink
pythongh-110367: Fix regrtest test_worker_output_on_failure() on ASAN…
Browse files Browse the repository at this point in the history
… build (python#110387)

Set ASAN_OPTIONS="handle_segv=0" env var to run the test.
  • Loading branch information
vstinner authored and Glyphack committed Jan 27, 2024
1 parent fee1b70 commit 36494c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
return unittest.skipIf(skip, reason)


def set_sanitizer_env_var(env, option):
for name in ('ASAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS'):
if name in env:
env[name] += f':{option}'
else:
env[name] = option


def system_must_validate_cert(f):
"""Skip the test on TLS certificate validation failures."""
@functools.wraps(f)
Expand Down
6 changes: 1 addition & 5 deletions Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ def get_output(self, code, filename=None, fd=None):

# Sanitizers must not handle SIGSEGV (ex: for test_enable_fd())
option = 'handle_segv=0'
for name in ('ASAN_OPTIONS', 'MSAN_OPTIONS', 'UBSAN_OPTIONS'):
if name in env:
env[name] += f':{option}'
else:
env[name] = option
support.set_sanitizer_env_var(env, option)

with support.SuppressCrashReport():
process = script_helper.spawn_python('-c', code,
Expand Down
15 changes: 11 additions & 4 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def run_command(self, args, input=None, exitcode=0, **kw):
if 'stderr' not in kw:
kw['stderr'] = subprocess.STDOUT
proc = subprocess.run(args,
universal_newlines=True,
text=True,
input=input,
stdout=subprocess.PIPE,
**kw)
Expand Down Expand Up @@ -756,8 +756,8 @@ def check_output(self, output):
self.check_executed_tests(output, self.tests,
randomize=True, stats=len(self.tests))

def run_tests(self, args):
output = self.run_python(args)
def run_tests(self, args, env=None):
output = self.run_python(args, env=env)
self.check_output(output)

def test_script_regrtest(self):
Expand Down Expand Up @@ -2061,7 +2061,14 @@ def test_crash(self):
""")
testname = self.create_test(code=code)

output = self.run_tests("-j1", testname, exitcode=EXITCODE_BAD_TEST)
# Sanitizers must not handle SIGSEGV (ex: for test_enable_fd())
env = dict(os.environ)
option = 'handle_segv=0'
support.set_sanitizer_env_var(env, option)

output = self.run_tests("-j1", testname,
exitcode=EXITCODE_BAD_TEST,
env=env)
self.check_executed_tests(output, testname,
failed=[testname],
stats=0, parallel=True)
Expand Down

0 comments on commit 36494c3

Please sign in to comment.