summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/BUILD (renamed from test/BUILD.opensource)2
-rw-r--r--test/syscalls/linux/rename.cc25
2 files changed, 24 insertions, 3 deletions
diff --git a/test/BUILD.opensource b/test/BUILD
index 8d2969204..6b83757f6 100644
--- a/test/BUILD.opensource
+++ b/test/BUILD
@@ -1,6 +1,6 @@
# gVisor is a general-purpose sandbox.
-licenses(["notice"])
+package(licenses = ["notice"])
exports_files(["LICENSE"])
diff --git a/test/syscalls/linux/rename.cc b/test/syscalls/linux/rename.cc
index f4c877a00..c0cbc7cd9 100644
--- a/test/syscalls/linux/rename.cc
+++ b/test/syscalls/linux/rename.cc
@@ -155,10 +155,11 @@ TEST(RenameTest, DirectoryToOwnChildDirectory) {
}
TEST(RenameTest, FileOverwritesFile) {
+ auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
auto f1 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileWith(
- GetAbsoluteTestTmpdir(), "first", TempPath::kDefaultFileMode));
+ dir.path(), "first", TempPath::kDefaultFileMode));
auto f2 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateFileWith(
- GetAbsoluteTestTmpdir(), "second", TempPath::kDefaultFileMode));
+ dir.path(), "second", TempPath::kDefaultFileMode));
ASSERT_THAT(rename(f1.path().c_str(), f2.path().c_str()), SyscallSucceeds());
EXPECT_THAT(Exists(f1.path()), IsPosixErrorOkAndHolds(false));
@@ -168,6 +169,26 @@ TEST(RenameTest, FileOverwritesFile) {
EXPECT_EQ("first", f2_contents);
}
+TEST(RenameTest, DirectoryOverwritesDirectoryLinkCount) {
+ auto parent1 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
+ EXPECT_THAT(Links(parent1.path()), IsPosixErrorOkAndHolds(2));
+
+ auto parent2 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
+ EXPECT_THAT(Links(parent2.path()), IsPosixErrorOkAndHolds(2));
+
+ auto dir1 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDirIn(parent1.path()));
+ auto dir2 = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDirIn(parent2.path()));
+
+ EXPECT_THAT(Links(parent1.path()), IsPosixErrorOkAndHolds(3));
+ EXPECT_THAT(Links(parent2.path()), IsPosixErrorOkAndHolds(3));
+
+ ASSERT_THAT(rename(dir1.path().c_str(), dir2.path().c_str()),
+ SyscallSucceeds());
+
+ EXPECT_THAT(Links(parent1.path()), IsPosixErrorOkAndHolds(2));
+ EXPECT_THAT(Links(parent2.path()), IsPosixErrorOkAndHolds(3));
+}
+
TEST(RenameTest, FileDoesNotExist) {
auto dir = ASSERT_NO_ERRNO_AND_VALUE(TempPath::CreateDir());
const std::string source = JoinPath(dir.path(), "source");