From 7e75cb107b08329dc3b49d82d469674aaef6372c Mon Sep 17 00:00:00 2001 From: Konstantin Bogomolov Date: Fri, 9 Feb 2024 16:15:50 -0800 Subject: [PATCH] Fix flaky inotify exec test. I believe in some cases some other process/thread in the testsuite also uses /bin/true, and happens to generate more events than expected. PiperOrigin-RevId: 605760072 --- test/syscalls/linux/inotify.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/syscalls/linux/inotify.cc b/test/syscalls/linux/inotify.cc index 193f78031..20deb5caf 100644 --- a/test/syscalls/linux/inotify.cc +++ b/test/syscalls/linux/inotify.cc @@ -1987,14 +1987,18 @@ TEST(Inotify, Xattr) { TEST(Inotify, Exec) { const FileDescriptor fd = ASSERT_NO_ERRNO_AND_VALUE(InotifyInit1(IN_NONBLOCK)); - const int wd = ASSERT_NO_ERRNO_AND_VALUE( - InotifyAddWatch(fd.get(), "/bin/true", IN_ALL_EVENTS)); + // Create a new executable file instead of using /bin/true directly in case + // the test suite uses it at any point and generates extra events. + TempPath p = ASSERT_NO_ERRNO_AND_VALUE( + TempPath::CreateFileWith(GetAbsoluteTestTmpdir(), "#!/bin/true", 0755)); + const int wd = ASSERT_NO_ERRNO_AND_VALUE( + InotifyAddWatch(fd.get(), p.path(), IN_ALL_EVENTS)); // Perform exec. pid_t child = -1; int execve_errno = -1; auto kill = ASSERT_NO_ERRNO_AND_VALUE( - ForkAndExec("/bin/true", {}, {}, nullptr, &child, &execve_errno)); + ForkAndExec(p.path(), {}, {}, nullptr, &child, &execve_errno)); ASSERT_EQ(0, execve_errno); int status;