1 /* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 /* This test checks that ns-3 behave correctly when multiple flows finish */
7 /* at the exact same time. Given the amount of simultaneous senders, it */
8 /* also serves as a (small) crash test for ns-3. */
10 #include "simgrid/s4u.hpp"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u tests");
14 const int payload = 1000;
15 const int nb_message_to_send = 5;
16 const int nb_sender = 2;
18 static void test_send()
20 simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test");
21 static int nb_messages_sent = 0;
22 for (int nb_message = 0; nb_message < nb_message_to_send; nb_message++) {
24 XBT_VERB("start sending test #%i", nb_messages_sent);
25 box->put(new int(nb_messages_sent), payload);
26 XBT_VERB("done sending test #%i", nb_messages_sent);
30 static void test_receive()
32 simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test");
33 for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
34 XBT_VERB("waiting for messages");
35 auto ptr = box->get_unique<int>();
37 XBT_VERB("received messages #%i", id);
39 XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send);
42 int main(int argc, char* argv[])
44 simgrid::s4u::Engine e(&argc, argv);
46 e.load_platform(argv[1]);
48 auto hosts = e.get_all_hosts();
49 simgrid::s4u::Actor::create("receiver", hosts[0], test_receive);
50 simgrid::s4u::Actor::create("send_same", hosts[0], test_send);
51 simgrid::s4u::Actor::create("send_other", hosts[1], test_send);