Skip to content

Commit deb932f

Browse files
committed
pythongh-90791: test.pythoninfo logs ASAN_OPTIONS env var (python#108289)
* Cleanup libregrtest code logging ASAN_OPTIONS. * Fix a typo on "ASAN_OPTIONS" vs "MSAN_OPTIONS". (cherry picked from commit 3a1ac87)
1 parent 15425da commit deb932f

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
@@ -309,6 +309,13 @@ def format_groups(groups):
309309
"_PYTHON_PROJECT_BASE",
310310
"_PYTHON_SYSCONFIGDATA_NAME",
311311
"__PYVENV_LAUNCHER__",
312+
313+
# Sanitizer options
314+
"ASAN_OPTIONS",
315+
"LSAN_OPTIONS",
316+
"MSAN_OPTIONS",
317+
"TSAN_OPTIONS",
318+
"UBSAN_OPTIONS",
312319
))
313320
for name, value in os.environ.items():
314321
uname = name.upper()

Lib/test/support/__init__.py

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

402402

403-
_cflags = sysconfig.get_config_var('CFLAGS') or ''
404-
_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
403+
cflags = sysconfig.get_config_var('CFLAGS') or ''
404+
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
405405
memory_sanitizer = (
406-
'-fsanitize=memory' in _cflags or
407-
'--with-memory-sanitizer' in _config_args
406+
'-fsanitize=memory' in cflags or
407+
'--with-memory-sanitizer' in config_args
408408
)
409409
address_sanitizer = (
410-
'-fsanitize=address' in _cflags or
411-
'--with-address-sanitizer' in _config_args
410+
'-fsanitize=address' in cflags or
411+
'--with-address-sanitizer' in config_args
412412
)
413413
ub_sanitizer = (
414-
'-fsanitize=undefined' in _cflags or
415-
'--with-undefined-behavior-sanitizer' in _config_args
414+
'-fsanitize=undefined' in cflags or
415+
'--with-undefined-behavior-sanitizer' in config_args
416416
)
417417
return (
418418
(memory and memory_sanitizer) or

0 commit comments

Comments
 (0)