Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
For tesh, produce the same output for different context settings
[simgrid.git] / src / xbt / config.c
index 138076c..f5fd93c 100644 (file)
@@ -18,6 +18,7 @@
 #include "xbt/peer.h"
 
 #include "xbt/config.h"         /* prototypes of this module */
+#include "surf/surf.h"                 /* COORD_HOST_LEVEL and COORD_ASR_LEVEL */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_cfg, xbt, "configuration support");
 
@@ -83,7 +84,7 @@ void xbt_cfg_cpy(xbt_cfg_t tocopy, xbt_cfg_t * whereto)
 
   XBT_DEBUG("Copy cfg set %p", tocopy);
   *whereto = NULL;
-  xbt_assert0(tocopy, "cannot copy NULL config");
+  xbt_assert(tocopy, "cannot copy NULL config");
 
   xbt_dict_foreach((xbt_dict_t) tocopy, cursor, name, variable) {
     xbt_cfg_register(whereto, name, variable->desc, variable->type, NULL,
@@ -211,7 +212,7 @@ xbt_cfg_register(xbt_cfg_t * cfg,
 
   if (*cfg == NULL)
     *cfg = xbt_cfg_new();
-  xbt_assert4(type >= xbt_cfgelm_int && type <= xbt_cfgelm_peer,
+  xbt_assert(type >= xbt_cfgelm_int && type <= xbt_cfgelm_peer,
               "type of %s not valid (%d should be between %d and %d)",
               name, type, xbt_cfgelm_int, xbt_cfgelm_peer);
   res = xbt_dict_get_or_null((xbt_dict_t) * cfg, name);
@@ -291,7 +292,7 @@ void xbt_cfg_unregister(xbt_cfg_t cfg, const char *name)
  * Each of them must use the following syntax: \<name\>:\<min nb\>_to_\<max nb\>_\<type\>
  * with type being one of  'string','int', 'peer' or 'double'.
  *
- * @fixme: this does not allow to set the description
+ * FIXME: this does not allow to set the description
  */
 
 void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry)
@@ -304,31 +305,32 @@ void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry)
   XBT_DEBUG("Register string '%s'", entry);
 
   tok = strchr(entrycpy, ':');
-  xbt_assert2(tok, "Invalid config element descriptor: %s%s",
+  xbt_assert(tok, "Invalid config element descriptor: %s%s",
               entry, "; Should be <name>:<min nb>_to_<max nb>_<type>");
   *(tok++) = '\0';
 
   min = strtol(tok, &tok, 10);
-  xbt_assert1(tok, "Invalid minimum in config element descriptor %s",
+  xbt_assert(tok, "Invalid minimum in config element descriptor %s",
               entry);
 
-  xbt_assert2(strcmp(tok, "_to_"),
+  xbt_assert(strcmp(tok, "_to_"),
               "Invalid config element descriptor : %s%s",
               entry, "; Should be <name>:<min nb>_to_<max nb>_<type>");
   tok += strlen("_to_");
 
   max = strtol(tok, &tok, 10);
-  xbt_assert1(tok, "Invalid maximum in config element descriptor %s",
+  xbt_assert(tok, "Invalid maximum in config element descriptor %s",
               entry);
 
-  xbt_assert2(*(tok++) == '_',
+  xbt_assert(*tok == '_',
               "Invalid config element descriptor: %s%s", entry,
               "; Should be <name>:<min nb>_to_<max nb>_<type>");
+  tok++;
 
   for (type = 0;
        type < xbt_cfgelm_type_count
        && strcmp(tok, xbt_cfgelm_type_name[type]); type++);
-  xbt_assert2(type < xbt_cfgelm_type_count,
+  xbt_assert(type < xbt_cfgelm_type_count,
               "Invalid type in config element descriptor: %s%s", entry,
               "; Should be one of 'string', 'int', 'peer' or 'double'.");
 
@@ -424,14 +426,14 @@ void xbt_cfg_check(xbt_cfg_t cfg)
   char *name;
   int size;
 
-  xbt_assert0(cfg, "NULL config set.");
+  xbt_assert(cfg, "NULL config set.");
   XBT_DEBUG("Check cfg set %p", cfg);
 
   xbt_dict_foreach((xbt_dict_t) cfg, cursor, name, variable) {
     size = xbt_dynar_length(variable->content);
     if (variable->min > size) {
       xbt_dict_cursor_free(&cursor);
-      THROW4(mismatch_error, 0,
+      THROWF(mismatch_error, 0,
              "Config elem %s needs at least %d %s, but there is only %d values.",
              name, variable->min, xbt_cfgelm_type_name[variable->type],
              size);
@@ -439,7 +441,7 @@ void xbt_cfg_check(xbt_cfg_t cfg)
 
     if (variable->max > 0 && variable->max < size) {
       xbt_dict_cursor_free(&cursor);
-      THROW4(mismatch_error, 0,
+      THROWF(mismatch_error, 0,
              "Config elem %s accepts at most %d %s, but there is %d values.",
              name, variable->max, xbt_cfgelm_type_name[variable->type],
              size);
@@ -458,11 +460,11 @@ static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg,
   res = xbt_dict_get_or_null((xbt_dict_t) cfg, name);
   if (!res) {
     xbt_cfg_help(cfg);
-    THROW1(not_found_error, 0,
+    THROWF(not_found_error, 0,
            "No registered variable '%s' in this config set", name);
   }
 
-  xbt_assert3(type == xbt_cfgelm_any || res->type == type,
+  xbt_assert(type == xbt_cfgelm_any || res->type == type,
               "You tried to access to the config element %s as an %s, but its type is %s.",
               name,
               xbt_cfgelm_type_name[type], xbt_cfgelm_type_name[res->type]);
@@ -485,7 +487,7 @@ e_xbt_cfgelm_type_t xbt_cfg_get_type(xbt_cfg_t cfg, const char *name)
 
   variable = xbt_dict_get_or_null((xbt_dict_t) cfg, name);
   if (!variable)
-    THROW1(not_found_error, 0,
+    THROWF(not_found_error, 0,
            "Can't get the type of '%s' since this variable does not exist",
            name);
 
@@ -517,7 +519,7 @@ void xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa)
   } CATCH(e) {
     if (e.category == not_found_error) {
       xbt_ex_free(e);
-      THROW1(not_found_error, 0,
+      THROWF(not_found_error, 0,
              "Can't set the property '%s' since it's not registered",
              name);
     }
@@ -547,8 +549,7 @@ void xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa)
     break;
 
   default:
-    xbt_die(bprintf("Config element variable %s not valid (type=%d)", name,
-                type));
+    xbt_die("Config element variable %s not valid (type=%d)", name, type);
   }
 }
 
@@ -645,13 +646,24 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
     val = strchr(name, ':');
     if (!val) {
       free(optionlist_cpy);
-      xbt_die(bprintf(
-                  "Option '%s' badly formated. Should be of the form 'name:value'",
-                  name));
+      xbt_die("Option '%s' badly formated. Should be of the form 'name:value'",
+              name);
     }
     *(val++) = '\0';
 
-    if (strcmp(name,"contexts/factory"))
+    if (!strcmp(name,"coordinates")){
+       if(!strcmp(val,"yes") && !COORD_HOST_LEVEL){
+               XBT_INFO("Configuration change: Set '%s' to '%s'", name, val);
+                       COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
+                       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
+                       free(optionlist_cpy);
+                       return;
+       }
+       if(strcmp(val,"yes"))
+               xbt_die("Setting CMD prop coordinates must be \"yes\"");
+    }
+
+    if (strncmp(name, "contexts/", strlen("contexts/")))
       XBT_INFO("Configuration change: Set '%s' to '%s'", name, val);
 
     TRY {
@@ -663,7 +675,7 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
       free(optionlist_cpy);
       if (e.category == not_found_error) {
         xbt_ex_free(e);
-        THROW1(not_found_error, 0,
+        THROWF(not_found_error, 0,
                "No registered variable corresponding to '%s'.", name);
       }
       RETHROW;
@@ -679,9 +691,7 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
         i = strtol(val, &val, 0);
         if (val == NULL) {
           free(optionlist_cpy);
-          xbt_die(bprintf(
-                      "Value of option %s not valid. Should be an integer",
-                      name));
+          xbt_die("Value of option %s not valid. Should be an integer", name);
         }
 
         xbt_cfg_set_int(cfg, name, i);  /* throws */
@@ -691,9 +701,7 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
         d = strtod(val, &val);
         if (val == NULL) {
           free(optionlist_cpy);
-          xbt_die(bprintf(
-                      "Value of option %s not valid. Should be a double",
-                      name));
+          xbt_die("Value of option %s not valid. Should be a double", name);
         }
 
         xbt_cfg_set_double(cfg, name, d);       /* throws */
@@ -704,25 +712,23 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
         val = strchr(val, ':');
         if (!val) {
           free(optionlist_cpy);
-          xbt_die(bprintf(
-                      "Value of option %s not valid. Should be an peer (machine:port)",
-                      name));
+          xbt_die("Value of option %s not valid. Should be an peer (machine:port)",
+                  name);
         }
 
         *(val++) = '\0';
         i = strtol(val, &val, 0);
         if (val == NULL) {
           free(optionlist_cpy);
-          xbt_die(bprintf(
-                      "Value of option %s not valid. Should be an peer (machine:port)",
-                      name));
+          xbt_die("Value of option %s not valid. Should be an peer (machine:port)",
+                  name);
         }
 
         xbt_cfg_set_peer(cfg, name, str, i);    /* throws */
         break;
 
       default:
-        THROW1(unknown_error, 0, "Type of config element %s is not valid.",
+        THROWF(unknown_error, 0, "Type of config element %s is not valid.",
                name);
       }
     }
@@ -835,7 +841,7 @@ void xbt_cfg_set_int(xbt_cfg_t cfg, const char *name, int val)
     if (variable->max
         && xbt_dynar_length(variable->content) ==
         (unsigned long) variable->max)
-      THROW3(mismatch_error, 0,
+      THROWF(mismatch_error, 0,
              "Cannot add value %d to the config element %s since it's already full (size=%d)",
              val, name, variable->max);
 
@@ -869,7 +875,7 @@ void xbt_cfg_set_double(xbt_cfg_t cfg, const char *name, double val)
   } else {
     if (variable->max
         && xbt_dynar_length(variable->content) == variable->max)
-      THROW3(mismatch_error, 0,
+      THROWF(mismatch_error, 0,
              "Cannot add value %f to the config element %s since it's already full (size=%d)",
              val, name, variable->max);
 
@@ -914,7 +920,7 @@ void xbt_cfg_set_string(xbt_cfg_t cfg, const char *name, const char *val)
   } else {
     if (variable->max
         && xbt_dynar_length(variable->content) == variable->max)
-      THROW3(mismatch_error, 0,
+      THROWF(mismatch_error, 0,
              "Cannot add value %s to the config element %s since it's already full (size=%d)",
              name, val, variable->max);
 
@@ -955,7 +961,7 @@ xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name, const char *peer,
   } else {
     if (variable->max
         && xbt_dynar_length(variable->content) == variable->max)
-      THROW4(mismatch_error, 0,
+      THROWF(mismatch_error, 0,
              "Cannot add value %s:%d to the config element %s since it's already full (size=%d)",
              peer, port, name, variable->max);
 
@@ -985,7 +991,7 @@ void xbt_cfg_rm_int(xbt_cfg_t cfg, const char *name, int val)
   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_int);
 
   if (xbt_dynar_length(variable->content) == variable->min)
-    THROW3(mismatch_error, 0,
+    THROWF(mismatch_error, 0,
            "Cannot remove value %d from the config element %s since it's already at its minimal size (=%d)",
            val, name, variable->min);
 
@@ -998,7 +1004,7 @@ void xbt_cfg_rm_int(xbt_cfg_t cfg, const char *name, int val)
     }
   }
 
-  THROW2(not_found_error, 0,
+  THROWF(not_found_error, 0,
          "Can't remove the value %d of config element %s: value not found.",
          val, name);
 }
@@ -1019,7 +1025,7 @@ void xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name, double val)
   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_double);
 
   if (xbt_dynar_length(variable->content) == variable->min)
-    THROW3(mismatch_error, 0,
+    THROWF(mismatch_error, 0,
            "Cannot remove value %f from the config element %s since it's already at its minimal size (=%d)",
            val, name, variable->min);
 
@@ -1032,7 +1038,7 @@ void xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name, double val)
     }
   }
 
-  THROW2(not_found_error, 0,
+  THROWF(not_found_error, 0,
          "Can't remove the value %f of config element %s: value not found.",
          val, name);
 }
@@ -1052,7 +1058,7 @@ void xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name, const char *val)
   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_string);
 
   if (xbt_dynar_length(variable->content) == variable->min)
-    THROW3(mismatch_error, 0,
+    THROWF(mismatch_error, 0,
            "Cannot remove value %s from the config element %s since it's already at its minimal size (=%d)",
            name, val, variable->min);
 
@@ -1065,7 +1071,7 @@ void xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name, const char *val)
     }
   }
 
-  THROW2(not_found_error, 0,
+  THROWF(not_found_error, 0,
          "Can't remove the value %s of config element %s: value not found.",
          val, name);
 }
@@ -1089,7 +1095,7 @@ xbt_cfg_rm_peer(xbt_cfg_t cfg, const char *name, const char *peer,
   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_peer);
 
   if (xbt_dynar_length(variable->content) == variable->min)
-    THROW4(mismatch_error, 0,
+    THROWF(mismatch_error, 0,
            "Cannot remove value %s:%d from the config element %s since it's already at its minimal size (=%d)",
            peer, port, name, variable->min);
 
@@ -1102,7 +1108,7 @@ xbt_cfg_rm_peer(xbt_cfg_t cfg, const char *name, const char *peer,
     }
   }
 
-  THROW3(not_found_error, 0,
+  THROWF(not_found_error, 0,
          "Can't remove the value %s:%d of config element %s: value not found.",
          peer, port, name);
 }
@@ -1117,7 +1123,7 @@ void xbt_cfg_rm_at(xbt_cfg_t cfg, const char *name, int pos)
   variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_any);
 
   if (xbt_dynar_length(variable->content) == variable->min)
-    THROW3(mismatch_error, 0,
+    THROWF(mismatch_error, 0,
            "Cannot remove %dth value from the config element %s since it's already at its minimal size (=%d)",
            pos, name, variable->min);
 
@@ -1144,7 +1150,7 @@ void xbt_cfg_empty(xbt_cfg_t cfg, const char *name)
       RETHROW;
 
     xbt_ex_free(e);
-    THROW1(not_found_error, 0,
+    THROWF(not_found_error, 0,
            "Can't empty  '%s' since this config element does not exist",
            name);
   }
@@ -1303,7 +1309,7 @@ xbt_dynar_t xbt_cfg_get_dynar(xbt_cfg_t cfg, const char *name)
   } CATCH(e) {
     if (e.category == not_found_error) {
       xbt_ex_free(e);
-      THROW1(not_found_error, 0,
+      THROWF(not_found_error, 0,
              "No registered variable %s in this config set", name);
     }
     RETHROW;
@@ -1376,7 +1382,7 @@ static xbt_cfg_t make_set()
 XBT_TEST_UNIT("memuse", test_config_memuse, "Alloc and free a config set")
 {
   xbt_cfg_t set = make_set();
-  xbt_test_add0("Alloc and free a config set");
+  xbt_test_add("Alloc and free a config set");
   xbt_cfg_set_parse(set,
                     "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
   xbt_cfg_free(&set);
@@ -1388,7 +1394,7 @@ XBT_TEST_UNIT("validation", test_config_validation, "Validation tests")
   xbt_cfg_t set = set = make_set();
   xbt_ex_t e;
 
-  xbt_test_add0("Having too few elements for speed");
+  xbt_test_add("Having too few elements for speed");
   xbt_cfg_set_parse(set,
                     "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
   TRY {
@@ -1398,7 +1404,7 @@ XBT_TEST_UNIT("validation", test_config_validation, "Validation tests")
     if (e.category != mismatch_error ||
         strncmp(e.msg, "Config elem speed needs",
                 strlen("Config elem speed needs")))
-      xbt_test_fail1("Got an exception. msg=%s", e.msg);
+      xbt_test_fail("Got an exception. msg=%s", e.msg);
     xbt_ex_free(e);
   }
   xbt_cfg_free(&set);
@@ -1406,7 +1412,7 @@ XBT_TEST_UNIT("validation", test_config_validation, "Validation tests")
 
 
 
-  xbt_test_add0("Having too much values of 'speed'");
+  xbt_test_add("Having too much values of 'speed'");
   set = make_set();
   xbt_cfg_set_parse(set, "peername:toto:42 user:alegrand");
   TRY {
@@ -1416,7 +1422,7 @@ XBT_TEST_UNIT("validation", test_config_validation, "Validation tests")
     if (e.category != mismatch_error ||
         strncmp(e.msg, "Cannot add value 34 to the config elem speed",
                 strlen("Config elem speed needs")))
-      xbt_test_fail1("Got an exception. msg=%s", e.msg);
+      xbt_test_fail("Got an exception. msg=%s", e.msg);
     xbt_ex_free(e);
   }
   xbt_cfg_check(set);
@@ -1428,7 +1434,7 @@ XBT_TEST_UNIT("validation", test_config_validation, "Validation tests")
 XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests")
 {
 
-  xbt_test_add0("Get a single value");
+  xbt_test_add("Get a single value");
   {
     /* get_single_value */
     int ival;
@@ -1437,11 +1443,11 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests")
     xbt_cfg_set_parse(myset, "peername:toto:42 speed:42");
     ival = xbt_cfg_get_int(myset, "speed");
     if (ival != 42)
-      xbt_test_fail1("Speed value = %d, I expected 42", ival);
+      xbt_test_fail("Speed value = %d, I expected 42", ival);
     xbt_cfg_free(&myset);
   }
 
-  xbt_test_add0("Get multiple values");
+  xbt_test_add("Get multiple values");
   {
     /* get_multiple_value */
     xbt_dynar_t dyn;
@@ -1454,24 +1460,24 @@ XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests")
     dyn = xbt_cfg_get_dynar(myset, "user");
 
     if (xbt_dynar_length(dyn) != 3)
-      xbt_test_fail1("Dynar length = %lu, I expected 3",
+      xbt_test_fail("Dynar length = %lu, I expected 3",
                      xbt_dynar_length(dyn));
 
     if (strcmp(xbt_dynar_get_as(dyn, 0, char *), "foo"))
-       xbt_test_fail1("Dynar[0] = %s, I expected foo",
+       xbt_test_fail("Dynar[0] = %s, I expected foo",
                       xbt_dynar_get_as(dyn, 0, char *));
 
     if (strcmp(xbt_dynar_get_as(dyn, 1, char *), "bar"))
-       xbt_test_fail1("Dynar[1] = %s, I expected bar",
+       xbt_test_fail("Dynar[1] = %s, I expected bar",
                       xbt_dynar_get_as(dyn, 1, char *));
 
     if (strcmp(xbt_dynar_get_as(dyn, 2, char *), "toto"))
-       xbt_test_fail1("Dynar[2] = %s, I expected toto",
+       xbt_test_fail("Dynar[2] = %s, I expected toto",
                       xbt_dynar_get_as(dyn, 2, char *));
     xbt_cfg_free(&myset);
   }
 
-  xbt_test_add0("Access to a non-existant entry");
+  xbt_test_add("Access to a non-existant entry");
   {
     /* non-existant_entry */
     xbt_cfg_t myset = make_set();