Skip to content

Commit

Permalink
more test (one does nothing new until disk failures are implemented i…
Browse files Browse the repository at this point in the history
…n SimGrid
  • Loading branch information
frs69wq committed May 23, 2024
1 parent f282e98 commit 65809aa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
40 changes: 21 additions & 19 deletions test/file_system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,27 @@ TEST_F(FileSystemTest, BadAccessMode) {
this->setup_platform();
// Create one actor (for this test we could likely do it all in the maestro but what the hell)
sg4::Actor::create("TestActor", host_, [this]() {
std::shared_ptr<sgfs::File> file;
XBT_INFO("Create a 10kB file at /dev/a/foo.txt");
ASSERT_NO_THROW(fs_->create_file("/dev/a/foo.txt", "10kB"));
XBT_INFO("Open the file in read mode ('r')");
ASSERT_NO_THROW(file = fs_->open("/dev/a/foo.txt", "r"));
XBT_INFO("Try to write in a file opened in read mode, which should fail");
ASSERT_THROW(file->write("5kB"), std::invalid_argument);
XBT_INFO("Close the file");
ASSERT_NO_THROW(fs_->close(file));
XBT_INFO("Open the file in write mode ('w')");
ASSERT_NO_THROW(file = fs_->open("/dev/a/foo.txt", "w"));
XBT_INFO("Try to read from a file opened in write mode, which should fail");
ASSERT_THROW(file->read("5kB"), std::invalid_argument);
XBT_INFO("Asynchronous read from a file opened in write mode should also fail");
ASSERT_THROW(file->read_async("5kB"), std::invalid_argument);
XBT_INFO("Close the file");
ASSERT_NO_THROW(fs_->close(file));
XBT_INFO("Open the file in unsupported mode ('w+'), which should fail");
ASSERT_THROW(file = fs_->open("/dev/a/foo.txt", "w+"), std::invalid_argument);
std::shared_ptr<sgfs::File> file;
XBT_INFO("Create a 10kB file at /dev/a/foo.txt");
ASSERT_NO_THROW(fs_->create_file("/dev/a/foo.txt", "10kB"));
XBT_INFO("Open the file in read mode ('r')");
ASSERT_NO_THROW(file = fs_->open("/dev/a/foo.txt", "r"));
XBT_INFO("Try to write in a file opened in read mode, which should fail");
ASSERT_THROW(file->write("5kB"), std::invalid_argument);
XBT_INFO("Close the file");
ASSERT_NO_THROW(fs_->close(file));
XBT_INFO("Open the file in write mode ('w')");
ASSERT_NO_THROW(file = fs_->open("/dev/a/foo.txt", "w"));
XBT_INFO("Try to read from a file opened in write mode, which should fail");
ASSERT_THROW(file->read("5kB"), std::invalid_argument);
XBT_INFO("Asynchronous read from a file opened in write mode should also fail");
ASSERT_THROW(file->read_async("5kB"), std::invalid_argument);
XBT_INFO("Close the file");
ASSERT_NO_THROW(fs_->close(file));
XBT_INFO("Open the file in unsupported mode ('w+'), which should fail");
ASSERT_THROW(file = fs_->open("/dev/a/foo.txt", "w+"), std::invalid_argument);
XBT_INFO("Open a non-existing file in read mode ('r'), which should fail");
ASSERT_THROW(file = fs_->open("/dev/a/bar.txt", "r"), sgfs::FileSystemException);
});

// Run the simulation
Expand Down
1 change: 0 additions & 1 deletion test/jbod_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ TEST_F(JBODStorageTest, NotEnoughDisks) {
TEST_F(JBODStorageTest, SingleRead) {
DO_TEST_WITH_FORK([this]() {
this->setup_platform();
xbt_log_control_set("root.thresh:info");
sg4::Actor::create("TestActor", fs_client_, [this]() {
std::shared_ptr<sgfs::File> file;
XBT_INFO("Create a 10kB file at /dev/a/foo.txt");
Expand Down
27 changes: 26 additions & 1 deletion test/one_disk_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ TEST_F(OneDiskStorageTest, SingleAsyncWrite) {
TEST_F(OneDiskStorageTest, SingleAppendWrite) {
DO_TEST_WITH_FORK([this]() {
this->setup_platform();
xbt_log_control_set("root.thresh:info");
sg4::Actor::create("TestActor", host_, [this]() {
std::shared_ptr<sgfs::File> file;
sg4::IoPtr my_write;
Expand All @@ -177,3 +176,29 @@ TEST_F(OneDiskStorageTest, SingleAppendWrite) {
ASSERT_NO_THROW(sg4::Engine::get_instance()->run());
});
}

TEST_F(OneDiskStorageTest, DiskFailure) {
DO_TEST_WITH_FORK([this]() {
this->setup_platform();
sg4::Actor::create("TestActor", host_, [this]() {
std::shared_ptr<sgfs::File> file;
sg4::IoPtr my_write;
sg_size_t num_bytes_written = 0;
XBT_INFO("Create a 10MB file at /dev/a/foo.txt");
ASSERT_NO_THROW(fs_->create_file("/dev/a/foo.txt", "10MB"));
XBT_INFO("Open File '/dev/a/foo.txt' in append mode ('a')");
ASSERT_NO_THROW(file = fs_->open("/dev/a/foo.txt", "a"));
XBT_INFO("Write 2MB at /dev/a/foo.txt");
ASSERT_NO_THROW(my_write = file->write_async("2MB"));
ASSERT_NO_THROW(sg4::this_actor::sleep_for(1));
//ASSERT_NO_THROW(disk_->turn_off());
ASSERT_NO_THROW(sg4::this_actor::sleep_for(1));
//ASSERT_NO_THROW(disk_->turn_on());
ASSERT_NO_THROW(my_write->wait());
XBT_INFO("Close the file");
ASSERT_NO_THROW(fs_->close(file));
});
// Run the simulation
ASSERT_NO_THROW(sg4::Engine::get_instance()->run());
});
}

0 comments on commit 65809aa

Please sign in to comment.