From 7cc4a08415897b884b1ba7da6ff911c36d0efb9c Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Thu, 16 May 2024 10:32:08 -0400 Subject: [PATCH 1/5] simplify seek --- include/fsmod/File.hpp | 3 +-- src/File.cpp | 8 -------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/include/fsmod/File.hpp b/include/fsmod/File.hpp index 4a83ce3..ab156e0 100644 --- a/include/fsmod/File.hpp +++ b/include/fsmod/File.hpp @@ -54,8 +54,7 @@ namespace simgrid::module::fs { void append(sg_size_t num_bytes); void truncate(sg_size_t num_bytes); - void seek(sg_offset_t pos); /** Sets the file head to the given position. */ - void seek(sg_offset_t pos, int origin); /** Sets the file head to the given position from a given origin. */ + void seek(sg_offset_t pos, int origin = SEEK_SET); /** Sets the file head to the given position from a given origin. */ /** Retrieves the current file position */ [[nodiscard]] sg_size_t tell() const { return current_position_; } diff --git a/src/File.cpp b/src/File.cpp index 47c578e..d24072f 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -170,14 +170,6 @@ namespace simgrid::module::fs { current_position_ = pos; } - /** - * @brief Seek to a position in the file - * @param pos: the position as an offset from the first byte of the file - */ - void File::seek(sg_offset_t pos) { - update_current_position(pos); - } - /** * @brief Seek to a position in the file from a given origin * @param pos: the position as an offset from the given origin in the file From 0dd9cd64e681276a62e1968f17698dcd80fa3bc8 Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Thu, 16 May 2024 10:32:32 -0400 Subject: [PATCH 2/5] test more corner cases --- test/file_system_test.cpp | 5 ++++- test/seek_test.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/file_system_test.cpp b/test/file_system_test.cpp index 54deed9..011db4c 100644 --- a/test/file_system_test.cpp +++ b/test/file_system_test.cpp @@ -77,6 +77,8 @@ TEST_F(FileSystemTest, FileCreate) { ASSERT_THROW(this->fs_->create_file("/dev/a/foo.txt", "10MB"), sgfs::FileSystemException); XBT_INFO("Create a 10kB file at /dev/a/foo.txt, which should work"); ASSERT_NO_THROW(this->fs_->create_file("/dev/a/foo.txt", "10kB")); + XBT_INFO("Create the same file again at /dev/a/foo.txt, which should fail"); + ASSERT_THROW(this->fs_->create_file("/dev/a/foo.txt", "10kB"), sgfs::FileSystemException); XBT_INFO("Check remaining space"); ASSERT_DOUBLE_EQ(this->fs_->partition_by_name("/dev/a")->get_free_space(), 90 * 1000); }); @@ -186,7 +188,8 @@ TEST_F(FileSystemTest, FileOpenClose) { XBT_INFO("Trying to unlink the file"); ASSERT_NO_THROW(fs_->unlink_file("/dev/a/stuff/foo.txt")); ASSERT_FALSE(fs_->file_exists("/dev/a/stuff/foo.txt")); - + XBT_INFO("Trying to unlink the file again"); + ASSERT_THROW(fs_->unlink_file("/dev/a/stuff/foo.txt"), sgfs::FileSystemException); }); // Run the simulation diff --git a/test/seek_test.cpp b/test/seek_test.cpp index 84c02a1..75d4ee6 100644 --- a/test/seek_test.cpp +++ b/test/seek_test.cpp @@ -75,6 +75,8 @@ TEST_F(SeekTest, SeekandTell) { ASSERT_NO_THROW(file->write("1kB")); XBT_INFO("Check file size, it should now be 104k"); ASSERT_DOUBLE_EQ(fs_->file_size("/dev/a/foo.txt"), 104000); + XBT_INFO("Seek from an arbitrary position in file, should work"); + ASSERT_NO_THROW(file->seek(1000, 2000)); XBT_INFO("Close the file"); ASSERT_NO_THROW(file->close()); }); From 4e57900512bacd385c24bfb3f00869b6cc0e7423 Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Thu, 16 May 2024 10:40:29 -0400 Subject: [PATCH 3/5] have flags before directory --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc3f0b3..7c13991 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: git checkout a0123b157d9d1e7f7d40198198d8776817fb4d46 mkdir build cd build - cmake .. -Denable_smpi=OFF -Denable_model-checking=OFF + cmake -Denable_smpi=OFF -Denable_model-checking=OFF .. make -j4 sudo make install From 4a42f7c8cea507a66216ee2d96939919c08a8841 Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Thu, 16 May 2024 10:42:05 -0400 Subject: [PATCH 4/5] no need for default dtor --- include/fsmod/Partition.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/fsmod/Partition.hpp b/include/fsmod/Partition.hpp index 81edda1..21330c4 100644 --- a/include/fsmod/Partition.hpp +++ b/include/fsmod/Partition.hpp @@ -30,7 +30,6 @@ namespace simgrid::module::fs { : name_(std::move(name)), storage_(std::move(storage)), size_(size), free_space_(size) {} public: - ~Partition() = default; [[nodiscard]] const std::string& get_name() const { return name_; } [[nodiscard]] const char* get_cname() const { return name_.c_str(); } [[nodiscard]] sg_size_t get_size() const { return size_; } From b3c7d9fe051033b36487931ca7e4cdcfc890e3e7 Mon Sep 17 00:00:00 2001 From: Fred Suter Date: Thu, 16 May 2024 10:57:05 -0400 Subject: [PATCH 5/5] test of moving file across partitions (forbidden) --- test/file_system_test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/file_system_test.cpp b/test/file_system_test.cpp index 011db4c..af665be 100644 --- a/test/file_system_test.cpp +++ b/test/file_system_test.cpp @@ -154,7 +154,13 @@ TEST_F(FileSystemTest, FileMove) { ASSERT_FALSE(fs_->file_exists("/dev/a/b/c/foo.txt")); ASSERT_TRUE(fs_->file_exists("/dev/a/stuff.txt")); ASSERT_DOUBLE_EQ(fs_->partition_by_name("/dev/a/")->get_free_space(), 90*1000); - }); + + auto ods = sgfs::OneDiskStorage::create("my_storage", disk_two_); + XBT_INFO("Mount a new partition"); + ASSERT_NO_THROW(fs_->mount_partition("/dev/b/", ods, "100kB")); + XBT_INFO("Move file /dev/a/stuff.txt to /dev/b/stuff.txt which is forbidden"); + ASSERT_THROW(fs_->move_file("/dev/a/stuff.txt", "/dev/b/stuff.txt"), sgfs::FileSystemException); + }); // Run the simulation ASSERT_NO_THROW(sg4::Engine::get_instance()->run());