]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40928: notify users running test_decimal on macOS of malloc warnings (GH-26783)
authorJack DeVries <58614260+jdevries3133@users.noreply.github.com>
Fri, 6 Aug 2021 12:50:56 +0000 (08:50 -0400)
committerGitHub <noreply@github.com>
Fri, 6 Aug 2021 12:50:56 +0000 (14:50 +0200)
* 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>
Lib/test/support/__init__.py
Lib/test/test_decimal.py
Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst [new file with mode: 0644]

index e2847d5d3771eaa9f9e9df9d6baf2d60ebdc31ed..b380271d24f2305ce74a772b94ccfb1c33e8c4f1 100644 (file)
@@ -467,6 +467,24 @@ TEST_HOME_DIR = os.path.dirname(TEST_SUPPORT_DIR)
 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
index 058829b03a3deeb273a2d69e94275fcd5f96e256..28d56909b30034bd03235237cf5d4c3650b07c0b 100644 (file)
@@ -36,7 +36,8 @@ from test.support import (run_unittest, run_doctest, is_resource_enabled,
                           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
@@ -44,6 +45,10 @@ 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']
diff --git a/Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst b/Misc/NEWS.d/next/Tests/2021-08-06-00-07-15.bpo-40928.aIwb6G.rst
new file mode 100644 (file)
index 0000000..c9a5e1b
--- /dev/null
@@ -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.