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[]) {
11 gras_init(&argc,argv);
13 /* Get the properties */
14 xbt_dict_t process_props = gras_process_properties();
15 xbt_dict_t host_props = gras_os_host_properties();
17 xbt_dict_cursor_t cursor = NULL;
21 /* Let the other process change the host props */
24 INFO0("== Dump all the properties of current host");
25 xbt_dict_foreach(host_props,cursor,key,data)
26 INFO2(" Host property: '%s' has value: '%s'",key,data);
28 INFO0("== Dump all the properties of alice");
29 xbt_dict_foreach(process_props,cursor,key,data)
30 if (!strncmp(key,"SG_TEST_",8))
31 INFO2(" Process property: '%s' has value: '%s'",key,data);
33 INFO0("== Try to get a process property that does not exist");
34 value = gras_process_property_value("Nonexisting");
35 xbt_assert0(!value, "nonexisting property exists!!");
37 /* Modify an existing property. First check it exists */
38 INFO0("== Trying to modify a process property");
39 value = gras_process_property_value("new prop");
40 xbt_assert0(!value,"Property 'new prop' exists before I add it!");
41 xbt_dict_set(process_props, "new prop", xbt_strdup("new value"), xbt_free_f);
43 /* Test if we have changed the value */
44 value = gras_process_property_value("new prop");
45 xbt_assert1(!strcmp(value,"new value"), "New property does have the value I've set ('%s' != 'new value')",value);
51 int bob(int argc, char *argv[]) {
52 gras_init(&argc,argv);
54 /* Get the properties */
55 xbt_dict_t host_props = gras_os_host_properties();
56 xbt_dict_cursor_t cursor = NULL;
60 INFO0("== Dump all the properties of host1");
61 xbt_dict_foreach(host_props,cursor,key,data)
62 INFO2(" Host property: '%s' has value: '%s'",key,data);
64 INFO0("== Try to get a property that does not exist");
65 value = gras_os_host_property_value("non existing key");
66 xbt_assert1(value == NULL, "The key 'non existing key' exists (with value '%s')!!",value);
68 INFO0("== Set a host property that alice will try to retrieve in SG (from bob->hello)");
69 xbt_dict_set(host_props,"from bob",xbt_strdup("hello"), xbt_free_f);
71 INFO0("== Dump all the properties of host1 again to check the addition");
72 xbt_dict_foreach(host_props,cursor,key,data)
73 INFO2(" Host property: '%s' has value: '%s'",key,data);
75 gras_os_sleep(1); /* KILLME once bug on empty main is solved */