5 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Simple Property example");
7 int alice(int argc, char *argv[]);
8 int bob(int argc, char *argv[]);
10 int alice(int argc, char *argv[])
12 gras_init(&argc, argv);
14 /* Get the properties */
15 xbt_dict_t process_props = gras_process_properties();
16 xbt_dict_t host_props = gras_os_host_properties();
18 xbt_dict_cursor_t cursor = NULL;
22 /* Let the other process change the host props */
25 INFO0("== Dump all the properties of current host");
26 xbt_dict_foreach(host_props, cursor, key, data)
27 INFO2(" Host property: '%s' has value: '%s'", key, data);
29 INFO0("== Dump all the properties of alice");
30 xbt_dict_foreach(process_props, cursor, key, data)
31 if (!strncmp(key, "SG_TEST_", 8))
32 INFO2(" Process property: '%s' has value: '%s'", key, data);
34 INFO0("== Try to get a process property that does not exist");
35 value = gras_process_property_value("Nonexisting");
36 xbt_assert0(!value, "nonexisting property exists!!");
38 /* Modify an existing property. First check it exists */
39 INFO0("== Trying to modify a process property");
40 value = gras_process_property_value("new prop");
41 xbt_assert0(!value, "Property 'new prop' exists before I add it!");
42 xbt_dict_set(process_props, "new prop", xbt_strdup("new value"),
45 /* Test if we have changed the value */
46 value = gras_process_property_value("new prop");
47 xbt_assert1(!strcmp(value, "new value"),
48 "New property does have the value I've set ('%s' != 'new value')",
55 int bob(int argc, char *argv[])
57 gras_init(&argc, argv);
59 /* Get the properties */
60 xbt_dict_t host_props = gras_os_host_properties();
61 xbt_dict_cursor_t cursor = NULL;
65 INFO0("== Dump all the properties of host1");
66 xbt_dict_foreach(host_props, cursor, key, data)
67 INFO2(" Host property: '%s' has value: '%s'", key, data);
69 INFO0("== Try to get a property that does not exist");
70 value = gras_os_host_property_value("non existing key");
71 xbt_assert1(value == NULL,
72 "The key 'non existing key' exists (with value '%s')!!", value);
75 ("== Set a host property that alice will try to retrieve in SG (from bob->hello)");
76 xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), xbt_free_f);
78 INFO0("== Dump all the properties of host1 again to check the addition");
79 xbt_dict_foreach(host_props, cursor, key, data)
80 INFO2(" Host property: '%s' has value: '%s'", key, data);
82 gras_os_sleep(1); /* KILLME once bug on empty main is solved */