1 /* Copyright (c) 2007, 2008, 2009, 2010. 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 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Simple Property example");
11 int alice(int argc, char *argv[]);
12 int bob(int argc, char *argv[]);
14 int alice(int argc, char *argv[])
16 gras_init(&argc, argv);
18 /* Get the properties */
19 xbt_dict_t process_props = gras_process_properties();
20 xbt_dict_t host_props = gras_os_host_properties();
22 xbt_dict_cursor_t cursor = NULL;
24 _XBT_GNUC_UNUSED const char *value;
26 /* Let the other process change the host props */
29 XBT_INFO("== Dump all the properties of current host");
30 xbt_dict_foreach(host_props, cursor, key, data)
31 XBT_INFO(" Host property: '%s' has value: '%s'", key, data);
33 XBT_INFO("== Dump all the properties of alice");
34 xbt_dict_foreach(process_props, cursor, key, data)
35 if (!strncmp(key, "SG_TEST_", 8))
36 XBT_INFO(" Process property: '%s' has value: '%s'", key, data);
38 XBT_INFO("== Try to get a process property that does not exist");
39 value = gras_process_property_value("Nonexisting");
40 xbt_assert(!value, "nonexisting property exists!!");
42 /* Modify an existing property. First check it exists */
43 XBT_INFO("== Trying to modify a process property");
44 value = gras_process_property_value("new prop");
45 xbt_assert(!value, "Property 'new prop' exists before I add it!");
46 xbt_dict_set(process_props, "new prop", xbt_strdup("new value"), NULL);
48 /* Test if we have changed the value */
49 value = gras_process_property_value("new prop");
50 xbt_assert(!strcmp(value, "new value"),
51 "New property does have the value I've set ('%s' != 'new value')",
58 int bob(int argc, char *argv[])
60 gras_init(&argc, argv);
62 /* Get the properties */
63 xbt_dict_t host_props = gras_os_host_properties();
64 xbt_dict_cursor_t cursor = NULL;
66 _XBT_GNUC_UNUSED const char *value;
68 XBT_INFO("== Dump all the properties of host1");
69 xbt_dict_foreach(host_props, cursor, key, data)
70 XBT_INFO(" Host property: '%s' has value: '%s'", key, data);
72 XBT_INFO("== Try to get a property that does not exist");
73 value = gras_os_host_property_value("non existing key");
74 xbt_assert(value == NULL,
75 "The key 'non existing key' exists (with value '%s')!!",
79 ("== Set a host property that alice will try to retrieve in SG (from bob->hello)");
80 xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), NULL);
82 XBT_INFO("== Dump all the properties of host1 again to check the addition");
83 xbt_dict_foreach(host_props, cursor, key, data)
84 XBT_INFO(" Host property: '%s' has value: '%s'", key, data);
86 gras_os_sleep(1); /* KILLME once bug on empty main is solved */