From: Martin Quinson Date: Sat, 20 Feb 2016 22:54:35 +0000 (+0100) Subject: surfxml: better error checking, and less include of internal headers X-Git-Tag: v3_13~763 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4740be30808ce9367af87084c8bf989883b1f2a0 surfxml: better error checking, and less include of internal headers --- diff --git a/include/surf/surfxml_parse.h b/include/surf/surfxml_parse.h index 83957d15fa..df7bf03f67 100644 --- a/include/surf/surfxml_parse.h +++ b/include/surf/surfxml_parse.h @@ -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); diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index b8300a4d5e..868c517197 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 1b7be72fb5..cc101f7a56 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -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); } diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 8f1216134b..5f52e8c316 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -104,6 +104,8 @@ void surf_network_model_init_IB(void) } +#include // 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"); diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 9a9a5e4ebd..17115295e1 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -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 // FIXME: move that back to the parsing area static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) { const char *groups = NULL; diff --git a/src/surf/network_smpi.cpp b/src/surf/network_smpi.cpp index f8422b4310..004dec9b08 100644 --- a/src/surf/network_smpi.cpp +++ b/src/surf/network_smpi.cpp @@ -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 // 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); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 500f481aed..2c4dd116ae 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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 */ diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 6fc77aed93..208f5524f8 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -80,6 +80,7 @@ StorageN11Model::~StorageN11Model(){ storage_running_action_set_that_does_not_need_being_checked = NULL; } +#include // 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) diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index dccea91c25..a2624dd729 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -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 */ } diff --git a/src/surf/surf_private.h b/src/surf/surf_private.h index 9c6ed3c539..1370cb1f06 100644 --- a/src/surf/surf_private.h +++ b/src/surf/surf_private.h @@ -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" diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index d0e9f2e91f..44f21cf6a6 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -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 // FIXME: move that back to the parsing area #include diff --git a/src/surf/surf_routing_cluster_fat_tree.cpp b/src/surf/surf_routing_cluster_fat_tree.cpp index e68b89c0da..9580c264b6 100644 --- a/src/surf/surf_routing_cluster_fat_tree.cpp +++ b/src/surf/surf_routing_cluster_fat_tree.cpp @@ -16,6 +16,9 @@ #include #include +#include // FIXME: move that back to the parsing area + + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_fat_tree, surf, "Routing for fat trees"); namespace simgrid { diff --git a/src/surf/surf_routing_cluster_torus.cpp b/src/surf/surf_routing_cluster_torus.cpp index 83151df2b0..60ccb735f8 100644 --- a/src/surf/surf_routing_cluster_torus.cpp +++ b/src/surf/surf_routing_cluster_torus.cpp @@ -6,6 +6,7 @@ #include "src/surf/surf_routing_private.hpp" #include "src/surf/surf_routing_cluster_torus.hpp" +#include // 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"); diff --git a/src/surf/surf_routing_private.hpp b/src/surf/surf_routing_private.hpp index 5904dc9fc5..041dda823f 100644 --- a/src/surf/surf_routing_private.hpp +++ b/src/surf/surf_routing_private.hpp @@ -16,7 +16,6 @@ #include "xbt/str.h" #include "xbt/config.h" #include "xbt/graph.h" -#include "surf/surfxml_parse.h" /* ************************************************************************** */ /* ******************************* NO ROUTING ******************************* */ diff --git a/src/surf/surfxml_parse.cpp b/src/surf/surfxml_parse.cpp index 382d772e03..5e0aab1c03 100644 --- a/src/surf/surfxml_parse.cpp +++ b/src/surf/surfxml_parse.cpp @@ -16,6 +16,8 @@ #include "src/surf/surf_private.h" #include "simgrid/sg_config.h" +#include + 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; diff --git a/src/surf/surfxml_parseplatf.cpp b/src/surf/surfxml_parseplatf.cpp index 3e889ee5cb..f80586543c 100644 --- a/src/surf/surfxml_parseplatf.cpp +++ b/src/surf/surfxml_parseplatf.cpp @@ -12,6 +12,8 @@ #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" +#include + #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 diff --git a/teshsuite/simdag/platforms/bogus_missing_gateway.tesh b/teshsuite/simdag/platforms/bogus_missing_gateway.tesh index c46f743e2b..ea44a75962 100644 --- a/teshsuite/simdag/platforms/bogus_missing_gateway.tesh +++ b/teshsuite/simdag/platforms/bogus_missing_gateway.tesh @@ -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 diff --git a/teshsuite/simix/stack_overflow/stack_overflow.c b/teshsuite/simix/stack_overflow/stack_overflow.c index 92bb77079f..342c9cd70e 100644 --- a/teshsuite/simix/stack_overflow/stack_overflow.c +++ b/teshsuite/simix/stack_overflow/stack_overflow.c @@ -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");