From b2fc51d7c2ef2b43435ae28c80f0539ecd8f262f Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Sun, 21 Apr 2024 21:34:56 -1000 Subject: [PATCH] testing++ --- README.md | 45 ++++++++++++++++++++++++++++++++------- examples/README.md | 3 +++ test/file_system_test.cpp | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 examples/README.md diff --git a/README.md b/README.md index 5ec5054..3066c64 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,51 @@ [![Build-Linux](https://github.com/frs69wq/file-system-module/actions/workflows/build.yml/badge.svg)](https://github.com/frs69wq/file-system-module/actions/workflows/build.yml) -# File System Module for SimGrid +# FSMod: File System Module for SimGrid -This project implements a simulated file system on top of [SimGrid](https://simgrid.frama.io/simgrid/), to -be used in any SimGrid-based simulator. - -## Prerequisites and installation +## Overview -TBD +This project implements a simulated file system "module" on top of [SimGrid](https://simgrid.frama.io/simgrid/), to +be used in any SimGrid-based simulator. +It supports the notion of partitions that store directories that store files, with the +expected operations (e.g., create files, move files, unlink files, unlink directories, check for existence), +and the notion of a file descriptor with POSIX-like operations (open, seek, read, write, close). + +The simulated file system implementation in FSMod is not full-featured (e.g., no notion of ownership, no notion of permission). +The biggest limitation is that a directory cannot contain another directory. That is, +a directory `/dev/a/tmp` could contain a file `foo.txt`, and a directory `/dev/a/tmp/other/c` could +contain a file `bar.txt`. But, directory `/dev/a/tmp` does **not** contain directory `other`. +`/dev/a/tmp` and `/dev/a/tmp/other/c` are two completely unrelated directory (there is no directory `/dev/a/tmp/other`). +In other words, each directory simply has a path-like unique name and can only contain files. +The rationale is that the intended use of this module is purely for simulation. As +a result, full-fledged file system functionality is not (or rarely) needed (and would add +overhead to the simulation). We expect that in most cases users will need/use a single directory. + +## Dependencies and installation + +The only required dependency is [SimGrid](https://simgrid.frama.io/simgrid/). An optional dependency +is [Google Test](https://github.com/google/googletest) for compiling the unit tests. + +Here is the typical Ubuntu installation procedure: + +```bash +cd file-system-module +mkdir build +cd build +cmake .. +make -j4 +sudo make install +``` + +after which the FSMod library and header files will be installed in `/usr/local/`. ## Examples -TBD +Example SimGrid simulators that use FSMod are provided in the `examples` directory (see `README.md` file therein). ## API Reference -TBD +The FSMod API is documented on [Read the docs](http://XXXX). --- diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..311db59 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# FSMod Examples + +TBD \ No newline at end of file diff --git a/test/file_system_test.cpp b/test/file_system_test.cpp index a3a38f3..fa872bb 100644 --- a/test/file_system_test.cpp +++ b/test/file_system_test.cpp @@ -125,6 +125,44 @@ TEST_F(FileSystemTest, FileMove) { ASSERT_DOUBLE_EQ(fs_->partition_by_name("/dev/a/")->get_free_space(), 90*1000); }); + // Run the simulation + ASSERT_NO_THROW(sg4::Engine::get_instance()->run()); + }); +} + + +TEST_F(FileSystemTest, FileOpenClose) { + DO_TEST_WITH_FORK([this]() { + this->setup_platform(); + +// 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]() { + 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"); + ASSERT_NO_THROW(fs_->create_file("/dev/a/stuff/other.txt", "10kB")); + + XBT_INFO("Opening the file"); + std::shared_ptr file; + ASSERT_NO_THROW(file = fs_->open("/dev/a/stuff/foo.txt")); + + XBT_INFO("Trying to move the file"); + ASSERT_THROW(fs_->move_file("/dev/a/stuff/foo.txt", "/dev/a/bar.txt"), sgfs::FileSystemException); + XBT_INFO("Trying to unlink the file"); + ASSERT_THROW(fs_->unlink_file("/dev/a/stuff/foo.txt"), sgfs::FileSystemException); + XBT_INFO("Trying to overwrite the file"); + ASSERT_THROW(fs_->move_file("/dev/a/stuff/other.txt", "/dev/a/stuff/foo.txt"), sgfs::FileSystemException); + + XBT_INFO("Close the file"); + ASSERT_NO_THROW(file->close()); + 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")); + + }); + // Run the simulation ASSERT_NO_THROW(sg4::Engine::get_instance()->run()); });