summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-09-14 18:58:19 (GMT)
committerGitHub <noreply@github.com>2021-09-14 18:58:19 (GMT)
commitbe200c3c6e2f82db553c0e5424e4ba70caf189c3 (patch)
treee158d08c624203c722852bad9842d682987ec5a2
parentfd74d2680ef96c0140bc02cf94d1cf1f2ef814c2 (diff)
downloadcpython-be200c3c6e2f82db553c0e5424e4ba70caf189c3.zip
cpython-be200c3c6e2f82db553c0e5424e4ba70caf189c3.tar.gz
cpython-be200c3c6e2f82db553c0e5424e4ba70caf189c3.tar.bz2
bpo-45196: prevent unittest crash on address sanitizer builds (GH-28331)
(cherry picked from commit b668cdfa09e9bdfcfddaadd23dbd455d5f667383) Co-authored-by: junyixie <xiejunyi.arch@bytedance.com>
-rw-r--r--Lib/test/test_decimal.py13
-rw-r--r--Lib/test/test_io.py10
2 files changed, 20 insertions, 3 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 28d5690..99263bb 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -43,6 +43,17 @@ from test.support import warnings_helper
import random
import inspect
import threading
+import sysconfig
+_cflags = sysconfig.get_config_var('CFLAGS') or ''
+_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
+MEMORY_SANITIZER = (
+ '-fsanitize=memory' in _cflags or
+ '--with-memory-sanitizer' in _config_args
+)
+
+ADDRESS_SANITIZER = (
+ '-fsanitize=address' in _cflags
+)
if sys.platform == 'darwin':
@@ -5500,6 +5511,8 @@ class CWhitebox(unittest.TestCase):
# Issue 41540:
@unittest.skipIf(sys.platform.startswith("aix"),
"AIX: default ulimit: test is flaky because of extreme over-allocation")
+ @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
+ "instead of returning NULL for malloc failure.")
def test_maxcontext_exact_arith(self):
# Make sure that exact operations do not raise MemoryError due
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 273545a..35013b6 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -73,6 +73,10 @@ MEMORY_SANITIZER = (
'--with-memory-sanitizer' in _config_args
)
+ADDRESS_SANITIZER = (
+ '-fsanitize=address' in _cflags
+)
+
# Does io.IOBase finalizer log the exception if the close() method fails?
# The exception is ignored silently by default in release build.
IOBASE_EMITS_UNRAISABLE = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
@@ -1546,7 +1550,7 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
tp = io.BufferedReader
- @unittest.skipIf(MEMORY_SANITIZER, "MSan defaults to crashing "
+ @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
def test_constructor(self):
BufferedReaderTest.test_constructor(self)
@@ -1911,7 +1915,7 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
tp = io.BufferedWriter
- @unittest.skipIf(MEMORY_SANITIZER, "MSan defaults to crashing "
+ @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
def test_constructor(self):
BufferedWriterTest.test_constructor(self)
@@ -2410,7 +2414,7 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest):
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
tp = io.BufferedRandom
- @unittest.skipIf(MEMORY_SANITIZER, "MSan defaults to crashing "
+ @unittest.skipIf(MEMORY_SANITIZER or ADDRESS_SANITIZER, "sanitizer defaults to crashing "
"instead of returning NULL for malloc failure.")
def test_constructor(self):
BufferedRandomTest.test_constructor(self)