summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/symlink.cc
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2020-05-13 17:35:04 -0700
committergVisor bot <gvisor-bot@google.com>2020-05-13 17:36:37 -0700
commitdb655f020ea556524f0e341e538e81c16d4f95e7 (patch)
tree0929921ff64e14b7f7329c8e4d59fe5ca744c873 /test/syscalls/linux/symlink.cc
parent8605c97136ab798e23d0ae4e85892270d8922b4d (diff)
Resolve remaining TODOs for tmpfs.
Closes #1197 PiperOrigin-RevId: 311438223
Diffstat (limited to 'test/syscalls/linux/symlink.cc')
-rw-r--r--test/syscalls/linux/symlink.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/syscalls/linux/symlink.cc b/test/syscalls/linux/symlink.cc
index 03ee1250d..a17ff62e9 100644
--- a/test/syscalls/linux/symlink.cc
+++ b/test/syscalls/linux/symlink.cc
@@ -20,6 +20,7 @@
#include <string>
#include "gtest/gtest.h"
+#include "absl/time/clock.h"
#include "test/util/capability_util.h"
#include "test/util/file_descriptor.h"
#include "test/util/fs_util.h"
@@ -272,6 +273,30 @@ TEST(SymlinkTest, ChmodSymlink) {
EXPECT_EQ(FilePermission(newpath), 0777);
}
+// Test that following a symlink updates the atime on the symlink.
+TEST(SymlinkTest, FollowUpdatesATime) {
+ const auto file = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFile());
+ const std::string link = NewTempAbsPath();
+ EXPECT_THAT(symlink(file.path().c_str(), link.c_str()), SyscallSucceeds());
+
+ // Lstat the symlink.
+ struct stat st_before_follow;
+ ASSERT_THAT(lstat(link.c_str(), &st_before_follow), SyscallSucceeds());
+
+ // Let the clock advance.
+ absl::SleepFor(absl::Seconds(1));
+
+ // Open the file via the symlink.
+ int fd;
+ ASSERT_THAT(fd = open(link.c_str(), O_RDWR, 0666), SyscallSucceeds());
+ FileDescriptor fd_closer(fd);
+
+ // Lstat the symlink again, and check that atime is updated.
+ struct stat st_after_follow;
+ ASSERT_THAT(lstat(link.c_str(), &st_after_follow), SyscallSucceeds());
+ EXPECT_LT(st_before_follow.st_atime, st_after_follow.st_atime);
+}
+
class ParamSymlinkTest : public ::testing::TestWithParam<std::string> {};
// Test that creating an existing symlink with creat will create the target.