From 3807f6651be774322f7175035aabe89aa92fb058 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 4 May 2021 10:57:09 +0200 Subject: [PATCH] Define an Engine constructor taking only a name parameter. It will by useful for unit tests. --- include/simgrid/s4u/Engine.hpp | 3 +++ src/s4u/s4u_Engine.cpp | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index a608f2e03f..2dfacd3f19 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -27,6 +27,8 @@ class XBT_PUBLIC Engine { friend simgrid::kernel::EngineImpl; public: + /** Constructor, taking only the name of your main function */ + explicit Engine(std::string name); /** Constructor, taking the command line parameters of your main function */ explicit Engine(int* argc, char** argv); /* Currently, only one instance is allowed to exist. This is why you can't copy or move it */ @@ -199,6 +201,7 @@ public: private: kernel::EngineImpl* const pimpl; static Engine* instance_; + void initialize(int* argc, char** argv); }; #ifndef DOXYGEN /* Internal use only, no need to expose it */ diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 2d94c66d87..2d980c9fa8 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -37,15 +37,26 @@ xbt::signal Engine::on_deadlock; Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */ -Engine::Engine(int* argc, char** argv) : pimpl(new kernel::EngineImpl()) +void Engine::initialize(int* argc, char** argv) { xbt_assert(Engine::instance_ == nullptr, "It is currently forbidden to create more than one instance of s4u::Engine"); instr::init(); SIMIX_global_init(argc, argv); - Engine::instance_ = this; } +Engine::Engine(std::string name) : pimpl(new kernel::EngineImpl()) +{ + int argc = 1; + char* argv = &name[0]; + initialize(&argc, &argv); +} + +Engine::Engine(int* argc, char** argv) : pimpl(new kernel::EngineImpl()) +{ + initialize(argc, argv); +} + Engine::~Engine() { delete pimpl; -- 2.20.1