Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
905017423f3fb9bbddc388f218a4ac22286f699b
[simgrid.git] / teshsuite / s4u / basic-link-test / basic-link-test.cpp
1 /* Copyright (c) 2008-2021. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/s4u.hpp"
8 #include <algorithm>
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(basic_link_test, s4u, "basic link test");
11
12 int main(int argc, char** argv)
13 {
14   std::string user_data = "some user_data";
15
16   /* initialization of SD */
17   simgrid::s4u::Engine e(&argc, argv);
18
19   /* creation of the environment */
20   e.load_platform(argv[1]);
21
22   std::vector<simgrid::s4u::Link*> links = simgrid::s4u::Engine::get_instance()->get_all_links();
23   XBT_INFO("Link count: %zu", links.size());
24
25   std::sort(links.begin(), links.end(), [](const simgrid::s4u::Link* a, const simgrid::s4u::Link* b) {
26     return strcmp(sg_link_get_name(a), sg_link_get_name(b)) < 0;
27   });
28
29   for (const auto& l : links) {
30     XBT_INFO("%s: latency = %.5f, bandwidth = %f", l->get_cname(), l->get_latency(), l->get_bandwidth());
31     l->set_data(&user_data);
32     xbt_assert(user_data == *static_cast<const std::string*>(l->get_data()), "User data was corrupted.");
33   }
34
35   return 0;
36 }