Skip to content

Commit 283a077

Browse files
committed
Allow libc to use different fstat variants
Running on my dev machine, ArchLinux, get fstat while Ubuntu CI machine finds newfstatat
1 parent ef298f2 commit 283a077

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Lib/test/test_fileio.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,14 @@ def test_syscalls_read(self):
383383
""",
384384
_strace_flags
385385
)
386-
self.assertEqual(calls, ['openat', 'fstat', 'ioctl', 'lseek',
387-
'lseek', 'fstat', 'read', 'read', 'close'])
386+
387+
# There are a number of related syscalls used to implement `fstat` in
388+
# a libc (ex. fstat, newfstatat). Default to fstat, but if we see the
389+
# system using a variant, allow that
390+
fstat = next((sc for sc in calls if 'fstat' in sc), 'fstat')
391+
392+
self.assertEqual(calls, ['openat', fstat, 'ioctl', 'lseek',
393+
'lseek', fstat, 'read', 'read', 'close'])
388394

389395
# Focus on just `read()`
390396
calls = strace_helper.get_syscalls(
@@ -393,7 +399,7 @@ def test_syscalls_read(self):
393399
cleanup="f.close()",
394400
strace_flags=_strace_flags
395401
)
396-
self.assertEqual(calls, ['lseek', 'fstat', 'read', 'read'])
402+
self.assertEqual(calls, ['lseek', fstat, 'read', 'read'])
397403

398404
# Readall in binary mode
399405
calls = strace_helper.get_syscalls(
@@ -404,8 +410,8 @@ def test_syscalls_read(self):
404410
""",
405411
_strace_flags
406412
)
407-
self.assertEqual(calls, ['openat', 'fstat', 'ioctl', 'lseek', 'lseek',
408-
'fstat', 'read', 'read', 'close'])
413+
self.assertEqual(calls, ['openat', fstat, 'ioctl', 'lseek', 'lseek',
414+
fstat, 'read', 'read', 'close'])
409415

410416
# Readall in text mode
411417
calls = strace_helper.get_syscalls(
@@ -416,8 +422,8 @@ def test_syscalls_read(self):
416422
""",
417423
_strace_flags
418424
)
419-
self.assertEqual(calls, ['openat', 'fstat', 'ioctl', 'lseek', 'lseek',
420-
'fstat', 'read', 'read', 'close'])
425+
self.assertEqual(calls, ['openat', fstat, 'ioctl', 'lseek', 'lseek',
426+
fstat, 'read', 'read', 'close'])
421427

422428

423429
class CAutoFileTests(AutoFileTests, unittest.TestCase):

0 commit comments

Comments
 (0)