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;
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"),
49 /* Test if we have changed the value */
50 value = gras_process_property_value("new prop");
51 xbt_assert(!strcmp(value, "new value"),
52 "New property does have the value I've set ('%s' != 'new value')",
59 int bob(int argc, char *argv[])
61 gras_init(&argc, argv);
63 /* Get the properties */
64 xbt_dict_t host_props = gras_os_host_properties();
65 xbt_dict_cursor_t cursor = NULL;
69 XBT_INFO("== Dump all the properties of host1");
70 xbt_dict_foreach(host_props, cursor, key, data)
71 XBT_INFO(" Host property: '%s' has value: '%s'", key, data);
73 XBT_INFO("== Try to get a property that does not exist");
74 value = gras_os_host_property_value("non existing key");
75 xbt_assert(value == NULL,
76 "The key 'non existing key' exists (with value '%s')!!",
80 ("== Set a host property that alice will try to retrieve in SG (from bob->hello)");
81 xbt_dict_set(host_props, "from bob", xbt_strdup("hello"), xbt_free_f);
83 XBT_INFO("== Dump all the properties of host1 again to check the addition");
84 xbt_dict_foreach(host_props, cursor, key, data)
85 XBT_INFO(" Host property: '%s' has value: '%s'", key, data);
87 gras_os_sleep(1); /* KILLME once bug on empty main is solved */