summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux/symlink.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/syscalls/linux/symlink.cc')
-rw-r--r--test/syscalls/linux/symlink.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/syscalls/linux/symlink.cc b/test/syscalls/linux/symlink.cc
index a17ff62e9..aa1f32c85 100644
--- a/test/syscalls/linux/symlink.cc
+++ b/test/syscalls/linux/symlink.cc
@@ -218,6 +218,35 @@ TEST(SymlinkTest, PreadFromSymlink) {
EXPECT_THAT(unlink(linkname.c_str()), SyscallSucceeds());
}
+TEST(SymlinkTest, PwriteToSymlink) {
+ std::string name = NewTempAbsPath();
+ int fd;
+ ASSERT_THAT(fd = open(name.c_str(), O_CREAT, 0644), SyscallSucceeds());
+ ASSERT_THAT(close(fd), SyscallSucceeds());
+
+ std::string linkname = NewTempAbsPath();
+ ASSERT_THAT(symlink(name.c_str(), linkname.c_str()), SyscallSucceeds());
+
+ ASSERT_THAT(fd = open(linkname.c_str(), O_WRONLY), SyscallSucceeds());
+
+ const int data_size = 10;
+ const std::string data = std::string(data_size, 'a');
+ EXPECT_THAT(pwrite64(fd, data.c_str(), data.size(), 0), SyscallSucceedsWithValue(data.size()));
+
+ ASSERT_THAT(close(fd), SyscallSucceeds());
+ ASSERT_THAT(fd = open(name.c_str(), O_RDONLY), SyscallSucceeds());
+
+ char buf[data_size+1];
+ EXPECT_THAT(pread64(fd, buf, data.size(), 0), SyscallSucceeds());
+ buf[data.size()] = '\0';
+ EXPECT_STREQ(buf, data.c_str());
+
+ ASSERT_THAT(close(fd), SyscallSucceeds());
+
+ EXPECT_THAT(unlink(name.c_str()), SyscallSucceeds());
+ EXPECT_THAT(unlink(linkname.c_str()), SyscallSucceeds());
+}
+
TEST(SymlinkTest, SymlinkAtDegradedPermissions_NoRandomSave) {
// Drop capabilities that allow us to override file and directory permissions.
ASSERT_NO_ERRNO(SetCapability(CAP_DAC_OVERRIDE, false));