Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surfxml: better error checking, and less include of internal headers
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 20 Feb 2016 22:54:35 +0000 (23:54 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 20 Feb 2016 22:54:35 +0000 (23:54 +0100)
18 files changed:
include/surf/surfxml_parse.h
src/bindings/java/jmsg.cpp
src/simix/smx_deployment.cpp
src/surf/network_ib.cpp
src/surf/network_ns3.cpp
src/surf/network_smpi.cpp
src/surf/sg_platf.cpp
src/surf/storage_n11.cpp
src/surf/surf_interface.cpp
src/surf/surf_private.h
src/surf/surf_routing.cpp
src/surf/surf_routing_cluster_fat_tree.cpp
src/surf/surf_routing_cluster_torus.cpp
src/surf/surf_routing_private.hpp
src/surf/surfxml_parse.cpp
src/surf/surfxml_parseplatf.cpp
teshsuite/simdag/platforms/bogus_missing_gateway.tesh
teshsuite/simix/stack_overflow/stack_overflow.c

index 83957d1..df7bf03 100644 (file)
@@ -22,11 +22,10 @@ typedef size_t yy_size_t;
 
 XBT_PUBLIC(void) surf_parse_open(const char *file);
 XBT_PUBLIC(void) surf_parse_close(void);
-XBT_PUBLIC(void) surf_parse_init_callbacks(void);
-XBT_PUBLIC(void) surf_parse_reset_callbacks(void);
-XBT_PUBLIC(void) surf_parse_free_callbacks(void);
+XBT_PUBLIC(void) surf_parse_assert(bool cond, const char *fmt, ...) XBT_ATTRIB_PRINTF(2,3);
 XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
 XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
+
 XBT_PUBLIC(double) surf_parse_get_double(const char *string);
 XBT_PUBLIC(int) surf_parse_get_int(const char *string);
 XBT_PUBLIC(double) surf_parse_get_time(const char *string, const char *entity_kind, const char *name);
index b8300a4..868c517 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <simgrid/msg.h>
 #include <simgrid/simix.h>
-#include <surf/surfxml_parse.h>
 #include <locale.h>
 #include <src/simix/smx_private.h>
 
index 1b7be72..cc101f7 100644 (file)
@@ -17,7 +17,8 @@ extern int surf_parse_lineno;
 
 void SIMIX_init_application(void)
 {
-  surf_parse_reset_callbacks();
+  sg_platf_exit();
+  sg_platf_init();
 }
 
 /**
@@ -63,11 +64,9 @@ void SIMIX_launch_application(const char *file)
  * \param name the reference name of the function.
  * \param code the function
  */
-void SIMIX_function_register(const char *name,
-                                        xbt_main_func_t code)
+void SIMIX_function_register(const char *name, xbt_main_func_t code)
 {
-  xbt_assert(simix_global,
-              "SIMIX_global_init has to be called before SIMIX_function_register."); 
+  xbt_assert(simix_global, "SIMIX_global_init has to be called before SIMIX_function_register.");
   xbt_dict_set(simix_global->registered_functions, name, (void*) code, NULL);
 }
 
index 8f12161..5f52e8c 100644 (file)
@@ -104,6 +104,8 @@ void surf_network_model_init_IB(void)
   
 }
 
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
+
 namespace simgrid {
 namespace surf {
 
@@ -115,8 +117,8 @@ NetworkIBModel::NetworkIBModel()
   const char* IB_factors_string=sg_cfg_get_string("smpi/IB_penalty_factors");
   xbt_dynar_t radical_elements = xbt_str_split(IB_factors_string, ";");
   
-  if(xbt_dynar_length(radical_elements)!=3)
-    surf_parse_error("smpi/IB_penalty_factors should be provided and contain 3 elements, semi-colon separated : for example 0.965;0.925;1.35");
+  surf_parse_assert(xbt_dynar_length(radical_elements)==3,
+    "smpi/IB_penalty_factors should be provided and contain 3 elements, semi-colon separated : for example 0.965;0.925;1.35");
   
   Be = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 0, char *), "First part of smpi/IB_penalty_factors is not numerical: %s");
   Bs = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 1, char *), "Second part of smpi/IB_penalty_factors is not numerical: %s");
