From f1cc430006034e95e75671c6d0f8339078ecd539 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 18 Nov 2019 06:25:09 +0100 Subject: [PATCH] parsing: less asserts, more exception raising --- src/surf/xml/surfxml_parseplatf.cpp | 47 +++++++++++++++-------------- src/surf/xml/surfxml_sax_cb.cpp | 18 +++++------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 88029c7226..8446b10643 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -32,9 +32,8 @@ XBT_PRIVATE std::unordered_map trace_connect_list_link void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect) { - xbt_assert(traces_set_list.find(trace_connect->trace) != traces_set_list.end(), - "Cannot connect trace %s to %s: trace unknown", trace_connect->trace.c_str(), - trace_connect->element.c_str()); + surf_parse_assert(traces_set_list.find(trace_connect->trace) != traces_set_list.end(), + std::string("Cannot connect trace ")+ trace_connect->trace+ " to "+trace_connect->element+": trace unknown"); switch (trace_connect->kind) { case simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL: @@ -100,45 +99,47 @@ void parse_platform_file(const std::string& file) /* connect all profiles relative to hosts */ for (auto const& elm : trace_connect_list_host_avail) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + auto profile = traces_set_list.at(elm.first); - simgrid::s4u::Host* host = simgrid::s4u::Host::by_name_or_null(elm.second); - xbt_assert(host, "Host %s undefined", elm.second.c_str()); + auto host = simgrid::s4u::Host::by_name_or_null(elm.second); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Host ")+elm.second+" undefined."); host->set_state_profile(profile); } for (auto const& elm : trace_connect_list_host_speed) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + auto profile = traces_set_list.at(elm.first); - simgrid::s4u::Host* host = simgrid::s4u::Host::by_name_or_null(elm.second); - xbt_assert(host, "Host %s undefined", elm.second.c_str()); + auto host = simgrid::s4u::Host::by_name_or_null(elm.second); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Host ")+elm.second+" undefined."); host->set_speed_profile(profile); } for (auto const& elm : trace_connect_list_link_avail) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + auto profile = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::by_name(elm.second); - xbt_assert(link, "Link %s undefined", elm.second.c_str()); + auto link = simgrid::s4u::Link::by_name(elm.second); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Link ")+elm.second+" undefined."); link->set_state_profile(profile); } for (auto const& elm : trace_connect_list_link_bw) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::by_name(elm.second); - xbt_assert(link, "Link %s undefined", elm.second.c_str()); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + auto profile = traces_set_list.at(elm.first); + + auto link = simgrid::s4u::Link::by_name(elm.second); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Link ")+elm.second+" undefined."); link->set_bandwidth_profile(profile); } for (auto const& elm : trace_connect_list_link_lat) { - xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); - simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::by_name(elm.second); - xbt_assert(link, "Link %s undefined", elm.second.c_str()); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + auto profile = traces_set_list.at(elm.first); + + auto link = simgrid::s4u::Link::by_name(elm.second); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Link ")+elm.second+" undefined."); link->set_latency_profile(profile); } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index d46e18a16b..ffec861c3a 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -353,7 +353,7 @@ void ETag_surfxml_include() void STag_surfxml_platform() { XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version); - xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n " + surf_parse_assert((version >= 1.0), "******* BIG FAT WARNING *********\n " "You're using an ancient XML file.\n" "Since SimGrid 3.1, units are Bytes, Flops, and seconds " "instead of MBytes, MFlops and seconds.\n" @@ -367,13 +367,13 @@ void STag_surfxml_platform() { "Last, do not forget to also update your values for " "the calls to MSG_task_create (if any)."); - xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n " + surf_parse_assert((version >= 3.0), "******* BIG FAT WARNING *********\n " "You're using an old XML file.\n" "Use simgrid_update_xml to update your file automatically. " "This program is installed automatically with SimGrid, or " "available in the tools/ directory of the source archive."); - xbt_assert((version >= 4.0), - "******* FILE %s IS TOO OLD (v:%.1f) *********\n " + surf_parse_assert((version >= 4.0), + std::string("******* THIS FILE IS TOO OLD (v:")+std::to_string(version)+") *********\n " "Changes introduced in SimGrid 3.13:\n" " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n" " - In , attribute kind=\"POWER\" is now kind=\"SPEED\".\n" @@ -382,8 +382,7 @@ void STag_surfxml_platform() { "\n\n" "Use simgrid_update_xml to update your file automatically. " "This program is installed automatically with SimGrid, or " - "available in the tools/ directory of the source archive.", - surf_parsed_filename.c_str(), version); + "available in the tools/ directory of the source archive."); if (version < 4.1) { XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 " "That's fine, the new version is backward compatible. \n\n" @@ -392,11 +391,10 @@ void STag_surfxml_platform() { "available in the tools/ directory of the source archive.", version, surf_parsed_filename.c_str()); } - xbt_assert(version <= 4.1, - "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n " + surf_parse_assert(version <= 4.1, + std::string("******* THIS FILE COMES FROM THE FUTURE (v:")+std::to_string(version)+") *********\n " "The most recent formalism that this version of SimGrid understands is v4.1.\n" - "Please update your code, or use another, more adapted, file.", - surf_parsed_filename.c_str(), version); + "Please update your code, or use another, more adapted, file."); } void ETag_surfxml_platform(){ simgrid::s4u::Engine::on_platform_created(); -- 2.20.1