diff --git a/test/file_system_test.cpp b/test/file_system_test.cpp index 666c87f..53f850f 100644 --- a/test/file_system_test.cpp +++ b/test/file_system_test.cpp @@ -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 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 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 diff --git a/test/jbod_storage_test.cpp b/test/jbod_storage_test.cpp index f42268c..9c29156 100644 --- a/test/jbod_storage_test.cpp +++ b/test/jbod_storage_test.cpp @@ -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 file; XBT_INFO("Create a 10kB file at /dev/a/foo.txt"); diff --git a/test/one_disk_storage_test.cpp b/test/one_disk_storage_test.cpp index 76f237a..fef4d1b 100644 --- a/test/one_disk_storage_test.cpp +++ b/test/one_disk_storage_test.cpp @@ -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 file; sg4::IoPtr my_write; @@ -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 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()); + }); +}