index 9a9a5e4..1711529 100644 (file)
@@ -65,6 +65,7 @@ static void parse_ns3_add_AS(simgrid::surf::As* as)
   xbt_lib_set(as_router_lib, as_id, NS3_ASR_LEVEL, ns3_add_AS(as_id) );
 }
 
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
 static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster)
 {
   const char *groups = NULL;
index f8422b4..004dec9 100644 (file)
@@ -32,7 +32,7 @@ static int factor_cmp(const void *pa, const void *pb)
          (((s_smpi_factor_t*)pa)->factor < ((s_smpi_factor_t*)pb)->factor) ? -1 : 0;
 }
 
-
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
 {
   char *value = NULL;
@@ -45,8 +45,8 @@ static xbt_dynar_t parse_factor(const char *smpi_coef_string)
   xbt_dynar_foreach(radical_elements, iter, value) {
 
     radical_elements2 = xbt_str_split(value, ":");
-    if (xbt_dynar_length(radical_elements2) != 2)
-      surf_parse_error("Malformed radical for smpi factor!");
+    surf_parse_assert(xbt_dynar_length(radical_elements2) == 2,
+        "Malformed radical '%s' for smpi factor. I was expecting something like 'a:b'", value);
 
     char *errmsg = bprintf("Invalid factor in chunk #%d: %%s", iter+1);
     fact.factor = xbt_str_parse_int(xbt_dynar_get_as(radical_elements2, 0, char *), errmsg);
index 500f481..2c4dd11 100644 (file)
@@ -55,6 +55,7 @@ void sg_platf_exit(void) {
 
   /* make sure that we will reinit the models while loading the platf once reinited */
   surf_parse_models_setup_already_called = 0;
+  surf_parse_lex_destroy();
 }
 
 /** @brief Add an "host" to the current AS */
index 6fc77ae..208f552 100644 (file)
@@ -80,6 +80,7 @@ StorageN11Model::~StorageN11Model(){
   storage_running_action_set_that_does_not_need_being_checked = NULL;
 }
 
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
 Storage *StorageN11Model::createStorage(const char* id, const char* type_id,
     const char* content_name, const char* content_type, xbt_dict_t properties,
     const char* attach)
index dccea91..a2624dd 100644 (file)
@@ -378,8 +378,7 @@ void surf_exit(void)
 #endif
 
   tmgr_finalize();
-  surf_parse_lex_destroy();
-  surf_parse_free_callbacks();
+  sg_platf_exit();
 
   NOW = 0;                      /* Just in case the user plans to restart the simulation afterward */
 }
index 9c6ed3c..1370cb1 100644 (file)
@@ -12,7 +12,6 @@
 #include "surf/surf.h"
 #include "surf/maxmin.h"
 #include "xbt/log.h"
-#include "surf/surfxml_parse.h"
 #include "src/surf/trace_mgr.hpp"
 #include "src/instr/instr_private.h"
 #include "surf/surfxml_parse_values.h"
index d0e9f2e..44f21cf 100644 (file)
@@ -20,6 +20,7 @@
 #include "src/surf/surf_routing_floyd.hpp"
 #include "src/surf/surf_routing_full.hpp"
 #include "src/surf/surf_routing_vivaldi.hpp"
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
 
 #include <vector>
 
index e68b89c..9580c26 100644 (file)
@@ -16,6 +16,9 @@
 #include <fstream>
 #include <sstream>
 
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
+
+
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_fat_tree, surf, "Routing for fat trees");
 
 namespace simgrid {
index 83151df..60ccb73 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "src/surf/surf_routing_private.hpp"
 #include "src/surf/surf_routing_cluster_torus.hpp"
+#include <surf/surfxml_parse.h> // FIXME: move that back to the parsing area
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_torus, surf_route_cluster, "Torus Routing part of surf");
 
index 5904dc9..041dda8 100644 (file)
@@ -16,7 +16,6 @@
 #include "xbt/str.h"
 #include "xbt/config.h"
 #include "xbt/graph.h"
-#include "surf/surfxml_parse.h"
 
 /* ************************************************************************** */
 /* ******************************* NO ROUTING ******************************* */
index 382d772..5e0aab1 100644 (file)
@@ -16,6 +16,8 @@
 #include "src/surf/surf_private.h"
 #include "simgrid/sg_config.h"
 
