diff options
author | Benjamin Peterson <benjamin@python.org> | 2018-09-12 22:12:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 22:12:24 (GMT) |
commit | c7042224b8a67748f125c22836862483f81a87a6 (patch) | |
tree | 2c5de2a4128f555e59add6af3f42eeb60d8ac51e /Lib/test | |
parent | 6f82bffd2df63a4072b3f0483cdbe93ddedb87e9 (diff) | |
download | cpython-c7042224b8a67748f125c22836862483f81a87a6.zip cpython-c7042224b8a67748f125c22836862483f81a87a6.tar.gz cpython-c7042224b8a67748f125c22836862483f81a87a6.tar.bz2 |
closes bpo-34650: Check if sched_getscheduler returns ENOSYS before declaring it supported. (GH-9228)
musl doesn't support the scheduler API, but declares stubs that alway return ENOSYS.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_posix.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 7a2fc26..d402d4f 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -25,6 +25,18 @@ _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(), requires_32b = unittest.skipUnless(sys.maxsize < 2**32, 'test is only meaningful on 32-bit builds') +def _supports_sched(): + if not hasattr(posix, 'sched_getscheduler'): + return False + try: + posix.sched_getscheduler(0) + except OSError as e: + if e.errno == errno.ENOSYS: + return False + return True + +requires_sched = unittest.skipUnless(_supports_sched(), 'requires POSIX scheduler API') + class PosixTester(unittest.TestCase): def setUp(self): @@ -1273,7 +1285,7 @@ class PosixTester(unittest.TestCase): self.assertRaises(OSError, posix.sched_get_priority_min, -23) self.assertRaises(OSError, posix.sched_get_priority_max, -23) - @unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler") + @requires_sched def test_get_and_set_scheduler_and_param(self): possible_schedulers = [sched for name, sched in posix.__dict__.items() if name.startswith("SCHED_")] @@ -1646,7 +1658,7 @@ class TestPosixSpawn(unittest.TestCase): [sys.executable, "-c", "pass"], os.environ, setsigdef=[signal.NSIG, signal.NSIG+1]) - @unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler") + @requires_sched def test_setscheduler_only_param(self): policy = os.sched_getscheduler(0) priority = os.sched_get_priority_min(policy) @@ -1664,7 +1676,7 @@ class TestPosixSpawn(unittest.TestCase): ) self.assertEqual(os.waitpid(pid, 0), (pid, 0)) - @unittest.skipUnless(hasattr(posix, 'sched_setscheduler'), "can't change scheduler") + @requires_sched def test_setscheduler_with_policy(self): policy = os.sched_getscheduler(0) priority = os.sched_get_priority_min(policy) |