13
13
import locale
14
14
import os
15
15
import pickle
16
+ import platform
16
17
import select
17
18
import selectors
18
19
import shutil
@@ -4085,9 +4086,15 @@ def test_eventfd_select(self):
4085
4086
@unittest .skipUnless (hasattr (os , 'timerfd_create' ), 'requires os.timerfd_create' )
4086
4087
@support .requires_linux_version (2 , 6 , 30 )
4087
4088
class TimerfdTests (unittest .TestCase ):
4088
- # Tolerate a difference of 1 ms
4089
- CLOCK_RES_NS = 1_000_000
4090
- CLOCK_RES = CLOCK_RES_NS * 1e-9
4089
+ # 1 ms accuracy is reliably achievable on every platform except Android
4090
+ # emulators, where we allow 10 ms (gh-108277).
4091
+ if sys .platform == "android" and platform .android_ver ().is_emulator :
4092
+ CLOCK_RES_PLACES = 2
4093
+ else :
4094
+ CLOCK_RES_PLACES = 3
4095
+
4096
+ CLOCK_RES = 10 ** - CLOCK_RES_PLACES
4097
+ CLOCK_RES_NS = 10 ** (9 - CLOCK_RES_PLACES )
4091
4098
4092
4099
def timerfd_create (self , * args , ** kwargs ):
4093
4100
fd = os .timerfd_create (* args , ** kwargs )
@@ -4109,18 +4116,18 @@ def test_timerfd_initval(self):
4109
4116
4110
4117
# 1st call
4111
4118
next_expiration , interval2 = os .timerfd_settime (fd , initial = initial_expiration , interval = interval )
4112
- self .assertAlmostEqual (interval2 , 0.0 , places = 3 )
4113
- self .assertAlmostEqual (next_expiration , 0.0 , places = 3 )
4119
+ self .assertAlmostEqual (interval2 , 0.0 , places = self . CLOCK_RES_PLACES )
4120
+ self .assertAlmostEqual (next_expiration , 0.0 , places = self . CLOCK_RES_PLACES )
4114
4121
4115
4122
# 2nd call
4116
4123
next_expiration , interval2 = os .timerfd_settime (fd , initial = initial_expiration , interval = interval )
4117
- self .assertAlmostEqual (interval2 , interval , places = 3 )
4118
- self .assertAlmostEqual (next_expiration , initial_expiration , places = 3 )
4124
+ self .assertAlmostEqual (interval2 , interval , places = self . CLOCK_RES_PLACES )
4125
+ self .assertAlmostEqual (next_expiration , initial_expiration , places = self . CLOCK_RES_PLACES )
4119
4126
4120
4127
# timerfd_gettime
4121
4128
next_expiration , interval2 = os .timerfd_gettime (fd )
4122
- self .assertAlmostEqual (interval2 , interval , places = 3 )
4123
- self .assertAlmostEqual (next_expiration , initial_expiration , places = 3 )
4129
+ self .assertAlmostEqual (interval2 , interval , places = self . CLOCK_RES_PLACES )
4130
+ self .assertAlmostEqual (next_expiration , initial_expiration , places = self . CLOCK_RES_PLACES )
4124
4131
4125
4132
def test_timerfd_non_blocking (self ):
4126
4133
fd = self .timerfd_create (time .CLOCK_REALTIME , flags = os .TFD_NONBLOCK )
@@ -4174,8 +4181,8 @@ def test_timerfd_interval(self):
4174
4181
4175
4182
# timerfd_gettime
4176
4183
next_expiration , interval2 = os .timerfd_gettime (fd )
4177
- self .assertAlmostEqual (interval2 , interval , places = 3 )
4178
- self .assertAlmostEqual (next_expiration , initial_expiration , places = 3 )
4184
+ self .assertAlmostEqual (interval2 , interval , places = self . CLOCK_RES_PLACES )
4185
+ self .assertAlmostEqual (next_expiration , initial_expiration , places = self . CLOCK_RES_PLACES )
4179
4186
4180
4187
count = 3
4181
4188
t = time .perf_counter ()
@@ -4206,8 +4213,8 @@ def test_timerfd_TFD_TIMER_ABSTIME(self):
4206
4213
# timerfd_gettime
4207
4214
# Note: timerfd_gettime returns relative values even if TFD_TIMER_ABSTIME is specified.
4208
4215
next_expiration , interval2 = os .timerfd_gettime (fd )
4209
- self .assertAlmostEqual (interval2 , interval , places = 3 )
4210
- self .assertAlmostEqual (next_expiration , offset , places = 3 )
4216
+ self .assertAlmostEqual (interval2 , interval , places = self . CLOCK_RES_PLACES )
4217
+ self .assertAlmostEqual (next_expiration , offset , places = self . CLOCK_RES_PLACES )
4211
4218
4212
4219
t = time .perf_counter ()
4213
4220
count_signaled = self .read_count_signaled (fd )
0 commit comments