+#include <surf/surfxml_parse.h>
+
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf,
                                 "Logging specific to the SURF parsing module");
 #undef CLEANUP
@@ -29,6 +31,19 @@ xbt_dynar_t parsed_link_list = NULL;   /* temporary store of current list link o
 /*
  * Helping functions
  */
+void surf_parse_assert(bool cond, const char *fmt, ...) {
+  if (!cond ) {
+    va_list va;
+    va_start(va,fmt);
+    int lineno = surf_parse_lineno;
+    char *msg = bvprintf(fmt,va);
+    va_end(va);
+    cleanup();
+    XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
+    surf_exit();
+    xbt_die("Exiting now");
+  }
+}
 void surf_parse_error(const char *fmt, ...) {
   va_list va;
   va_start(va,fmt);
@@ -360,23 +375,6 @@ int ETag_surfxml_include_state(void)
   return 1;
 }
 
-
-void surf_parse_init_callbacks(void)
-{
-    sg_platf_init();
-}
-
-void surf_parse_reset_callbacks(void)
-{
-  surf_parse_free_callbacks();
-  surf_parse_init_callbacks();
-}
-
-void surf_parse_free_callbacks(void)
-{
-  sg_platf_exit();
-}
-
 /* Stag and Etag parse functions */
 
 void STag_surfxml_platform(void) {
@@ -722,44 +720,51 @@ void ETag_surfxml_backbone(void){
 }
 
 void STag_surfxml_route(void){
-  xbt_assert(strlen(A_surfxml_route_src) > 0 || strlen(A_surfxml_route_dst) > 0,
-      "Missing end-points while defining route \"%s\"->\"%s\"",
-      A_surfxml_route_src, A_surfxml_route_dst);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_src),
+      "Route src='%s' does name a node.", A_surfxml_route_src);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_route_dst),
+      "Route dst='%s' does name a node.", A_surfxml_route_dst);
   parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 }
 
 void STag_surfxml_ASroute(void){
-  xbt_assert(strlen(A_surfxml_ASroute_src) > 0
-             && strlen(A_surfxml_ASroute_dst) > 0
-             && strlen(A_surfxml_ASroute_gw___src) > 0
-             && strlen(A_surfxml_ASroute_gw___dst) > 0,
-             "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
-             A_surfxml_ASroute_src, A_surfxml_ASroute_dst,
-             A_surfxml_ASroute_gw___src, A_surfxml_ASroute_gw___dst);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_src),
+      "ASroute src='%s' does name a node.", A_surfxml_route_src);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_dst),
+      "ASroute dst='%s' does name a node.", A_surfxml_route_dst);
+
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___src),
+      "ASroute gw_src='%s' does name a node.", A_surfxml_ASroute_gw___src);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_ASroute_gw___dst),
+      "ASroute gw_dst='%s' does name a node.", A_surfxml_ASroute_gw___dst);
+
   parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 }
 
 void STag_surfxml_bypassRoute(void){
-  xbt_assert(strlen(A_surfxml_bypassRoute_src) > 0
-             && strlen(A_surfxml_bypassRoute_dst) > 0,
-             "Missing end-points while defining bypass route \"%s\"->\"%s\"",
-             A_surfxml_bypassRoute_src, A_surfxml_bypassRoute_dst);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_src),
+      "bypassRoute src='%s' does name a node.", A_surfxml_bypassRoute_src);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassRoute_dst),
+      "bypassRoute dst='%s' does name a node.", A_surfxml_bypassRoute_dst);
+
   parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 }
 
 void STag_surfxml_bypassASroute(void){
-  xbt_assert(strlen(A_surfxml_bypassASroute_src) > 0
-             && strlen(A_surfxml_bypassASroute_dst) > 0
-             && strlen(A_surfxml_bypassASroute_gw___src) > 0
-             && strlen(A_surfxml_bypassASroute_gw___dst) > 0,
-             "Missing end-points while defining route \"%s\"->\"%s\" (with %s and %s as gateways)",
-             A_surfxml_bypassASroute_src, A_surfxml_bypassASroute_dst,
-             A_surfxml_bypassASroute_gw___src,A_surfxml_bypassASroute_gw___dst);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_src),
+      "bypassASroute src='%s' does name a node.", A_surfxml_bypassASroute_src);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_dst),
+      "bypassASroute dst='%s' does name a node.", A_surfxml_bypassASroute_dst);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___src),
+      "bypassASroute gw_src='%s' does name a node.", A_surfxml_bypassASroute_gw___src);
+  surf_parse_assert(sg_netcard_by_name_or_null(A_surfxml_bypassASroute_gw___dst),
+      "bypassASroute gw_dst='%s' does name a node.", A_surfxml_bypassASroute_gw___dst);
+
   parsed_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 }
 
 void ETag_surfxml_route(void){
-  s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
+  s_sg_platf_route_cbarg_t route;
   memset(&route,0,sizeof(route));
 
   route.src       = A_surfxml_route_src;
@@ -783,7 +788,7 @@ void ETag_surfxml_route(void){
 }
 
 void ETag_surfxml_ASroute(void){
-  s_sg_platf_route_cbarg_t ASroute = SG_PLATF_ROUTE_INITIALIZER;
+  s_sg_platf_route_cbarg_t ASroute;
   memset(&ASroute,0,sizeof(ASroute));
 
   ASroute.src = A_surfxml_ASroute_src;
@@ -816,7 +821,7 @@ void ETag_surfxml_ASroute(void){
 }
 
 void ETag_surfxml_bypassRoute(void){
-  s_sg_platf_route_cbarg_t route = SG_PLATF_ROUTE_INITIALIZER;
+  s_sg_platf_route_cbarg_t route;
   memset(&route,0,sizeof(route));
 
   route.src = A_surfxml_bypassRoute_src;
@@ -831,7 +836,7 @@ void ETag_surfxml_bypassRoute(void){
 }
 
 void ETag_surfxml_bypassASroute(void){
-  s_sg_platf_route_cbarg_t ASroute = SG_PLATF_ROUTE_INITIALIZER;
+  s_sg_platf_route_cbarg_t ASroute;
   memset(&ASroute,0,sizeof(ASroute));
 
   ASroute.src         = A_surfxml_bypassASroute_src;
index 3e889ee..f805865 100644 (file)
@@ -12,6 +12,8 @@
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 
+#include <surf/surfxml_parse.h>
+
 #ifdef HAVE_LUA
 extern "C" {
 #include "src/bindings/lua/simgrid_lua.h"
@@ -131,7 +133,7 @@ void parse_platform_file(const char *file)
         && file[strlen(file)-1] == 'a');
 #endif
 
-  surf_parse_init_callbacks();
+  sg_platf_init();
 
 #ifdef HAVE_LUA
   /* Check if file extension is "lua". If so, we will use
index c46f743..ea44a75 100644 (file)
@@ -1,11 +1,11 @@
 ! expect signal SIGABRT
 $ ${bindir:=.}/flatifier bogus_missing_src_gateway.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n"
 > [  0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks.
-> [  0.000000] [0:maestro@] Parse error at bogus_missing_src_gateway.xml:19: gw_src="nod-cluster_router.cluster.us" not found for ASroute from "us" to "fr"
+> [  0.000000] [0:maestro@] Parse error at bogus_missing_src_gateway.xml:17: ASroute gw_src='nod-cluster_router.cluster.us' does name a node.
 > [  0.000000] [0:maestro@] Exiting now
 
 ! expect signal SIGABRT
 $ ${bindir:=.}/flatifier bogus_missing_dst_gateway.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n"
 > [  0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks.
-> [  0.000000] [0:maestro@] Parse error at bogus_missing_dst_gateway.xml:19: gw_dst="neud-grappe_router.grappe.fr" not found for ASroute from "us" to "fr"
+> [  0.000000] [0:maestro@] Parse error at bogus_missing_dst_gateway.xml:17: ASroute gw_dst='neud-grappe_router.grappe.fr' does name a node.
 > [  0.000000] [0:maestro@] Exiting now
index 92bb770..342c9cd 100644 (file)
@@ -8,7 +8,6 @@
 
 #include "simgrid/platf.h"
 #include "simgrid/simix.h"
-#include "surf/surfxml_parse.h"
 #include "xbt/log.h"
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "my log messages");