Skip to content

Commit dc87215

Browse files
committed
pythongh-90791: test.pythoninfo logs ASAN_OPTIONS env var
* Cleanup libregrtest code logging ASAN_OPTIONS. * Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS".
1 parent 893215a commit dc87215

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

Lib/test/libregrtest/main.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -526,26 +526,33 @@ def display_header(self):
526526
print("== CPU count:", cpu_count)
527527
print("== encodings: locale=%s, FS=%s"
528528
% (locale.getencoding(), sys.getfilesystemencoding()))
529+
self.display_sanitizers()
530+
531+
def display_sanitizers(self):
532+
# This makes it easier to remember what to set in your local
533+
# environment when trying to reproduce a sanitizer failure.
529534
asan = support.check_sanitizer(address=True)
530535
msan = support.check_sanitizer(memory=True)
531536
ubsan = support.check_sanitizer(ub=True)
532-
# This makes it easier to remember what to set in your local
533-
# environment when trying to reproduce a sanitizer failure.
534-
if asan or msan or ubsan:
535-
names = [n for n in (asan and "address",
536-
msan and "memory",
537-
ubsan and "undefined behavior")
538-
if n]
539-
print(f"== sanitizers: {', '.join(names)}")
540-
a_opts = os.environ.get("ASAN_OPTIONS")
541-
if asan and a_opts is not None:
542-
print(f"== ASAN_OPTIONS={a_opts}")
543-
m_opts = os.environ.get("ASAN_OPTIONS")
544-
if msan and m_opts is not None:
545-
print(f"== MSAN_OPTIONS={m_opts}")
546-
ub_opts = os.environ.get("UBSAN_OPTIONS")
547-
if ubsan and ub_opts is not None:
548-
print(f"== UBSAN_OPTIONS={ub_opts}")
537+
sanitizers = []
538+
if asan:
539+
sanitizers.append("address")
540+
if msan:
541+
sanitizers.append("memory")
542+
if ubsan:
543+
sanitizers.append("undefined behavior")
544+
if not sanitizers:
545+
return
546+
547+
print(f"== sanitizers: {', '.join(sanitizers)}")
548+
for sanitizer, env_var in (
549+
(asan, "ASAN_OPTIONS"),
550+
(msan, "MSAN_OPTIONS"),
551+
(ubsan, "UBSAN_OPTIONS"),
552+
):
553+
options= os.environ.get(env_var)
554+
if sanitizer and options is not None:
555+
print(f"== {env_var}={options!r}")
549556

550557
def no_tests_run(self):
551558
return not any((self.good, self.bad, self.skipped, self.interrupted,

Lib/test/pythoninfo.py

+7
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ def format_groups(groups):
308308
"_PYTHON_PROJECT_BASE",
309309
"_PYTHON_SYSCONFIGDATA_NAME",
310310
"__PYVENV_LAUNCHER__",
311+
312+
# ASAN options
313+
"ASAN_OPTIONS",
314+
"LSAN_OPTIONS",
315+
"MSAN_OPTIONS",
316+
"TSAN_OPTIONS",
317+
"UBSAN_OPTIONS",
311318
))
312319
for name, value in os.environ.items():
313320
uname = name.upper()

Lib/test/support/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,19 @@ def check_sanitizer(*, address=False, memory=False, ub=False):
407407
raise ValueError('At least one of address, memory, or ub must be True')
408408

409409

410-
_cflags = sysconfig.get_config_var('CFLAGS') or ''
411-
_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
410+
cflags = sysconfig.get_config_var('CFLAGS') or ''
411+
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
412412
memory_sanitizer = (
413-
'-fsanitize=memory' in _cflags or
414-
'--with-memory-sanitizer' in _config_args
413+
'-fsanitize=memory' in cflags or
414+
'--with-memory-sanitizer' in config_args
415415
)
416416
address_sanitizer = (
417-
'-fsanitize=address' in _cflags or
418-
'--with-address-sanitizer' in _config_args
417+
'-fsanitize=address' in cflags or
418+
'--with-address-sanitizer' in config_args
419419
)
420420
ub_sanitizer = (
421-
'-fsanitize=undefined' in _cflags or
422-
'--with-undefined-behavior-sanitizer' in _config_args
421+
'-fsanitize=undefined' in cflags or
422+
'--with-undefined-behavior-sanitizer' in config_args
423423
)
424424
return (
425425
(memory and memory_sanitizer) or

0 commit comments

Comments
 (0)