Skip to content

Commit e5796c4

Browse files
authored
bpo-35214: Skip test_io tests that'd cause a huge malloc under msan (#11385)
* skip test_constructor under msan. * fix the others as well. * reuse existing related news entry. * typo fix
1 parent d6f45b2 commit e5796c4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Lib/test/test_io.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import random
2929
import signal
3030
import sys
31+
import sysconfig
3132
import threading
3233
import time
3334
import unittest
@@ -59,6 +60,13 @@ def byteslike(*pos, **kw):
5960
class EmptyStruct(ctypes.Structure):
6061
pass
6162

63+
_cflags = sysconfig.get_config_var('CFLAGS') or ''
64+
_config_args = sysconfig.get_config_var('CONFIG_ARGS') or ''
65+
MEMORY_SANITIZER = (
66+
'-fsanitize=memory' in _cflags or
67+
'--with-memory-sanitizer' in _config_args
68+
)
69+
6270
def _default_chunk_size():
6371
"""Get the default TextIOWrapper chunk size"""
6472
with open(__file__, "r", encoding="latin-1") as f:
@@ -1496,6 +1504,8 @@ def test_read_on_closed(self):
14961504
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
14971505
tp = io.BufferedReader
14981506

1507+
@unittest.skipIf(MEMORY_SANITIZER, "MSan defaults to crashing "
1508+
"instead of returning NULL for malloc failure.")
14991509
def test_constructor(self):
15001510
BufferedReaderTest.test_constructor(self)
15011511
# The allocation can succeed on 32-bit builds, e.g. with more
@@ -1840,6 +1850,8 @@ def test_slow_close_from_thread(self):
18401850
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
18411851
tp = io.BufferedWriter
18421852

1853+
@unittest.skipIf(MEMORY_SANITIZER, "MSan defaults to crashing "
1854+
"instead of returning NULL for malloc failure.")
18431855
def test_constructor(self):
18441856
BufferedWriterTest.test_constructor(self)
18451857
# The allocation can succeed on 32-bit builds, e.g. with more
@@ -2314,6 +2326,8 @@ def test_interleaved_readline_write(self):
23142326
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
23152327
tp = io.BufferedRandom
23162328

2329+
@unittest.skipIf(MEMORY_SANITIZER, "MSan defaults to crashing "
2330+
"instead of returning NULL for malloc failure.")
23172331
def test_constructor(self):
23182332
BufferedRandomTest.test_constructor(self)
23192333
# The allocation can succeed on 32-bit builds, e.g. with more
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
clang Memory Sanitizer build instrumentation was added to work around false
2-
positives from socket, time, and test_faulthandler.
2+
positives from socket, time, test_io, and test_faulthandler.

0 commit comments

Comments
 (0)