Skip to content

Commit 2f62a5d

Browse files
gh-95672 skip fcntl when pipesize is smaller than pagesize (gh-102163)
1 parent c1748ed commit 2f62a5d

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Doc/library/test.rst

+7
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,13 @@ The :mod:`test.support` module defines the following functions:
536536
:func:`doctest.testmod`.
537537

538538

539+
.. function:: get_pagesize()
540+
541+
Get size of a page in bytes.
542+
543+
.. versionadded:: 3.12
544+
545+
539546
.. function:: setswitchinterval(interval)
540547

541548
Set the :func:`sys.setswitchinterval` to the given *interval*. Defines

Lib/test/support/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
# sys
5252
"is_jython", "is_android", "is_emscripten", "is_wasi",
5353
"check_impl_detail", "unix_shell", "setswitchinterval",
54+
# os
55+
"get_pagesize",
5456
# network
5557
"open_urlresource",
5658
# processes
@@ -1893,6 +1895,18 @@ def setswitchinterval(interval):
18931895
return sys.setswitchinterval(interval)
18941896

18951897

1898+
def get_pagesize():
1899+
"""Get size of a page in bytes."""
1900+
try:
1901+
page_size = os.sysconf('SC_PAGESIZE')
1902+
except (ValueError, AttributeError):
1903+
try:
1904+
page_size = os.sysconf('SC_PAGE_SIZE')
1905+
except (ValueError, AttributeError):
1906+
page_size = 4096
1907+
return page_size
1908+
1909+
18961910
@contextlib.contextmanager
18971911
def disable_faulthandler():
18981912
import faulthandler

Lib/test/test_fcntl.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import struct
77
import sys
88
import unittest
9-
from test.support import verbose, cpython_only
9+
from test.support import verbose, cpython_only, get_pagesize
1010
from test.support.import_helper import import_module
1111
from test.support.os_helper import TESTFN, unlink
1212

@@ -201,7 +201,8 @@ def test_fcntl_f_pipesize(self):
201201
# Get the default pipesize with F_GETPIPE_SZ
202202
pipesize_default = fcntl.fcntl(test_pipe_w, fcntl.F_GETPIPE_SZ)
203203
pipesize = pipesize_default // 2 # A new value to detect change.
204-
if pipesize < 512: # the POSIX minimum
204+
pagesize_default = get_pagesize()
205+
if pipesize < pagesize_default: # the POSIX minimum
205206
raise unittest.SkipTest(
206207
'default pipesize too small to perform test.')
207208
fcntl.fcntl(test_pipe_w, fcntl.F_SETPIPE_SZ, pipesize)

Lib/test/test_subprocess.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ def test_pipesizes(self):
717717
os.close(test_pipe_r)
718718
os.close(test_pipe_w)
719719
pipesize = pipesize_default // 2
720-
if pipesize < 512: # the POSIX minimum
720+
pagesize_default = support.get_pagesize()
721+
if pipesize < pagesize_default: # the POSIX minimum
721722
raise unittest.SkipTest(
722723
'default pipesize too small to perform test.')
723724
p = subprocess.Popen(

0 commit comments

Comments
 (0)