From 99195b0e166536dd81c7096c0dc0f2cc527f1553 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Thu, 28 Mar 2019 14:14:13 -0700 Subject: Setting timestamps should trigger an inotify event. PiperOrigin-RevId: 240850187 Change-Id: I1458581b771a1031e47bba439e480829794927b8 --- test/syscalls/linux/inotify.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/syscalls') diff --git a/test/syscalls/linux/inotify.cc b/test/syscalls/linux/inotify.cc index 88997094c..b99d339e5 100644 --- a/test/syscalls/linux/inotify.cc +++ b/test/syscalls/linux/inotify.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -1232,6 +1233,26 @@ TEST(Inotify, LinkGeneratesAttribAndCreateEvents) { Event(IN_CREATE, root_wd, Basename(link1.path()))})); } +TEST(Inotify, UtimesGeneratesAttribEvent) { + const TempPath root = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); + const FileDescriptor fd = + ASSERT_NO_ERRNO_AND_VALUE(InotifyInit1(IN_NONBLOCK)); + const TempPath file1 = + ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileIn(root.path())); + + const FileDescriptor file1_fd = + ASSERT_NO_ERRNO_AND_VALUE(Open(file1.path(), O_RDWR)); + const int wd = ASSERT_NO_ERRNO_AND_VALUE( + InotifyAddWatch(fd.get(), root.path(), IN_ALL_EVENTS)); + + struct timeval times[2] = {{1, 0}, {2, 0}}; + EXPECT_THAT(futimes(file1_fd.get(), times), SyscallSucceeds()); + + const std::vector events = + ASSERT_NO_ERRNO_AND_VALUE(DrainEvents(fd.get())); + ASSERT_THAT(events, Are({Event(IN_ATTRIB, wd, Basename(file1.path()))})); +} + TEST(Inotify, HardlinksReuseSameWatch) { const TempPath root = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir()); TempPath file1 = -- cgit v1.2.3