From bd836b9ecbdf7110d3e953fe1f5d6065087b7975 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 11 Nov 2024 12:58:02 -0600 Subject: [PATCH] fuse unit tests and fixes --- .../src/fuse_drive_create_and_open_test.cpp | 294 +++++++++++++----- 1 file changed, 224 insertions(+), 70 deletions(-) diff --git a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp index f7eca296..0ef24ce5 100644 --- a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp @@ -60,6 +60,7 @@ TYPED_TEST(fuse_test, create_can_create_file_with_specific_perms) { this->unlink_file_and_test(file_path); } +// 1. Create File - O_CREAT TYPED_TEST(fuse_test, create_can_create_file) { std::string file_name{"create_test"}; auto file_path = this->create_file_path(file_name); @@ -71,28 +72,7 @@ TYPED_TEST(fuse_test, create_can_create_file) { this->unlink_file_and_test(file_path); } -TYPED_TEST(fuse_test, create_can_create_file_ro) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_RDONLY, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} - -TYPED_TEST(fuse_test, create_can_create_file_rw) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_RDWR, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} - +// 2. Create File - O_CREAT | O_WRONLY TYPED_TEST(fuse_test, create_can_create_file_wo) { std::string file_name{"create_test"}; auto file_path = this->create_file_path(file_name); @@ -104,17 +84,19 @@ TYPED_TEST(fuse_test, create_can_create_file_wo) { this->unlink_file_and_test(file_path); } -TYPED_TEST(fuse_test, create_can_create_file_for_append) { +// 3. Create File - O_CREAT | O_RDWR +TYPED_TEST(fuse_test, create_can_create_file_rw) { std::string file_name{"create_test"}; auto file_path = this->create_file_path(file_name); - auto handle = open(file_path.c_str(), O_CREAT | O_APPEND, ACCESSPERMS); + auto handle = open(file_path.c_str(), O_CREAT | O_RDWR, ACCESSPERMS); EXPECT_LE(1, handle); close(handle); this->unlink_file_and_test(file_path); } +// 4. Create File - O_CREAT | O_TRUNC TYPED_TEST(fuse_test, create_can_create_with_truncate_file) { std::string file_name{"create_test"}; auto file_path = this->create_file_path(file_name); @@ -130,7 +112,176 @@ TYPED_TEST(fuse_test, create_can_create_with_truncate_file) { this->unlink_file_and_test(file_path); } -TYPED_TEST(fuse_test, create_can_create_or_open_and_truncate_existing_file) { +// 5. Create File - O_CREAT | O_TRUNC | O_WRONLY +TYPED_TEST(fuse_test, create_can_create_with_truncate_file_wo) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = + open(file_path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + auto size = utils::file::file{file_path}.size(); + EXPECT_TRUE(size.has_value()); + EXPECT_EQ(0U, *size); + + this->unlink_file_and_test(file_path); +} + +// 6. Create File - O_CREAT | O_TRUNC | O_RDWR +TYPED_TEST(fuse_test, create_can_create_with_truncate_file_rw) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = + open(file_path.c_str(), O_CREAT | O_TRUNC | O_RDWR, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + auto size = utils::file::file{file_path}.size(); + EXPECT_TRUE(size.has_value()); + EXPECT_EQ(0U, *size); + + this->unlink_file_and_test(file_path); +} + +// 7. Create File - O_CREAT | O_APPEND +TYPED_TEST(fuse_test, create_can_create_file_for_append) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = open(file_path.c_str(), O_CREAT | O_APPEND, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 8. Create File - O_CREAT | O_APPEND | O_WRONLY +TYPED_TEST(fuse_test, create_can_create_file_for_append_wo) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = + open(file_path.c_str(), O_CREAT | O_APPEND | O_WRONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 9. Create File - O_CREAT | O_EXCL | O_WRONLY (file does not exist) +TYPED_TEST(fuse_test, create_can_create_file_excl_wo) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = + open(file_path.c_str(), O_CREAT | O_EXCL | O_WRONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 10. Create File - O_CREAT | O_EXCL | O_RDWR (file does not exist) +TYPED_TEST(fuse_test, create_can_create_file_excl_rw) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = open(file_path.c_str(), O_CREAT | O_EXCL | O_RDWR, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 11. Create File - O_CREAT | O_EXCL (file does not exist) +TYPED_TEST(fuse_test, create_can_create_file_excl) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_path(file_name); + + auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 1. Open Existing File - O_RDONLY +TYPED_TEST(fuse_test, create_can_open_existing_file_ro) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_RDONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 2. Open Existing File - O_WRONLY +TYPED_TEST(fuse_test, create_can_open_existing_file_wo) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_WRONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 3. Open Existing File - O_RDWR +TYPED_TEST(fuse_test, create_can_open_existing_file_rw) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_RDWR, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 4. Open Existing File - O_APPEND +TYPED_TEST(fuse_test, create_can_open_existing_file_for_append) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_APPEND, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 5. Open Existing File - O_APPEND | O_WRONLY +TYPED_TEST(fuse_test, create_can_open_existing_file_for_append_wo) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_APPEND | O_WRONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 6. Open Existing File - O_APPEND | O_RDWR +TYPED_TEST(fuse_test, create_can_open_existing_file_for_append_rw) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_APPEND | O_RDWR, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 7. Open Existing File - O_TRUNC | O_WRONLY +TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file_wo) { std::string file_name{"create_test"}; auto file_path = this->create_file_and_test(file_name); EXPECT_EQ(0, truncate(file_path.c_str(), 24U)); @@ -139,7 +290,7 @@ TYPED_TEST(fuse_test, create_can_create_or_open_and_truncate_existing_file) { EXPECT_TRUE(size.has_value()); EXPECT_EQ(24U, *size); - auto handle = open(file_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS); + auto handle = open(file_path.c_str(), O_TRUNC | O_WRONLY, ACCESSPERMS); EXPECT_LE(1, handle); close(handle); @@ -150,6 +301,28 @@ TYPED_TEST(fuse_test, create_can_create_or_open_and_truncate_existing_file) { this->unlink_file_and_test(file_path); } +// 8. Open Existing File - O_TRUNC | O_RDWR +TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file_rw) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + EXPECT_EQ(0, truncate(file_path.c_str(), 24U)); + + auto size = utils::file::file{file_path}.size(); + EXPECT_TRUE(size.has_value()); + EXPECT_EQ(24U, *size); + + auto handle = open(file_path.c_str(), O_TRUNC | O_RDWR, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + size = utils::file::file{file_path}.size(); + EXPECT_TRUE(size.has_value()); + EXPECT_EQ(0U, *size); + + this->unlink_file_and_test(file_path); +} + +// 9. Open Existing File - O_TRUNC TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file) { std::string file_name{"create_test"}; auto file_path = this->create_file_and_test(file_name); @@ -170,6 +343,31 @@ TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file) { this->unlink_file_and_test(file_path); } +// 10. Open Existing File - O_EXCL | O_WRONLY (file does not exist) +TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl_wr) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_EXCL | O_WRONLY, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 11. Open Existing File - O_EXCL | O_RDWR (file does not exist) +TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl_rw) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + + auto handle = open(file_path.c_str(), O_EXCL | O_RDWR, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +// 12. Open Existing File - O_EXCL (file does not exist): TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) { std::string file_name{"create_test"}; auto file_path = this->create_file_and_test(file_name); @@ -180,50 +378,6 @@ TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) { this->unlink_file_and_test(file_path); } - -TYPED_TEST(fuse_test, create_can_open_existing_file_ro) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_and_test(file_name); - - auto handle = open(file_path.c_str(), O_RDONLY, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} - -TYPED_TEST(fuse_test, create_can_open_existing_file_rw) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_and_test(file_name); - - auto handle = open(file_path.c_str(), O_RDWR, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} - -TYPED_TEST(fuse_test, create_can_open_existing_file_wo) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_and_test(file_name); - - auto handle = open(file_path.c_str(), O_WRONLY, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} - -TYPED_TEST(fuse_test, create_can_open_existing_file_for_append) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_and_test(file_name); - - auto handle = open(file_path.c_str(), O_APPEND, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} } // namespace repertory #endif // !defined(_WIN32)