]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-95672 skip fcntl when pipesize is smaller than pagesize (gh-102163)
authorHyunkyun Moon <hyunkyun.moon@linecorp.com>
Wed, 1 Mar 2023 14:56:19 +0000 (23:56 +0900)
committerGitHub <noreply@github.com>
Wed, 1 Mar 2023 14:56:19 +0000 (23:56 +0900)
Doc/library/test.rst
Lib/test/support/__init__.py
Lib/test/test_fcntl.py
Lib/test/test_subprocess.py

index 8199a27d7d9c4eb493e9d2c3cb5fda89d6117a6c..3c759648e4e626bd5b0eb29df87f745cfa5e1087 100644 (file)
@@ -536,6 +536,13 @@ The :mod:`test.support` module defines the following functions:
    :func:`doctest.testmod`.
 
 
+.. function:: get_pagesize()
+
+   Get size of a page in bytes.
+
+    .. versionadded:: 3.12
+
+
 .. function:: setswitchinterval(interval)
 
    Set the :func:`sys.setswitchinterval` to the given *interval*.  Defines
index 4a22ccdd4db4030c4acc6b30f56f123805cbb8ed..c309fd7910e0e6b72d0684b143e398d82cde308c 100644 (file)
@@ -51,6 +51,8 @@ __all__ = [
     # sys
     "is_jython", "is_android", "is_emscripten", "is_wasi",
     "check_impl_detail", "unix_shell", "setswitchinterval",
+    # os
+    "get_pagesize",
     # network
     "open_urlresource",
     # processes
@@ -1893,6 +1895,18 @@ def setswitchinterval(interval):
     return sys.setswitchinterval(interval)
 
 
+def get_pagesize():
+    """Get size of a page in bytes."""
+    try:
+        page_size = os.sysconf('SC_PAGESIZE')
+    except (ValueError, AttributeError):
+        try:
+            page_size = os.sysconf('SC_PAGE_SIZE')
+        except (ValueError, AttributeError):
+            page_size = 4096
+    return page_size
+
+
 @contextlib.contextmanager
 def disable_faulthandler():
     import faulthandler
index 26de67d924272a9b3f3ba0302e1bbd251daadc5d..5da75615b41d79760e2971a5b06d0c8107a8dbad 100644 (file)
@@ -6,7 +6,7 @@ import os
 import struct
 import sys
 import unittest
-from test.support import verbose, cpython_only
+from test.support import verbose, cpython_only, get_pagesize
 from test.support.import_helper import import_module
 from test.support.os_helper import TESTFN, unlink
 
@@ -201,7 +201,8 @@ class TestFcntl(unittest.TestCase):
             # Get the default pipesize with F_GETPIPE_SZ
             pipesize_default = fcntl.fcntl(test_pipe_w, fcntl.F_GETPIPE_SZ)
             pipesize = pipesize_default // 2  # A new value to detect change.
-            if pipesize < 512:  # the POSIX minimum
+            pagesize_default = get_pagesize()
+            if pipesize < pagesize_default:  # the POSIX minimum
                 raise unittest.SkipTest(
                     'default pipesize too small to perform test.')
             fcntl.fcntl(test_pipe_w, fcntl.F_SETPIPE_SZ, pipesize)
index 727b0e6dc578c2958b8ec0dc7775dea669419049..3880125807f23572d2f18d6f67c57d2e301ffb5a 100644 (file)
@@ -717,7 +717,8 @@ class ProcessTestCase(BaseTestCase):
             os.close(test_pipe_r)
             os.close(test_pipe_w)
         pipesize = pipesize_default // 2
-        if pipesize < 512:  # the POSIX minimum
+        pagesize_default = support.get_pagesize()
+        if pipesize < pagesize_default:  # the POSIX minimum
             raise unittest.SkipTest(
                 'default pipesize too small to perform test.')
         p = subprocess.Popen(