1 /* Copyright (c) 2007-2022. 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 #include "simgrid/actor.h"
7 #include "simgrid/engine.h"
8 #include "simgrid/host.h"
9 #include "simgrid/zone.h"
11 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
17 static void test_host(const char* hostname)
19 sg_host_t thehost = sg_host_by_name(hostname);
20 xbt_dict_t props = sg_host_get_properties(thehost);
21 xbt_dict_cursor_t cursor = NULL;
24 const char* noexist = "Unknown";
28 XBT_INFO("== Print the properties of the host '%s'", hostname);
29 xbt_dict_foreach (props, cursor, key, data)
30 XBT_INFO(" Host property: '%s' -> '%s'", key, data);
32 XBT_INFO("== Try to get a host property that does not exist");
33 value = sg_host_get_property_value(thehost, noexist);
34 xbt_assert(!value, "The key exists (it's not supposed to)");
36 XBT_INFO("== Try to get a host property that does exist");
37 value = sg_host_get_property_value(thehost, exist);
38 xbt_assert(value, "\tProperty %s is undefined (where it should)", exist);
39 xbt_assert(!strcmp(value, "180"), "\tValue of property %s is defined to %s (where it should be 180)", exist, value);
40 XBT_INFO(" Property: %s old value: %s", exist, value);
42 XBT_INFO("== Trying to modify a host property");
43 sg_host_set_property_value(thehost, exist, (char*)"250");
45 /* Test if we have changed the value */
46 value = sg_host_get_property_value(thehost, exist);
47 xbt_assert(value, "Property %s is undefined (where it should)", exist);
48 xbt_assert(!strcmp(value, "250"), "Value of property %s is defined to %s (where it should be 250)", exist, value);
49 XBT_INFO(" Property: %s old value: %s", exist, value);
51 /* Restore the value for the next test */
52 sg_host_set_property_value(thehost, exist, (char*)"180");
54 xbt_dict_free(&props);
57 static void alice(int argc, char* argv[])
58 { /* Dump what we have on the current host */
62 static void carole(int argc, char* argv[])
63 { /* Dump what we have on a remote host */
64 sg_actor_sleep_for(1); // Wait for alice to be done with its experiment
68 static void david(int argc, char* argv[])
69 { /* Dump what we have on a remote host */
70 sg_actor_sleep_for(2); // Wait for alice and carole to be done with its experiment
71 test_host("node-0.simgrid.org");
74 static void bob(int argc, char* argv[])
76 /* this host also tests the properties of the NetZone*/
77 const_sg_netzone_t root = sg_zone_get_root();
78 XBT_INFO("== Print the properties of the NetZone");
79 XBT_INFO(" Actor property: filename -> %s", sg_zone_get_property_value(root, "filename"));
80 XBT_INFO(" Actor property: date -> %s", sg_zone_get_property_value(root, "date"));
81 XBT_INFO(" Actor property: author -> %s", sg_zone_get_property_value(root, "author"));
83 /* Get the property list of current bob actor */
84 xbt_dict_t props = sg_actor_get_properties(sg_actor_self());
85 xbt_dict_cursor_t cursor = NULL;
88 const char* noexist = "UnknownActorProp";
91 XBT_INFO("== Print the properties of the actor");
92 xbt_dict_foreach (props, cursor, key, data)
93 XBT_INFO(" Actor property: %s -> %s", key, data);
95 XBT_INFO("== Try to get an actor property that does not exist");
97 value = sg_actor_get_property_value(sg_actor_self(), noexist);
98 xbt_assert(!value, "The property is defined (it shouldn't)");
99 xbt_dict_free(&props);
102 int main(int argc, char* argv[])
104 simgrid_init(&argc, argv);
106 "Usage: %s platform_file deployment_file\n"
107 "\tExample: %s platform.xml deployment.xml\n",
110 simgrid_register_function("alice", alice);
111 simgrid_register_function("bob", bob);
112 simgrid_register_function("carole", carole);
113 simgrid_register_function("david", david);
115 simgrid_load_platform(argv[1]);
116 size_t host_count = sg_host_count();
117 XBT_INFO("There are %zu hosts in the environment", host_count);
119 sg_host_t* hosts = sg_host_list();
120 for (size_t i = 0; i < host_count; i++)
121 XBT_INFO("Host '%s' runs at %.0f flops/s", sg_host_get_name(hosts[i]), sg_host_get_speed(hosts[i]));
125 simgrid_load_deployment(argv[2]);