X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/48eb2f1b9262fc74f527816c348ed2aa6efa9f65..9e16470be6ab815e9db9f301760848bb5492dd43:/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index 430bb73a21..c28714e19a 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -50,8 +50,8 @@ static void sender(std::vector args) XBT_INFO("Sender spec: %s", args[0].c_str()); for (unsigned int test = 1; test <= args[0].size(); test++) { this_actor::sleep_until(test * 5 - 5); - char* mboxName = bprintf("Test #%u", test); - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName); + std::string* mboxName = new std::string("Test #" + std::to_string(test)); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName->c_str()); switch (args[0][test - 1]) { case 'r': @@ -97,8 +97,8 @@ static void receiver(std::vector args) XBT_INFO("Receiver spec: %s", args[0].c_str()); for (unsigned int test = 1; test <= args[0].size(); test++) { this_actor::sleep_until(test * 5 - 5); - char* mboxName = bprintf("Test #%u", test); - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName); + std::string mboxName = "Test #" + std::to_string(test); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName.c_str()); void* received = nullptr; switch (args[0][test - 1]) { @@ -146,10 +146,9 @@ static void receiver(std::vector args) default: xbt_die("Unknown receiver spec for test %u: '%c'", test, args[0][test - 1]); } - - xbt_assert(strcmp(static_cast(received), mboxName) == 0); - xbt_free(received); - xbt_free(mboxName); + std::string* receivedStr = static_cast(received); + xbt_assert(*receivedStr == mboxName); + delete receivedStr; XBT_INFO("Test %u OK", test); } simgrid::s4u::this_actor::sleep_for(0.5); @@ -167,11 +166,11 @@ int main(int argc, char* argv[]) std::vector argSend{specSend.c_str()}; std::vector argRecv{specRecv.c_str()}; - simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); if (argc < 2) usage(argv[0], specSend.c_str(), specRecv.c_str()); - e->loadPlatform(argv[1]); + e.loadPlatform(argv[1]); if (argc >= 3) { argSend.clear(); @@ -183,14 +182,13 @@ int main(int argc, char* argv[]) } xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size"); - simgrid::s4u::Host** hosts = sg_host_list(); + std::vector hosts = e.getAllHosts(); + simgrid::s4u::Actor::createActor("sender", hosts[0], sender, argSend); simgrid::s4u::Actor::createActor("recver", hosts[1], receiver, argRecv); - xbt_free(hosts); - e->run(); - XBT_INFO("Simulation time %g", e->getClock()); + e.run(); + XBT_INFO("Simulation time %g", e.getClock()); - delete e; return 0; }