From a3e90fc2932ac73c86f8888949517cb6def895f9 Mon Sep 17 00:00:00 2001 From: HyunKyun Moon Date: Thu, 23 Feb 2023 11:00:02 +0900 Subject: [PATCH 1/8] skip fcntl when pipesize is smaller than pagesize --- Lib/test/test_fcntl.py | 3 ++- Lib/test/test_subprocess.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 26de67d924272a..21f70eac23fbfd 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -201,7 +201,8 @@ def test_fcntl_f_pipesize(self): # 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 + minimum_pipe_size = os.sysconf('SC_PAGESIZE') # There's a check that attempts to skip the tests if the pipe capacity is 512 bytes, but that's less than the smallest page size on x86. + if pipesize < minimum_pipe_size: # the POSIX minimum raise unittest.SkipTest( 'default pipesize too small to perform test.') fcntl.fcntl(test_pipe_w, fcntl.F_SETPIPE_SZ, pipesize) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 727b0e6dc578c2..446de35b8ae208 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -717,7 +717,8 @@ def test_pipesizes(self): os.close(test_pipe_r) os.close(test_pipe_w) pipesize = pipesize_default // 2 - if pipesize < 512: # the POSIX minimum + minimum_pipe_size = os.sysconf('SC_PAGESIZE') # There's a check that attempts to skip the tests if the pipe capacity is 512 bytes, but that's less than the smallest page size on x86. + if pipesize < minimum_pipe_size: # the POSIX minimum raise unittest.SkipTest( 'default pipesize too small to perform test.') p = subprocess.Popen( From 89cc89f4484303bcb8d0ebd1c25a4e1f0ef35a0d Mon Sep 17 00:00:00 2001 From: HyunKyun Moon Date: Fri, 24 Feb 2023 23:50:39 +0900 Subject: [PATCH 2/8] apply review --- Lib/test/test_fcntl.py | 5 +++-- Lib/test/test_subprocess.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 21f70eac23fbfd..f2d36f6234b99e 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -196,13 +196,14 @@ def test_fcntl_f_getpath(self): hasattr(fcntl, "F_SETPIPE_SZ") and hasattr(fcntl, "F_GETPIPE_SZ"), "F_SETPIPE_SZ and F_GETPIPE_SZ are not available on all platforms.") def test_fcntl_f_pipesize(self): + resource = import_module('resource') test_pipe_r, test_pipe_w = os.pipe() try: # 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. - minimum_pipe_size = os.sysconf('SC_PAGESIZE') # There's a check that attempts to skip the tests if the pipe capacity is 512 bytes, but that's less than the smallest page size on x86. - if pipesize < minimum_pipe_size: # the POSIX minimum + pagesize_default = resource.getpagesize() + 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) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 446de35b8ae208..ffabb65a230bf4 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -709,6 +709,7 @@ def test_stdin_devnull(self): @unittest.skipUnless(fcntl and hasattr(fcntl, 'F_GETPIPE_SZ'), 'fcntl.F_GETPIPE_SZ required for test.') def test_pipesizes(self): + resource = import_helper.import_module('resource') test_pipe_r, test_pipe_w = os.pipe() try: # Get the default pipesize with F_GETPIPE_SZ @@ -717,8 +718,8 @@ def test_pipesizes(self): os.close(test_pipe_r) os.close(test_pipe_w) pipesize = pipesize_default // 2 - minimum_pipe_size = os.sysconf('SC_PAGESIZE') # There's a check that attempts to skip the tests if the pipe capacity is 512 bytes, but that's less than the smallest page size on x86. - if pipesize < minimum_pipe_size: # the POSIX minimum + pagesize_default = resource.getpagesize() + if pipesize < pagesize_default: # the POSIX minimum raise unittest.SkipTest( 'default pipesize too small to perform test.') p = subprocess.Popen( From aa752c637c7a76d1211ac902b6c0ce39462f57e0 Mon Sep 17 00:00:00 2001 From: HyunKyun Moon Date: Sat, 25 Feb 2023 11:41:01 +0900 Subject: [PATCH 3/8] apply review --- Lib/test/test_fcntl.py | 2 +- Lib/test/test_subprocess.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index f2d36f6234b99e..cf393e6bfcbccb 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -6,6 +6,7 @@ import struct import sys import unittest +import resource from test.support import verbose, cpython_only from test.support.import_helper import import_module from test.support.os_helper import TESTFN, unlink @@ -196,7 +197,6 @@ def test_fcntl_f_getpath(self): hasattr(fcntl, "F_SETPIPE_SZ") and hasattr(fcntl, "F_GETPIPE_SZ"), "F_SETPIPE_SZ and F_GETPIPE_SZ are not available on all platforms.") def test_fcntl_f_pipesize(self): - resource = import_module('resource') test_pipe_r, test_pipe_w = os.pipe() try: # Get the default pipesize with F_GETPIPE_SZ diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index ffabb65a230bf4..607f0158747721 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -24,6 +24,7 @@ import textwrap import json import pathlib +import resource from test.support.os_helper import FakePath try: @@ -709,7 +710,6 @@ def test_stdin_devnull(self): @unittest.skipUnless(fcntl and hasattr(fcntl, 'F_GETPIPE_SZ'), 'fcntl.F_GETPIPE_SZ required for test.') def test_pipesizes(self): - resource = import_helper.import_module('resource') test_pipe_r, test_pipe_w = os.pipe() try: # Get the default pipesize with F_GETPIPE_SZ From eea71c344b26ed5fd47bd391debfebdf8e8dd4bf Mon Sep 17 00:00:00 2001 From: HyunKyun Moon Date: Wed, 1 Mar 2023 19:20:07 +0900 Subject: [PATCH 4/8] add get_pagesize to test.support --- Doc/library/test.rst | 5 +++++ Lib/test/support/__init__.py | 12 ++++++++++++ Lib/test/test_fcntl.py | 4 ++-- Lib/test/test_subprocess.py | 3 +-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 8199a27d7d9c4e..0e86dea529ebef 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -536,6 +536,11 @@ The :mod:`test.support` module defines the following functions: :func:`doctest.testmod`. +.. function:: get_pagesize() + + Get size of a page in bytes. + + .. function:: setswitchinterval(interval) Set the :func:`sys.setswitchinterval` to the given *interval*. Defines diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 4a22ccdd4db403..1c7936b17ea84b 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -51,6 +51,8 @@ # sys "is_jython", "is_android", "is_emscripten", "is_wasi", "check_impl_detail", "unix_shell", "setswitchinterval", + # os + "get_pagesize", # network "open_urlresource", # processes @@ -1892,6 +1894,16 @@ def setswitchinterval(interval): interval = minimum_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(): diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index cf393e6bfcbccb..1e199ab09b937d 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -6,7 +6,7 @@ import struct import sys import unittest -import resource +from test import support from test.support import verbose, cpython_only from test.support.import_helper import import_module from test.support.os_helper import TESTFN, unlink @@ -202,7 +202,7 @@ def test_fcntl_f_pipesize(self): # 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. - pagesize_default = resource.getpagesize() + pagesize_default = support.get_pagesize() if pipesize < pagesize_default: # the POSIX minimum raise unittest.SkipTest( 'default pipesize too small to perform test.') diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 607f0158747721..3880125807f235 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -24,7 +24,6 @@ import textwrap import json import pathlib -import resource from test.support.os_helper import FakePath try: @@ -718,7 +717,7 @@ def test_pipesizes(self): os.close(test_pipe_r) os.close(test_pipe_w) pipesize = pipesize_default // 2 - pagesize_default = resource.getpagesize() + pagesize_default = support.get_pagesize() if pipesize < pagesize_default: # the POSIX minimum raise unittest.SkipTest( 'default pipesize too small to perform test.') From ca6a96e32ae476f93084cc83414ca3d475fa59f2 Mon Sep 17 00:00:00 2001 From: Hyunkyun Moon Date: Wed, 1 Mar 2023 21:01:03 +0900 Subject: [PATCH 5/8] Update Lib/test/support/__init__.py Co-authored-by: Dong-hee Na --- Lib/test/support/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 1c7936b17ea84b..f04880488bbbb6 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1894,6 +1894,7 @@ def setswitchinterval(interval): interval = minimum_interval return sys.setswitchinterval(interval) + def get_pagesize(): """Get size of a page in bytes.""" try: From e14a3457353ea11e8dcc8be416d11ffc798543e6 Mon Sep 17 00:00:00 2001 From: Hyunkyun Moon Date: Wed, 1 Mar 2023 21:01:14 +0900 Subject: [PATCH 6/8] Update Lib/test/support/__init__.py Co-authored-by: Dong-hee Na --- Lib/test/support/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index f04880488bbbb6..c309fd7910e0e6 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1906,6 +1906,7 @@ def get_pagesize(): page_size = 4096 return page_size + @contextlib.contextmanager def disable_faulthandler(): import faulthandler From d5c4006ee899a9d26dedac8198dc1b9baf71f566 Mon Sep 17 00:00:00 2001 From: Hyunkyun Moon Date: Wed, 1 Mar 2023 21:01:27 +0900 Subject: [PATCH 7/8] Update Doc/library/test.rst Co-authored-by: Dong-hee Na --- Doc/library/test.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/test.rst b/Doc/library/test.rst index 0e86dea529ebef..3c759648e4e626 100644 --- a/Doc/library/test.rst +++ b/Doc/library/test.rst @@ -540,6 +540,8 @@ The :mod:`test.support` module defines the following functions: Get size of a page in bytes. + .. versionadded:: 3.12 + .. function:: setswitchinterval(interval) From 60fe601b5f9c043cd53ac6bb28139984f14df6f7 Mon Sep 17 00:00:00 2001 From: HyunKyun Moon Date: Wed, 1 Mar 2023 22:29:38 +0900 Subject: [PATCH 8/8] apply reivew --- Lib/test/test_fcntl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 1e199ab09b937d..5da75615b41d79 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -6,8 +6,7 @@ import struct import sys import unittest -from test import support -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 @@ -202,7 +201,7 @@ def test_fcntl_f_pipesize(self): # 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. - pagesize_default = support.get_pagesize() + pagesize_default = get_pagesize() if pipesize < pagesize_default: # the POSIX minimum raise unittest.SkipTest( 'default pipesize too small to perform test.')