From 8a1192306f62ed0b0b560a58e2746b2c86b4fc37 Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Wed, 16 Oct 2024 09:35:42 -1000 Subject: [PATCH] Adding new API function for adding a File to the simulation --- include/wrench/simulation/Simulation.h | 3 ++- src/wrench/simulation/Simulation.cpp | 20 ++++++++++++++++---- test/workflow/WorkflowFileTest.cpp | 6 +++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/wrench/simulation/Simulation.h b/include/wrench/simulation/Simulation.h index c9275d13b3..802d5d00e4 100755 --- a/include/wrench/simulation/Simulation.h +++ b/include/wrench/simulation/Simulation.h @@ -86,7 +86,8 @@ namespace wrench { static void removeAllFiles(); static std::shared_ptr getFileByID(const std::string &id); static std::shared_ptr getFileByIDOrNull(const std::string &id); - static std::shared_ptr addFile(const std::string &, sg_size_t); + static std::shared_ptr addFile(const std::string &id, sg_size_t size); + static std::shared_ptr addFile(const std::string &id, const std::string &size); void launch(); diff --git a/src/wrench/simulation/Simulation.cpp b/src/wrench/simulation/Simulation.cpp index 6c5daa43eb..b97feb8b08 100644 --- a/src/wrench/simulation/Simulation.cpp +++ b/src/wrench/simulation/Simulation.cpp @@ -23,6 +23,8 @@ #include //#include #include +#include + #ifdef MESSAGE_MANAGER #include @@ -1576,10 +1578,6 @@ namespace wrench { * */ std::shared_ptr 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 '" + @@ -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 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 diff --git a/test/workflow/WorkflowFileTest.cpp b/test/workflow/WorkflowFileTest.cpp index 57eaf6eff8..07a43b240f 100755 --- a/test/workflow/WorkflowFileTest.cpp +++ b/test/workflow/WorkflowFileTest.cpp @@ -16,9 +16,13 @@ TEST(DataFileTest, FileStructure) { auto workflow = wrench::Workflow::createWorkflow(); std::shared_ptr 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(); }