Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add gras prop tests to the make check
[simgrid.git] / examples / gras / properties / properties.c
1 /*      $Id$     */
2
3 #include "gras.h"
4
5 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Simple Property example");
6
7 int master(int argc, char *argv[]);
8 int slave(int argc, char *argv[]);
9
10
11 int slave(int argc, char *argv[]) {
12   gras_init(&argc,argv);
13
14   /* Get the properties */
15   xbt_dict_t props = gras_process_properties();
16   xbt_dict_cursor_t cursor = NULL;
17   char *key,*data;
18
19   /* Print the properties of the workstation 1 */
20   xbt_dict_foreach(props,cursor,key,data) {
21     INFO2("Process property: %s has value: %s",key,data);
22   }
23  
24   /* Try to get a property that does not exist */
25   const char *noexist="Nonexisting";
26   const char *value = gras_process_property_value(noexist);
27   if ( value == NULL) 
28     INFO1("Process property: %s is undefined", noexist);
29   else
30     INFO2("Process property: %s has value: %s", noexist, value);
31  
32    /* Modify an existing property. First check it exists */
33     INFO0("Trying to modify a process property");
34     const char *exist="otherprop";
35     value = gras_process_property_value(exist);
36     if (value == NULL) 
37       INFO1("\tProperty: %s is undefined", exist);
38     else {
39       INFO2("\tProperty: %s old value: %s", exist, value);
40       xbt_dict_set(props, exist, xbt_strdup("newValue"), free);  
41     }
42  
43     /* Test if we have changed the value */
44     value = gras_process_property_value(exist);
45     if (value == NULL) 
46       INFO1("\tProperty: %s is undefined", exist);
47     else
48       INFO2("\tProperty: %s new value: %s", exist, value);
49
50   gras_os_sleep(1);
51   gras_exit();
52   return 0;
53 }
54
55 int master(int argc, char *argv[]) {
56   gras_init(&argc,argv);
57
58   /* Get the properties */
59   xbt_dict_t props = gras_os_host_properties();
60   xbt_dict_cursor_t cursor = NULL;
61   char *key,*data;
62
63   /* Print the properties of the workstation 1 */
64   xbt_dict_foreach(props,cursor,key,data) {
65     INFO2("Host property: %s has value: %s",key,data);
66   }
67  
68   /* Try to get a property that does not exist */
69   const char *noexist="Nonexisting";
70   const char *value = gras_os_host_property_value(noexist);
71   xbt_assert2(value == NULL, "Host property: %s has value: %s", noexist, value);
72   
73   gras_os_sleep(1);
74   gras_exit();
75   return 0;
76 }