gh-137044: Fix test_resource on 32-bit Linux (GH-137941)

This commit is contained in:
Serhiy Storchaka 2025-08-19 15:22:30 +03:00 committed by GitHub
parent 379161dd51
commit ac37b77441
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -116,33 +116,40 @@ def test_fsize_not_too_big(self):
self.addCleanup(resource.setrlimit, resource.RLIMIT_FSIZE, (cur, max))
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))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), (2**31-5, 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))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32-5))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**32-5))
try:
resource.setrlimit(resource.RLIMIT_FSIZE, (2**32, max))
except OverflowError:
pass
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))
self.assertEqual(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63-5))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**63-5))
try:
resource.setrlimit(resource.RLIMIT_FSIZE, (2**63, max))
except ValueError:
# There is a hard limit on macOS.
pass
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))
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",
"setting RLIMIT_FSIZE is not supported on VxWorks")