1 /* Copyright (c) 2017. 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 // TODO: also test the properties attached to links
8 #include <simgrid/s4u.hpp>
11 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Property test");
13 static void test_host(std::string hostname)
15 simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname);
16 std::map<std::string, std::string>* props = thehost->getProperties();
17 const char* noexist = "Unknown";
18 const char* exist = "Hdd";
21 XBT_INFO("== Print the properties of the host '%s'", hostname.c_str());
22 for (const auto& kv : *props)
23 XBT_INFO(" Host property: '%s' -> '%s'", kv.first.c_str(), kv.second.c_str());
25 XBT_INFO("== Try to get a host property that does not exist");
26 value = thehost->getProperty(noexist);
27 xbt_assert(not value, "The key exists (it's not supposed to)");
29 XBT_INFO("== Try to get a host property that does exist");
30 value = thehost->getProperty(exist);
31 xbt_assert(value, "\tProperty %s is undefined (where it should)", exist);
32 xbt_assert(!strcmp(value, "180"), "\tValue of property %s is defined to %s (where it should be 180)", exist, value);
33 XBT_INFO(" Property: %s old value: %s", exist, value);
35 XBT_INFO("== Trying to modify a host property");
36 thehost->setProperty(exist, "250");
38 /* Test if we have changed the value */
39 value = thehost->getProperty(exist);
40 xbt_assert(value, "Property %s is undefined (where it should)", exist);
41 xbt_assert(!strcmp(value, "250"), "Value of property %s is defined to %s (where it should be 250)", exist, value);
42 XBT_INFO(" Property: %s old value: %s", exist, value);
44 /* Restore the value for the next test */
45 thehost->setProperty(exist, "180");
48 static int alice(int argc, char* argv[])
50 /* Dump what we have on the current host */
55 static int carole(int argc, char* argv[])
57 /* Dump what we have on a remote host */
58 simgrid::s4u::this_actor::sleep_for(1); // Wait for alice to be done with its experiment
63 static int david(int argc, char* argv[])
65 /* Dump what we have on a remote host */
66 simgrid::s4u::this_actor::sleep_for(2); // Wait for alice and carole to be done with its experiment
67 test_host("node-0.acme.org");
71 static int bob(int argc, char* argv[])
73 /* this host also tests the properties of the AS*/
74 simgrid::s4u::NetZone* root = simgrid::s4u::Engine::getInstance()->getNetRoot();
75 XBT_INFO("== Print the properties of the zone");
76 XBT_INFO(" Zone property: filename -> %s", root->getProperty("filename"));
77 XBT_INFO(" Zone property: date -> %s", root->getProperty("date"));
78 XBT_INFO(" Zone property: author -> %s", root->getProperty("author"));
80 /* Get the property list of current bob process */
81 std::map<std::string, std::string>* props = simgrid::s4u::Actor::self()->getProperties();
82 const char* noexist = "UnknownProcessProp";
83 XBT_ATTRIB_UNUSED const char* value;
85 XBT_INFO("== Print the properties of the actor");
86 for (const auto& kv : *props)
87 XBT_INFO(" Actor property: %s -> %s", kv.first.c_str(), kv.second.c_str());
89 XBT_INFO("== Try to get an actor property that does not exist");
91 value = simgrid::s4u::Actor::self()->getProperty(noexist);
92 xbt_assert(not value, "The property is defined (it shouldnt)");
96 int main(int argc, char* argv[])
98 simgrid::s4u::Engine e(&argc, argv);
99 e.loadPlatform(argv[1]);
101 e.registerFunction("alice", alice);
102 e.registerFunction("bob", bob);
103 e.registerFunction("carole", carole);
104 e.registerFunction("david", david);
106 size_t totalHosts = sg_host_count();
108 XBT_INFO("There are %zu hosts in the environment", totalHosts);
109 std::vector<simgrid::s4u::Host*> hosts = e.getAllHosts();
110 for (unsigned int i = 0; i < hosts.size(); i++)
111 XBT_INFO("Host '%s' runs at %.0f flops/s", hosts[i]->get_cname(), hosts[i]->getSpeed());
113 e.loadDeployment(argv[2]);