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
This commit is contained in:
Konstantin Bogomolov
2024-02-09 16:19:20 -08:00
committed by gVisor bot
parent a3c06e8493
commit 7e75cb107b
+7 -3
View File
@@ -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;