Skip to content

Commit cc804f8

Browse files
committed
gh-157354: Recognize disabled sanitizer configure options in tests
1 parent d352f25 commit cc804f8

4 files changed

Lines changed: 44 additions & 18 deletions

File tree

‎Lib/test/support/__init__.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import _opcode
1212
import os
1313
import re
14+
import shlex
1415
import stat
1516
import sys
1617
import sysconfig
@@ -469,27 +470,39 @@ def check_sanitizer(*, address=False, hwaddress=False, memory=False, ub=False,
469470

470471

471472
cflags = sysconfig.get_config_var('CFLAGS') or ''
472-
config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
473+
config_args = shlex.split(sysconfig.get_config_var('CONFIG_ARGS') or '')
474+
475+
def configured_with_sanitizer(name):
476+
with_option = f'--with-{name}-sanitizer'
477+
without_option = f'--without-{name}-sanitizer'
478+
enabled = False
479+
for arg in config_args:
480+
if arg == without_option or arg == f'{with_option}=no':
481+
enabled = False
482+
elif arg == with_option or arg.startswith(f'{with_option}='):
483+
enabled = True
484+
return enabled
485+
473486
memory_sanitizer = (
474487
'-fsanitize=memory' in cflags or
475-
'--with-memory-sanitizer' in config_args
488+
configured_with_sanitizer('memory')
476489
)
477490
hwaddress_sanitizer = (
478491
'-fsanitize=hwaddress' in cflags or
479-
'--with-hwaddress-sanitizer' in config_args
492+
configured_with_sanitizer('hwaddress')
480493
)
481494
address_sanitizer = (
482495
'-fsanitize=address' in cflags or
483-
'--with-address-sanitizer' in config_args or
496+
configured_with_sanitizer('address') or
484497
hwaddress_sanitizer
485498
)
486499
ub_sanitizer = (
487500
'-fsanitize=undefined' in cflags or
488-
'--with-undefined-behavior-sanitizer' in config_args
501+
configured_with_sanitizer('undefined-behavior')
489502
)
490503
thread_sanitizer = (
491504
'-fsanitize=thread' in cflags or
492-
'--with-thread-sanitizer' in config_args
505+
configured_with_sanitizer('thread')
493506
)
494507
function_sanitizer = (
495508
'-fsanitize=function' in cflags

‎Lib/test/test_support.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import textwrap
1818
import unittest
1919
import warnings
20+
from unittest import mock
2021

2122
from test import support
2223
from test.support import isolation
@@ -60,6 +61,29 @@ def _caplog():
6061

6162

6263
class TestSupport(unittest.TestCase):
64+
def test_check_sanitizer_config_args(self):
65+
sanitizers = (
66+
('address', 'address'),
67+
('hwaddress', 'hwaddress'),
68+
('memory', 'memory'),
69+
('undefined-behavior', 'ub'),
70+
('thread', 'thread'),
71+
)
72+
for option, keyword in sanitizers:
73+
for config_arg, expected in (
74+
(f'--with-{option}-sanitizer=no', False),
75+
(f'--without-{option}-sanitizer', False),
76+
(f'--with-{option}-sanitizer', True),
77+
(f'--with-{option}-sanitizer=yes', True),
78+
):
79+
with self.subTest(config_arg=config_arg):
80+
config = {'CFLAGS': '', 'CONFIG_ARGS': f"'{config_arg}'"}
81+
with mock.patch.object(sysconfig, 'get_config_var',
82+
side_effect=config.get):
83+
self.assertEqual(
84+
support.check_sanitizer(**{keyword: True}), expected
85+
)
86+
6387
@classmethod
6488
def setUpClass(cls):
6589
orig_filter_len = len(warnings._get_filters())
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Honor ``=no`` and ``--without-...`` for the AddressSanitizer,
22
HWAddressSanitizer, MemorySanitizer, UndefinedBehaviorSanitizer, and
3-
ThreadSanitizer configure options without adding sanitizer flags or changing
4-
the pymalloc setting.
3+
ThreadSanitizer configure options without adding sanitizer flags.

‎configure‎

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)