From 8ebf66a686a715b17a3a055aae457ff30647a70e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 11 Nov 2024 19:54:56 -0600 Subject: [PATCH] fuse unit tests and fixes --- .../src/fuse_drive_create_and_open_test.cpp | 292 +++++------------- 1 file changed, 70 insertions(+), 222 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 ed184b42..12615525 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 @@ -22,7 +22,6 @@ #if !defined(_WIN32) #include "fixtures/fuse_fixture.hpp" - namespace repertory { TYPED_TEST_CASE(fuse_test, fuse_provider_types); @@ -367,240 +366,89 @@ TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl_rw) { 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); - - auto handle = open(file_path.c_str(), O_EXCL, ACCESSPERMS); - EXPECT_LE(1, handle); - close(handle); - - this->unlink_file_and_test(file_path); -} - -// 1. O_CREAT-Failure: ENOENT (No such file or directory) if the parent -// directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_if_parent_does_not_exist) { - std::string file_name{"no_dir/create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 1. O_CREAT-Failure: EISDIR (Is a directory) if a directory exists instead of -// a file. -TYPED_TEST(fuse_test, create_fails_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = open(dir_path.c_str(), O_CREAT, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); -} - -// 2. O_CREAT|O_TRUNC-Failure: ENOENT (No such file or directory) if the parent -// directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_trunc_if_parent_does_not_exist) { - std::string file_name{"no_dir/create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 2. O_CREAT|O_TRUNC-Failure: EISDIR (Is a directory) if a directory exists -// instead of a file. -TYPED_TEST(fuse_test, create_fails_with_trunc_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = open(dir_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); -} - -// 3. O_CREAT|O_EXCL-Failure: ENOENT (No such file or directory) if the parent -// directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_excl_if_parent_does_not_exist) { - std::string file_name{"no_dir/create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 3. O_CREAT|O_EXCL-Failure: EEXIST (File exists) if the file already exists. -TYPED_TEST(fuse_test, create_fails_with_excl_if_file_exists) { - std::string file_name{"create_test"}; - auto file_path = this->create_file_and_test(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EEXIST, errno); - - this->unlink_file_and_test(file_path); -} - -// 3. O_CREAT|O_EXCL-Failure: EEXIST (File exists) if the file or directory -// already exists. TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) { + std::array ops{ + O_CREAT | O_EXCL, + O_CREAT | O_EXCL | O_RDWR, + O_CREAT | O_EXCL | O_WRONLY, + }; + std::string dir_name{"create_test"}; auto dir_path = this->create_directory_and_test(dir_name); - auto handle = open(dir_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS); - EXPECT_EQ(-1, handle); + for (auto &&mode : ops) { + auto handle = open(dir_path.c_str(), mode, ACCESSPERMS); + EXPECT_EQ(-1, handle); - EXPECT_EQ(EEXIST, errno); + EXPECT_EQ(EEXIST, errno); + } this->rmdir_and_test(dir_path); } -// 4. O_CREAT | O_APPEND-Failure: ENOENT (No such file or directory) if the -// parent directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_append_if_parent_does_not_exist) { +TYPED_TEST(fuse_test, create_fails_with_excl_if_file_exists) { + std::array ops{ + O_CREAT | O_EXCL, + O_CREAT | O_EXCL | O_RDWR, + O_CREAT | O_EXCL | O_WRONLY, + }; + + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + for (auto &&mode : ops) { + auto handle = open(file_path.c_str(), mode, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EEXIST, errno); + } + this->unlink_file_and_test(file_path); +} + +TYPED_TEST(fuse_test, create_fails_if_path_is_directory) { + std::array ops{ + O_CREAT | O_APPEND, + O_CREAT | O_RDWR, + O_CREAT | O_TRUNC | O_RDWR, + O_CREAT | O_TRUNC | O_WRONLY, + O_CREAT | O_TRUNC, + O_CREAT | O_WRONLY, + O_CREAT, + }; + + std::string dir_name{"create_test"}; + auto dir_path = this->create_directory_and_test(dir_name); + for (auto &&mode : ops) { + auto handle = open(dir_path.c_str(), mode, ACCESSPERMS); + EXPECT_EQ(-1, handle); + + EXPECT_EQ(EISDIR, errno); + } + this->rmdir_and_test(dir_path); +} + +TYPED_TEST(fuse_test, create_fails_if_parent_path_does_not_exist) { + std::array ops{ + O_CREAT | O_APPEND, + O_CREAT | O_EXCL, + O_CREAT | O_EXCL | O_RDWR, + O_CREAT | O_EXCL | O_WRONLY, + O_CREAT | O_RDWR, + O_CREAT | O_TRUNC | O_RDWR, + O_CREAT | O_TRUNC | O_WRONLY, + O_CREAT | O_TRUNC, + O_CREAT | O_WRONLY, + O_CREAT, + }; + std::string file_name{"no_dir/create_test"}; auto file_path = this->create_file_path(file_name); - auto handle = open(file_path.c_str(), O_CREAT | O_APPEND, ACCESSPERMS); - EXPECT_EQ(-1, handle); + for (auto &&mode : ops) { + auto handle = open(file_path.c_str(), mode, ACCESSPERMS); + EXPECT_EQ(-1, handle); - EXPECT_EQ(ENOENT, errno); -} - -// 4. O_CREAT | O_APPEND-Failure: EISDIR (Is a directory) if a directory exists -// instead of a file. -TYPED_TEST(fuse_test, create_fails_with_append_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = open(dir_path.c_str(), O_CREAT | O_APPEND, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); -} - -// 5. O_CREAT | O_RDWR-Failure: ENOENT (No such file or directory) if the -// parent directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_rdrw_if_parent_does_not_exist) { - std::string file_name{"no_dir/create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_RDWR, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 5. O_CREAT | O_RDWR-Failure: EISDIR (Is a directory) if a directory exists -// instead of a file. -TYPED_TEST(fuse_test, create_fails_with_rdrw_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = open(dir_path.c_str(), O_CREAT | O_RDWR, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); -} - -// 6. O_CREAT | O_WRONLY-Failure: ENOENT (No such file or directory) if the -// parent directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_wo_if_parent_does_not_exist) { - std::string file_name{"no_dir/create_test"}; - auto file_path = this->create_file_path(file_name); - - auto handle = open(file_path.c_str(), O_CREAT | O_WRONLY, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 6. O_CREAT | O_WRONLY-Failure: EISDIR (Is a directory) if a directory exists -// instead of a file. -TYPED_TEST(fuse_test, create_fails_with_wo_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = open(dir_path.c_str(), O_CREAT | O_WRONLY, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); -} - -// 7. O_CREAT | O_TRUNC | O_WRONLY-Failure: ENOENT (No such file or directory) -// if the parent directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_trunc_wo_if_parent_does_not_exist) { - std::string file_name{"no_dir/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_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 7. O_CREAT | O_TRUNC | O_WRONLY-Failure: EISDIR (Is a directory) if a -// directory exists instead of a file. -TYPED_TEST(fuse_test, create_fails_with_trunc_wo_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = - open(dir_path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); -} - -// 8. O_CREAT | O_TRUNC | O_RDWR-Failure: ENOENT (No such file or directory) -// if the parent directory doesn’t exist. -TYPED_TEST(fuse_test, create_fails_with_trunc_rw_if_parent_does_not_exist) { - std::string file_name{"no_dir/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_EQ(-1, handle); - - EXPECT_EQ(ENOENT, errno); -} - -// 8. O_CREAT | O_TRUNC | O_RDWR-Failure: EISDIR (Is a directory) if a -// directory exists instead of a file. -TYPED_TEST(fuse_test, create_fails_with_trunc_rw_if_path_is_directory) { - std::string dir_name{"create_test"}; - auto dir_path = this->create_directory_and_test(dir_name); - - auto handle = open(dir_path.c_str(), O_CREAT | O_TRUNC | O_RDWR, ACCESSPERMS); - EXPECT_EQ(-1, handle); - - EXPECT_EQ(EISDIR, errno); - - this->rmdir_and_test(dir_path); + EXPECT_EQ(ENOENT, errno); + } } } // namespace repertory