Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Set level COORD_HOST_LEVEL and COORD_ASR_LEVEL if there are used.
[simgrid.git] / src / xbt / config.c
index 2b18cc8..fc93278 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");
 
@@ -321,9 +322,10 @@ void xbt_cfg_register_str(xbt_cfg_t * cfg, const char *entry)
   xbt_assert1(tok, "Invalid maximum in config element descriptor %s",
               entry);
 
-  xbt_assert2(*(tok++) == '_',
+  xbt_assert2(*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
@@ -547,8 +549,7 @@ void xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa)
     break;
 
   default:
-    xbt_assert2(0, "Config element variable %s not valid (type=%d)", name,
-                type);
+    xbt_die("Config element variable %s not valid (type=%d)", name, type);
   }
 }
 
@@ -594,7 +595,7 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
 
   int len;
 
-  XBT_IN;
+  XBT_IN("");
   if (!options || !strlen(options)) {   /* nothing to do */
     return;
   }
@@ -645,12 +646,23 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
     val = strchr(name, ':');
     if (!val) {
       free(optionlist_cpy);
-      xbt_assert1(FALSE,
-                  "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,"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 (strcmp(name,"contexts/factory"))
       XBT_INFO("Configuration change: Set '%s' to '%s'", name, val);
 
@@ -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_assert1(FALSE,
-                      "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_assert1(FALSE,
-                      "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,18 +712,16 @@ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options)
         val = strchr(val, ':');
         if (!val) {
           free(optionlist_cpy);
-          xbt_assert1(FALSE,
-                      "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_assert1(FALSE,
-                      "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 */
@@ -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();