Skip to content

gh-137044: Fix test_resource on 32-bit Linux #137941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Lib/test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading