Skip to content

Commit

Permalink
testing++
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Apr 22, 2024
1 parent a60f053 commit b2fc51d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).


---
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# FSMod Examples

TBD
38 changes: 38 additions & 0 deletions test/file_system_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<sgfs::File> 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());
});
Expand Down

0 comments on commit b2fc51d

Please sign in to comment.