mirror of
https://github.com/python/cpython.git
synced 2025-11-11 19:12:05 +00:00
gh-137044: Fix test_resource on 32-bit Linux (GH-137941)
This commit is contained in:
parent
379161dd51
commit
ac37b77441
1 changed files with 14 additions and 7 deletions
|
|
@ -116,33 +116,40 @@ def test_fsize_not_too_big(self):
|
||||||
self.addCleanup(resource.setrlimit, resource.RLIMIT_FSIZE, (cur, max))
|
self.addCleanup(resource.setrlimit, resource.RLIMIT_FSIZE, (cur, max))
|
||||||
|
|
||||||
def expected(cur):
|
def expected(cur):
|
||||||
return (min(cur, resource.RLIM_INFINITY), max)
|
# The glibc wrapper functions use a 64-bit rlim_t data type,
|
||||||
|
# even on 32-bit platforms. If a program tried to set a resource
|
||||||
|
# limit to a value larger than can be represented in a 32-bit
|
||||||
|
# unsigned long, then the glibc setrlimit() wrapper function
|
||||||
|
# silently converted the limit value to RLIM_INFINITY.
|
||||||
|
if sys.maxsize < 2**32 <= cur <= resource.RLIM_INFINITY:
|
||||||
|
return [(resource.RLIM_INFINITY, max), (cur, max)]
|
||||||
|
return [(min(cur, resource.RLIM_INFINITY), max)]
|
||||||
|
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**31-5, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**31-5, max))
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), (2**31-5, max))
|
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), (2**31-5, max))
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**31, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**31, max))
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**31))
|
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**31))
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32-5, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32-5, max))
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32-5))
|
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32-5))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32, max))
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32))
|
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32))
|
||||||
|
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**63-5, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**63-5, max))
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63-5))
|
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63-5))
|
||||||
try:
|
try:
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**63, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**63, max))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# There is a hard limit on macOS.
|
# There is a hard limit on macOS.
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63))
|
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63))
|
||||||
resource.setrlimit(resource.RLIMIT_FSIZE, (2**64-5, max))
|
resource.setrlimit(resource.RLIMIT_FSIZE, (2**64-5, max))
|
||||||
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**64-5))
|
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**64-5))
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform == "vxworks",
|
@unittest.skipIf(sys.platform == "vxworks",
|
||||||
"setting RLIMIT_FSIZE is not supported on VxWorks")
|
"setting RLIMIT_FSIZE is not supported on VxWorks")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue