Skip to content

Commit

Permalink
Merge branch 'main' into caching
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed May 17, 2024
2 parents bf38ed4 + b3c7d9f commit 29e78d5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/fsmod/File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down
2 changes: 1 addition & 1 deletion include/fsmod/Partition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ namespace simgrid::module::fs {

} // namespace simgrid::module::fs

#endif
#endif
8 changes: 0 additions & 8 deletions src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,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
Expand Down
13 changes: 11 additions & 2 deletions test/file_system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -152,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());
Expand Down Expand Up @@ -186,7 +194,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
Expand Down
2 changes: 2 additions & 0 deletions test/seek_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand Down

0 comments on commit 29e78d5

Please sign in to comment.