Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make MSG fade away (part 2)
[simgrid.git] / teshsuite / msg / platform-properties / platform-properties.c
1 /* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/msg.h"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
9
10 static void test_host(const char* hostname)
11 {
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;
15   char* key;
16   char* data;
17   const char* noexist = "Unknown";
18   const char* value;
19   char exist[] = "Hdd";
20
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);
24
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)");
28
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);
34
35   XBT_INFO("== Trying to modify a host property");
36   MSG_host_set_property_value(thehost, exist, (char*)"250");
37
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);
43
44   /* Restore the value for the next test */
45   MSG_host_set_property_value(thehost, exist, (char*)"180");
46
47   xbt_dict_free(&props);
48 }
49
50 static int alice(int argc, char* argv[])
51 { /* Dump what we have on the current host */
52   test_host("host1");
53   return 0;
54 }
55
56 static int carole(int argc, char* argv[])
57 {                       /* Dump what we have on a remote host */
58   MSG_process_sleep(1); // Wait for alice to be done with its experiment
59   test_host("host1");
60   return 0;
61 }
62
63 static int david(int argc, char* argv[])
64 {                       /* Dump what we have on a remote host */
65   MSG_process_sleep(2); // Wait for alice and carole to be done with its experiment
66   test_host("node-0.acme.org");
67   return 0;
68 }
69
70 static int bob(int argc, char* argv[])
71 {
72   /* this host also tests the properties of the AS*/
73   msg_as_t root = MSG_zone_get_root();
74   XBT_INFO("== Print the properties of the AS");
75   XBT_INFO("   Process property: filename -> %s", MSG_zone_get_property_value(root, "filename"));
76   XBT_INFO("   Process property: date -> %s", MSG_zone_get_property_value(root, "date"));
77   XBT_INFO("   Process property: author -> %s", MSG_zone_get_property_value(root, "author"));
78
79   /* Get the property list of current bob process */
80   xbt_dict_t props         = MSG_process_get_properties(MSG_process_self());
81   xbt_dict_cursor_t cursor = NULL;
82   char* key;
83   char* data;
84   const char* noexist = "UnknownProcessProp";
85   XBT_ATTRIB_UNUSED const char* value;
86
87   XBT_INFO("== Print the properties of the process");
88   xbt_dict_foreach (props, cursor, key, data)
89     XBT_INFO("   Process property: %s -> %s", key, data);
90
91   XBT_INFO("== Try to get a process property that does not exist");
92
93   value = MSG_process_get_property_value(MSG_process_self(), noexist);
94   xbt_assert(!value, "The property is defined (it shouldnt)");
95   xbt_dict_free(&props);
96
97   return 0;
98 }
99
100 int main(int argc, char* argv[])
101 {
102   unsigned int i;
103   msg_host_t host;
104
105   MSG_init(&argc, argv);
106   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
107                        "\tExample: %s msg_platform.xml msg_deployment.xml\n",
108              argv[0], argv[0]);
109
110   MSG_function_register("alice", alice);
111   MSG_function_register("bob", bob);
112   MSG_function_register("carole", carole);
113   MSG_function_register("david", david);
114
115   MSG_create_environment(argv[1]);
116
117   XBT_INFO("There are %zu hosts in the environment", MSG_get_host_number());
118
119   xbt_dynar_t hosts = MSG_hosts_as_dynar();
120   xbt_dynar_foreach (hosts, i, host) {
121     XBT_INFO("Host '%s' runs at %.0f flops/s", MSG_host_get_name(host), MSG_host_get_speed(host));
122   }
123   xbt_dynar_free(&hosts);
124
125   MSG_launch_application(argv[2]);
126
127   msg_error_t res = MSG_main();
128
129   return res != MSG_OK;
130 }