Skip to content

Commit

Permalink
Testing++
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Apr 23, 2024
1 parent c15e2a7 commit ba07a41
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions test/file_system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(fs_test, "File System Test");
class FileSystemTest : public ::testing::Test {
public:
std::shared_ptr<sgfs::FileSystem> fs_;
sg4::Host * host_{};
sg4::Host * host_;
sg4::Disk * disk_one_;
sg4::Disk * disk_two_;

FileSystemTest() = default;

void setup_platform() {
XBT_INFO("Creating a platform with one host and one disk...");
auto *my_zone = sg4::create_full_zone("zone");
host_ = my_zone->create_host("my_host", "100Gf");
auto my_disk = host_->create_disk("my_disk", "1kBps", "2kBps");
disk_one_ = host_->create_disk("disk_one", "1kBps", "2kBps");
disk_two_ = host_->create_disk("disk_two", "1kBps", "2kBps");
my_zone->seal();

XBT_INFO("Creating a one-disk storage on the host's disk...");
auto ods = sgfs::OneDiskStorage::create("my_storage", my_disk);
auto ods = sgfs::OneDiskStorage::create("my_storage", disk_one_);
XBT_INFO("Creating a file system...");
fs_ = sgfs::FileSystem::create("my_fs");
XBT_INFO("Mounting a 100kB partition...");
Expand All @@ -40,12 +43,33 @@ class FileSystemTest : public ::testing::Test {

};


TEST_F(FileSystemTest, MountPartition) {
DO_TEST_WITH_FORK([this]() {
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]() {
auto ods = sgfs::OneDiskStorage::create("my_storage", disk_two_);
XBT_INFO("Mount a new partition with a name conflict, which shouldn't work");
ASSERT_THROW(fs_->mount_partition("/dev/a", ods, "100kB"), std::invalid_argument);
XBT_INFO("Mount a new partition incorrectly");
ASSERT_THROW(fs_->mount_partition("/dev/", ods, "100kB"), std::invalid_argument);
XBT_INFO("Mount a new partition correctly");
ASSERT_NO_THROW(fs_->mount_partition("/dev/b", ods, "100kB"));
});

// Run the simulation
ASSERT_NO_THROW(sg4::Engine::get_instance()->run());
});
}

TEST_F(FileSystemTest, FileCreate) {
DO_TEST_WITH_FORK([this]() {
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("FileCreator", host_, [this]() {
sg4::Actor::create("TestActor", host_, [this]() {
XBT_INFO("Create a 10MB file at /foo/foo.txt, which should fail");
ASSERT_THROW(this->fs_->create_file("/foo/foo.txt", "10MB"), sgfs::FileSystemException);
XBT_INFO("Create a 10MB file at /dev/a/foo.txt, which should fail");
Expand All @@ -68,7 +92,7 @@ TEST_F(FileSystemTest, Directories) {
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("FileCreator", host_, [this]() {
sg4::Actor::create("TestActor", host_, [this]() {
XBT_INFO("Create a 10kB file at /dev/a/foo.txt");
ASSERT_NO_THROW(fs_->create_file("/dev/a/foo.txt", "10kB"));
XBT_INFO("Create a 10kB file at /dev/a/b/c/foo.txt");
Expand Down Expand Up @@ -104,7 +128,7 @@ TEST_F(FileSystemTest, FileMove) {
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("FileCreator", host_, [this]() {
sg4::Actor::create("TestActor", host_, [this]() {
XBT_INFO("Create a 10kB file at /dev/a/foo.txt");
ASSERT_NO_THROW(fs_->create_file("/dev/a/foo.txt", "10kB"));
ASSERT_DOUBLE_EQ(fs_->partition_by_name("/dev/a/")->get_free_space(), 90*1000);
Expand Down Expand Up @@ -138,7 +162,7 @@ TEST_F(FileSystemTest, FileOpenClose) {
// xbt_log_control_set("root.thresh:info");

// Create one actor (for this test we could likely do it all in the maestro but what the hell)
sg4::Actor::create("FileCreator", host_, [this]() {
sg4::Actor::create("TestActor", host_, [this]() {
XBT_INFO("Create a 10kB file at /dev/a/stuff/foo.txt");
ASSERT_NO_THROW(fs_->create_file("/dev/a/stuff/foo.txt", "10kB"));
XBT_INFO("Create a 10kB file at /dev/a/stuff/other.txt");
Expand Down

0 comments on commit ba07a41

Please sign in to comment.