gh-117061: Fix test_posix.test_sched_setaffinity() on RHEL9 (#117126)

On RHEL9, sched_setaffinity(0, []) does not fail.
This commit is contained in:
Victor Stinner 2024-03-21 23:17:09 +01:00 committed by GitHub
parent 0907871d43
commit 50f9b0b1e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 1 deletions

View File

@ -1335,12 +1335,21 @@ class PosixTester(unittest.TestCase):
def test_sched_setaffinity(self): def test_sched_setaffinity(self):
mask = posix.sched_getaffinity(0) mask = posix.sched_getaffinity(0)
self.addCleanup(posix.sched_setaffinity, 0, list(mask)) self.addCleanup(posix.sched_setaffinity, 0, list(mask))
if len(mask) > 1: if len(mask) > 1:
# Empty masks are forbidden # Empty masks are forbidden
mask.pop() mask.pop()
posix.sched_setaffinity(0, mask) posix.sched_setaffinity(0, mask)
self.assertEqual(posix.sched_getaffinity(0), mask) self.assertEqual(posix.sched_getaffinity(0), mask)
self.assertRaises(OSError, posix.sched_setaffinity, 0, [])
try:
posix.sched_setaffinity(0, [])
# gh-117061: On RHEL9, sched_setaffinity(0, []) does not fail
except OSError:
# sched_setaffinity() manual page documents EINVAL error
# when the mask is empty.
pass
self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10]) self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10])
self.assertRaises(ValueError, posix.sched_setaffinity, 0, map(int, "0X")) self.assertRaises(ValueError, posix.sched_setaffinity, 0, map(int, "0X"))
self.assertRaises(OverflowError, posix.sched_setaffinity, 0, [1<<128]) self.assertRaises(OverflowError, posix.sched_setaffinity, 0, [1<<128])