From cc2c9c69020b14e6e1ba00d9f95c05854ca236cb Mon Sep 17 00:00:00 2001 From: xiejunyi Date: Tue, 14 Sep 2021 21:02:33 +0800 Subject: [PATCH] bugfix: issue45196, ./configure --with-address-sanitizer;run unitest crash failed --- Lib/test/test_decimal.py | 13 +++++++++++++ Lib/test/test_io.py | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 28d56909b30034..99263bb13b0d14 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -43,6 +43,17 @@ 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 @@ def __abs__(self): # 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 d1e3b68cc8d96f..3619e749d1731e 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -73,6 +73,10 @@ class EmptyStruct(ctypes.Structure): '--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 @@ def test_truncate_on_read_only(self): 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 @@ def test_slow_close_from_thread(self): 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 @@ def test_interleaved_readline_write(self): 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)