1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
9 #include "simgrid/simdag.h"
12 #include "xbt/dynar.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
17 int main(int argc, char **argv)
24 xbt_dict_cursor_t cursor = NULL;
26 char noexist[] = "NoProp";
30 /* SD initialization */
33 "Usage: %s platform_file\n\tExample: %s ../two_hosts.xml",
36 SD_create_environment(argv[1]);
38 /* init of platform elements */
39 w1 = sg_host_by_name("host1");
40 w2 = sg_host_by_name("host2");
41 name1 = sg_host_get_name(w1);
42 name2 = sg_host_get_name(w2);
45 /* The host properties can be retrieved from all interfaces */
47 XBT_INFO("Property list for workstation %s", name1);
48 /* Get the property list of the workstation 1 */
49 props = sg_host_get_properties(w1);
52 /* Trying to set a new property */
53 xbt_dict_set(props, "NewProp", strdup("newValue"), xbt_free_f);
55 /* Print the properties of the workstation 1 */
56 xbt_dict_foreach(props, cursor, key, data) {
57 XBT_INFO("\tProperty: %s has value: %s", key, data);
60 /* Try to get a property that does not exist */
62 value = sg_host_get_property_value(w1, noexist);
63 XBT_INFO("\tProperty: %s has value: %s", noexist, value?value:"Undefined (NULL)");
66 XBT_INFO("Property list for workstation %s", name2);
67 /* Get the property list of the workstation 2 */
68 props = sg_host_get_properties(w2);
71 /* Print the properties of the workstation 2 */
72 xbt_dict_foreach(props, cursor, key, data) {
73 XBT_INFO("\tProperty: %s on host: %s", key, data);
76 /* Modify an existing property test. First check it exists */
77 XBT_INFO("Modify an existing property");
79 value = sg_host_get_property_value(w2, exist);
81 XBT_INFO("\tProperty: %s is undefined", exist);
83 XBT_INFO("\tProperty: %s old value: %s", exist, value);
84 xbt_dict_set(props, exist, strdup("250"), xbt_free_f);
87 /* Test if we have changed the value */
88 value = sg_host_get_property_value(w2, exist);
89 XBT_INFO("\tProperty: %s new value: %s", exist, value?value:"Undefined (NULL)");
91 /* Test if properties are displayed by sg_host_dump */