1 /* Copyright (c) 2007-2016. 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/msg.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
10 static void test_host(const char*hostname)
12 msg_host_t thehost = MSG_host_by_name(hostname);
13 xbt_dict_t props = MSG_host_get_properties(thehost);
14 xbt_dict_cursor_t cursor = NULL;
17 const char *noexist = "Unknown";
21 XBT_INFO("== Print the properties of the host '%s'", hostname);
22 xbt_dict_foreach(props, cursor, key, data)
23 XBT_INFO(" Host property: '%s' -> '%s'", key, data);
25 XBT_INFO("== Try to get a host property that does not exist");
26 value = MSG_host_get_property_value(thehost, noexist);
27 xbt_assert(!value, "The key exists (it's not supposed to)");
29 XBT_INFO("== Try to get a host property that does exist");
30 value = MSG_host_get_property_value(thehost, 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 MSG_host_set_property_value(thehost, exist, xbt_strdup("250"));
38 /* Test if we have changed the value */
39 value = MSG_host_get_property_value(thehost, 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 MSG_host_set_property_value(thehost, exist, xbt_strdup("180"));
48 static int alice(int argc, char *argv[]) { /* Dump what we have on the current host */
53 static int carole(int argc, char *argv[]) {/* Dump what we have on a remote host */
54 MSG_process_sleep(1); // Wait for alice to be done with its experiment
59 static int david(int argc, char *argv[]) {/* Dump what we have on a remote host */
60 MSG_process_sleep(2); // Wait for alice and carole to be done with its experiment
61 test_host("node-0.acme.org");
65 static int bob(int argc, char *argv[])
67 /* this host also tests the properties of the AS*/
68 msg_as_t root = MSG_zone_get_root();
69 XBT_INFO("== Print the properties of the AS");
70 XBT_INFO(" Process property: filename -> %s", MSG_zone_get_property_value(root, "filename"));
71 XBT_INFO(" Process property: date -> %s", MSG_zone_get_property_value(root, "date"));
72 XBT_INFO(" Process property: author -> %s", MSG_zone_get_property_value(root, "author"));
74 /* Get the property list of current bob process */
75 xbt_dict_t props = MSG_process_get_properties(MSG_process_self());
76 xbt_dict_cursor_t cursor = NULL;
79 const char *noexist = "UnknownProcessProp";
80 XBT_ATTRIB_UNUSED const char *value;
82 XBT_INFO("== Print the properties of the process");
83 xbt_dict_foreach(props, cursor, key, data)
84 XBT_INFO(" Process property: %s -> %s", key, data);
86 XBT_INFO("== Try to get a process property that does not exist");
88 value = MSG_process_get_property_value(MSG_process_self(), noexist);
89 xbt_assert(!value, "The property is defined (it shouldnt)");
94 int main(int argc, char *argv[])
99 MSG_init(&argc, argv);
100 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
101 "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
103 MSG_function_register("alice", alice);
104 MSG_function_register("bob", bob);
105 MSG_function_register("carole", carole);
106 MSG_function_register("david", david);
108 MSG_create_environment(argv[1]);
110 XBT_INFO("There are %d hosts in the environment", MSG_get_host_number());
112 xbt_dynar_t hosts = MSG_hosts_as_dynar();
113 xbt_dynar_foreach(hosts, i, host){
114 XBT_INFO("Host '%s' runs at %.0f flops/s",MSG_host_get_name(host), MSG_host_get_speed(host));
116 xbt_dynar_free(&hosts);
118 MSG_launch_application(argv[2]);
120 msg_error_t res = MSG_main();