Skip to content

Commit

Permalink
bpo-40928: notify users running test_decimal on macOS of malloc warni…
Browse files Browse the repository at this point in the history
…ngs (pythonGH-26783)

* When trying to allocate very large regions on macOS, malloc does not   fail silently. It sends a noisy error out to STDERR
* This provides a helper function to warn the user, and provides the warning for test_decimal, which consistently generates these warnings on macOS.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
jdevries3133 and ambv committed Aug 6, 2021
1 parent 4d77691 commit 15d3c14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,24 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
TEST_DATA_DIR = os.path.join(TEST_HOME_DIR, "data")


def darwin_malloc_err_warning(test_name):
"""Assure user that loud errors generated by macOS libc's malloc are
expected."""
if sys.platform != 'darwin':
return

import shutil
msg = ' NOTICE '
detail = (f'{test_name} may generate "malloc can\'t allocate region"\n'
'warnings on macOS systems. This behavior is known. Do not\n'
'report a bug unless tests are also failing. See bpo-40928.')

padding, _ = shutil.get_terminal_size()
print(msg.center(padding, '-'))
print(detail)
print('-' * padding)


def findfile(filename, subdir=None):
"""Try to find a file on sys.path or in the test directory. If it is not
found the argument passed to the function is returned (this does not
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@
requires_IEEE_754, requires_docstrings,
requires_legacy_unicode_capi)
from test.support import (TestFailed,
run_with_locale, cpython_only)
run_with_locale, cpython_only,
darwin_malloc_err_warning)
from test.support.import_helper import import_fresh_module
from test.support import warnings_helper
import random
import inspect
import threading


if sys.platform == 'darwin':
darwin_malloc_err_warning('test_decimal')


C = import_fresh_module('decimal', fresh=['_decimal'])
P = import_fresh_module('decimal', blocked=['_decimal'])
orig_sys_decimal = sys.modules['decimal']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Notify users running test_decimal regression tests on macOS of potential
harmless "malloc can't allocate region" messages spewed by test_decimal.

0 comments on commit 15d3c14

Please sign in to comment.