8000 gh-108277: Fix test_os TimerfdTests · python/cpython@5f17c7c · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f17c7c

Browse files
committed
gh-108277: Fix test_os TimerfdTests
* test_timerfd_TFD_TIMER_ABSTIME() and test_timerfd_ns_TFD_TIMER_ABSTIME() tolerate a difference of 50 us. * test_timerfd_negative() checks if os.TFD_TIMER_CANCEL_ON_SET is defined.
1 parent 8e56d55 commit 5f17c7c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Lib/test/test_os.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,6 +3929,10 @@ def test_eventfd_select(self):
39293929
@unittest.skipUnless(hasattr(os, 'timerfd_create'), 'requires os.timerfd_create')
39303930
@support.requires_linux_version(2, 6, 30)
39313931
class TimerfdTests(unittest.TestCase):
3932+
# Tolerate a difference of 50 us
3933+
CLOCK_RES_NS = 50_000
3934+
CLOCK_RES = CLOCK_RES_NS * 1e-9
3935+
39323936
def timerfd_create(self, *args, **kwargs):
39333937
fd = os.timerfd_create(*args, **kwargs)
39343938
self.assertGreaterEqual(fd, 0)
@@ -3982,9 +3986,13 @@ def test_timerfd_negative(self):
39823986
one_sec_in_nsec = 10**9
39833987
fd = self.timerfd_create(time.CLOCK_REALTIME)
39843988

3989+
test_flags = [0, os.TFD_TIMER_ABSTIME]
3990+
if hasattr(os, 'TFD_TIMER_CANCEL_ON_SET'):
3991+
test_flags.append(os.TFD_TIMER_ABSTIME | os.TFD_TIMER_CANCEL_ON_SET)
3992+
39853993
# Any of 'initial' and 'interval' is negative value.
39863994
for initial, interval in ( (-1, 0), (1, -1), (-1, -1), (-0.1, 0), (1, -0.1), (-0.1, -0.1)):
3987-
for flags in (0, os.TFD_TIMER_ABSTIME, os.TFD_TIMER_ABSTIME|os.TFD_TIMER_CANCEL_ON_SET):
3995+
for flags in test_flags:
39883996
with self.subTest(flags=flags, initial=initial, interval=interval):
39893997
with self.assertRaises(OSError) as context:
39903998
_, _ = os.timerfd_settime(fd, flags=flags, initial=initial, interval=interval)
@@ -4055,7 +4063,7 @@ def test_timerfd_TFD_TIMER_ABSTIME(self):
40554063
t = time.perf_counter() - t
40564064
self.assertEqual(count_signaled, 1)
40574065

4058-
self.assertGreater(t, offset)
4066+
self.assertGreater(t, offset - self.CLOCK_RES)
40594067

40604068
def test_timerfd_select(self):
40614069
size = 8 # read 8 bytes
@@ -4208,7 +4216,7 @@ def test_timerfd_ns_TFD_TIMER_ABSTIME(self):
42084216
t = time.perf_counter_ns() - t
42094217
self.assertEqual(count_signaled, 1)
42104218

4211-
self.assertGreater(t, offset_ns)
4219+
self.assertGreater(t, offset_ns - self.CLOCK_RES_NS)
42124220

42134221
def test_timerfd_ns_select(self):
42144222
size = 8 # read 8 bytes

0 commit comments

Comments
 (0)
0