Skip to content

Commit

Permalink
Adding new API function for adding a File to the simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Oct 16, 2024
1 parent 3de179c commit 8a11923
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/wrench/simulation/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ namespace wrench {
static void removeAllFiles();
static std::shared_ptr<DataFile> getFileByID(const std::string &id);
static std::shared_ptr<DataFile> getFileByIDOrNull(const std::string &id);
static std::shared_ptr<DataFile> addFile(const std::string &, sg_size_t);
static std::shared_ptr<DataFile> addFile(const std::string &id, sg_size_t size);
static std::shared_ptr<DataFile> addFile(const std::string &id, const std::string &size);


void launch();
Expand Down
20 changes: 16 additions & 4 deletions src/wrench/simulation/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <wrench/simgrid_S4U_util/S4U_CommPort.h>
//#include <wrench/services/memory/MemoryManager.h>
#include <wrench/data_file/DataFile.h>
#include <wrench/util/UnitParser.h>


#ifdef MESSAGE_MANAGER
#include <wrench/util/MessageManager.h>
Expand Down Expand Up @@ -1576,10 +1578,6 @@ namespace wrench {
*
*/
std::shared_ptr<DataFile> Simulation::addFile(const std::string &id, sg_size_t size) {
if (size < 0) {
throw std::invalid_argument("Simulation::addFile(): Invalid file size");
}

// Create the DataFile object
if (Simulation::data_files.find(id) != Simulation::data_files.end()) {
throw std::invalid_argument("Simulation::addFile(): DataFile with id '" +
Expand All @@ -1594,6 +1592,20 @@ namespace wrench {
return file;
}

/**
* @brief Add a new file to the simulation (use at your own peril if you're using the workflow API - use Workflow::addFile() instead)
*
* @param id: a unique string id
* @param size: a size as a unit string (e.g., "10MB")
*
* @return the DataFile instance
*
*/
std::shared_ptr<DataFile> Simulation::addFile(const std::string &id, const std::string &size) {
sg_size_t size_in_bytes = UnitParser::parse_size(size);
return Simulation::addFile(id, UnitParser::parse_size(size));
}

/**
* @brief Remove a file from the simulation (use at your own peril if you're using the workflow API - use Workflow::removeFile() instead)
* @param file : file to remove
Expand Down
6 changes: 5 additions & 1 deletion test/workflow/WorkflowFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
TEST(DataFileTest, FileStructure) {
auto workflow = wrench::Workflow::createWorkflow();
std::shared_ptr<wrench::DataFile> f1 = wrench::Simulation::addFile("file-01", 100);

ASSERT_EQ(f1->getID(), "file-01");
ASSERT_EQ(f1->getSize(), 100);

ASSERT_EQ(wrench::Simulation::addFile("file-02", "100MB")->getSize(), 100000000ULL);
ASSERT_EQ(wrench::Simulation::addFile("file-03", "100MiB")->getSize(), 100ULL * 1024ULL * 1024ULL);
ASSERT_THROW(wrench::Simulation::addFile("file-03", "100MXiB")->getSize(), std::invalid_argument);

workflow->clear();
wrench::Simulation::removeAllFiles();
}

0 comments on commit 8a11923

Please sign in to comment.