Skip to content

Commit

Permalink
pythongh-117061: Fix test_posix.test_sched_setaffinity() on RHEL9
Browse files Browse the repository at this point in the history
On RHEL9, sched_setaffinity(0, []) does not fail.
  • Loading branch information
vstinner committed Mar 21, 2024
1 parent e728303 commit 4ece34c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,12 +1335,23 @@ def test_sched_getaffinity(self):
def test_sched_setaffinity(self):
mask = posix.sched_getaffinity(0)
self.addCleanup(posix.sched_setaffinity, 0, list(mask))

if len(mask) > 1:
# Empty masks are forbidden
mask.pop()
posix.sched_setaffinity(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
except Exception as exc:
self.fail("unexpected exception: {exc!r}")

self.assertRaises(ValueError, posix.sched_setaffinity, 0, [-10])
self.assertRaises(ValueError, posix.sched_setaffinity, 0, map(int, "0X"))
self.assertRaises(OverflowError, posix.sched_setaffinity, 0, [1<<128])
Expand Down

0 comments on commit 4ece34c

Please sign in to comment.