1313import locale
1414import os
1515import pickle
16+ import platform
1617import select
1718import selectors
1819import shutil
@@ -4085,9 +4086,15 @@ def test_eventfd_select(self):
40854086@unittest .skipUnless (hasattr (os , 'timerfd_create' ), 'requires os.timerfd_create' )
40864087@support .requires_linux_version (2 , 6 , 30 )
40874088class 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 )
40914098
40924099 def timerfd_create (self , * args , ** kwargs ):
40934100 fd = os .timerfd_create (* args , ** kwargs )
@@ -4109,18 +4116,18 @@ def test_timerfd_initval(self):
41094116
41104117 # 1st call
41114118 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 )
41144121
41154122 # 2nd call
41164123 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 )
41194126
41204127 # timerfd_gettime
41214128 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 )
41244131
41254132 def test_timerfd_non_blocking (self ):
41264133 fd = self .timerfd_create (time .CLOCK_REALTIME , flags = os .TFD_NONBLOCK )
@@ -4174,8 +4181,8 @@ def test_timerfd_interval(self):
41744181
41754182 # timerfd_gettime
41764183 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 )
41794186
41804187 count = 3
41814188 t = time .perf_counter ()
@@ -4206,8 +4213,8 @@ def test_timerfd_TFD_TIMER_ABSTIME(self):
42064213 # timerfd_gettime
42074214 # Note: timerfd_gettime returns relative values even if TFD_TIMER_ABSTIME is specified.
42084215 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 )
42114218
42124219 t = time .perf_counter ()
42134220 count_signaled = self .read_count_signaled (fd )
0 commit comments