From 49b53eb334bc6f19b530603201d00bcc312bfd29 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 31 Mar 2021 11:58:57 +0200 Subject: [PATCH] Change "if(...) xbt_die(...)" to "xbt_assert(...)". Some of them could certainly be improved to report the error to the user code, for example with a proper exception, but it's another work. --- doc/doxygen/uhood_switch.doc | 6 +-- examples/c/dht-pastry/dht-pastry.c | 10 ++-- examples/cpp/dht-chord/s4u-dht-chord.cpp | 10 ++-- examples/cpp/maestro-set/s4u-maestro-set.cpp | 7 ++- .../simdag/ptg-dotload/sd_ptg-dotload.c | 4 +- include/simgrid/kernel/future.hpp | 3 +- include/xbt/sysdep.h | 12 ++--- src/bindings/java/jmsg_task.cpp | 3 +- src/instr/instr_interface.cpp | 6 +-- src/instr/instr_platform.cpp | 4 +- src/kernel/activity/CommImpl.cpp | 3 +- src/kernel/activity/SynchroRaw.cpp | 5 +- src/kernel/context/ContextSwapped.cpp | 23 ++++----- src/mc/ModelChecker.cpp | 5 +- .../CommunicationDeterminismChecker.cpp | 3 +- src/mc/checker/simgrid_mc.cpp | 3 +- src/mc/inspect/LocationList.cpp | 10 ++-- src/mc/inspect/mc_dwarf.cpp | 8 ++-- src/mc/mc_config.cpp | 8 ++-- src/mc/mc_record.cpp | 9 ++-- src/mc/remote/AppSide.cpp | 31 +++++------- src/mc/remote/RemoteProcess.cpp | 8 ++-- src/mc/sosp/PageStore.cpp | 12 ++--- src/mc/sosp/Snapshot.cpp | 9 ++-- src/plugins/file_system/s4u_FileSystem.cpp | 18 +++---- src/s4u/s4u_Host.cpp | 3 +- src/simdag/sd_daxloader.cpp | 4 +- src/smpi/bindings/smpi_pmpi.cpp | 6 +-- .../bcast/bcast-scatter-rdb-allgather.cpp | 14 ++---- src/smpi/colls/smpi_coll.cpp | 9 ++-- src/smpi/internals/smpi_bench.cpp | 24 +++++----- src/smpi/internals/smpi_global.cpp | 6 +-- src/smpi/internals/smpi_memory.cpp | 30 ++++++------ src/smpi/internals/smpi_shared.cpp | 5 +- src/smpi/internals/smpi_utils.cpp | 5 +- src/smpi/mpi/smpi_file.cpp | 4 +- src/smpi/mpi/smpi_request.cpp | 44 +++++++++-------- src/smpi/mpi/smpi_win.cpp | 3 +- src/surf/cpu_ti.cpp | 9 ++-- src/surf/network_ns3.cpp | 47 +++++++++---------- src/surf/surf_interface.cpp | 3 +- src/surf/xml/surfxml_parseplatf.cpp | 6 +-- src/xbt/automaton/automatonparse_promela.c | 3 +- src/xbt/config.cpp | 19 +++----- src/xbt/string.cpp | 7 ++- src/xbt/xbt_log_appender_file.cpp | 9 ++-- teshsuite/simdag/flatifier/flatifier.cpp | 4 +- .../coll-allreduce-with-leaks.tesh | 2 +- teshsuite/xbt/mmalloc/mmalloc_test.cpp | 9 ++-- 49 files changed, 204 insertions(+), 291 deletions(-) diff --git a/doc/doxygen/uhood_switch.doc b/doc/doxygen/uhood_switch.doc index ae652130c5..45217229a0 100644 --- a/doc/doxygen/uhood_switch.doc +++ b/doc/doxygen/uhood_switch.doc @@ -260,8 +260,7 @@ T simgrid::kernel::Future::get() template T simgrid::kernel::FutureState::get() { - if (status_ != FutureStatus::ready) - xbt_die("Deadlock: this future is not ready"); + xbt_assert(status_ == FutureStatus::ready, "Deadlock: this future is not ready"); status_ = FutureStatus::done; if (exception_) { std::exception_ptr exception = std::move(exception_); @@ -478,8 +477,7 @@ template auto kernel_sync(F code) -> decltype(code().get()) { typedef decltype(code().get()) T; - if (SIMIX_is_maestro()) - xbt_die("Can't execute blocking call in kernel mode"); + xbt_assert(not SIMIX_is_maestro(), "Can't execute blocking call in kernel mode"); smx_actor_t self = SIMIX_process_self(); simgrid::xbt::Result result; diff --git a/examples/c/dht-pastry/dht-pastry.c b/examples/c/dht-pastry/dht-pastry.c index 10f21acaa6..0c1f9811cb 100644 --- a/examples/c/dht-pastry/dht-pastry.c +++ b/examples/c/dht-pastry/dht-pastry.c @@ -526,12 +526,10 @@ int main(int argc, char* argv[]) XBT_DEBUG("Set nb_bits to %d", nb_bits); } else { length = strlen("-timeout="); - if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) { - timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"); - XBT_DEBUG("Set timeout to %d", timeout); - } else { - xbt_die("Invalid pastry option '%s'", options[0]); - } + xbt_assert(strncmp(options[0], "-timeout=", length) == 0 && strlen(options[0]) > length, + "Invalid pastry option '%s'", options[0]); + timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"); + XBT_DEBUG("Set timeout to %d", timeout); } options++; } diff --git a/examples/cpp/dht-chord/s4u-dht-chord.cpp b/examples/cpp/dht-chord/s4u-dht-chord.cpp index 6651af6298..bc2fb64e30 100644 --- a/examples/cpp/dht-chord/s4u-dht-chord.cpp +++ b/examples/cpp/dht-chord/s4u-dht-chord.cpp @@ -26,12 +26,10 @@ int main(int argc, char* argv[]) XBT_DEBUG("Set nb_bits to %d", nb_bits); } else { length = strlen("-timeout="); - if (not strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) { - timeout = static_cast(xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s")); - XBT_DEBUG("Set timeout to %d", timeout); - } else { - xbt_die("Invalid chord option '%s'", options[0]); - } + xbt_assert(strncmp(options[0], "-timeout=", length) == 0 && strlen(options[0]) > length, + "Invalid chord option '%s'", options[0]); + timeout = static_cast(xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s")); + XBT_DEBUG("Set timeout to %d", timeout); } options++; } diff --git a/examples/cpp/maestro-set/s4u-maestro-set.cpp b/examples/cpp/maestro-set/s4u-maestro-set.cpp index 3f5e8d822e..5ffa6e62c5 100644 --- a/examples/cpp/maestro-set/s4u-maestro-set.cpp +++ b/examples/cpp/maestro-set/s4u-maestro-set.cpp @@ -68,10 +68,9 @@ int main(int argc, char* argv[]) simgrid::s4u::Engine e(&argc, argv); - if (argc != 2) { - XBT_CRITICAL("Usage: %s platform_file\n", argv[0]); - xbt_die("example: %s ../platforms/small_platform.xml\n", argv[0]); - } + xbt_assert(argc == 2, "Usage: %s platform_file\n" + "example: %s ../platforms/small_platform.xml\n", + argv[0], argv[0]); e.load_platform(argv[1]); diff --git a/examples/deprecated/simdag/ptg-dotload/sd_ptg-dotload.c b/examples/deprecated/simdag/ptg-dotload/sd_ptg-dotload.c index de67161f22..4f3bf64fa5 100644 --- a/examples/deprecated/simdag/ptg-dotload/sd_ptg-dotload.c +++ b/examples/deprecated/simdag/ptg-dotload/sd_ptg-dotload.c @@ -26,9 +26,7 @@ int main(int argc, char **argv){ /* load the DOT file */ dot = SD_PTG_dotload(argv[2]); - if(dot == NULL){ - xbt_die("No dot load may be you have a cycle in your graph"); - } + xbt_assert(dot != NULL, "No dot load may be you have a cycle in your graph"); /* Display all the tasks */ XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------"); diff --git a/include/simgrid/kernel/future.hpp b/include/simgrid/kernel/future.hpp index 897e4c231a..e3a24687ac 100644 --- a/include/simgrid/kernel/future.hpp +++ b/include/simgrid/kernel/future.hpp @@ -116,8 +116,7 @@ protected: **/ void resolve() { - if (status_ != FutureStatus::ready) - xbt_die("Deadlock: this future is not ready"); + xbt_assert(status_ == FutureStatus::ready, "Deadlock: this future is not ready"); status_ = FutureStatus::done; if (exception_) { std::exception_ptr exception = std::move(exception_); diff --git a/include/xbt/sysdep.h b/include/xbt/sysdep.h index 96407350d8..6a132f7dea 100644 --- a/include/xbt/sysdep.h +++ b/include/xbt/sysdep.h @@ -40,8 +40,7 @@ static XBT_ALWAYS_INLINE char *xbt_strdup(const char *s) { char *res = NULL; if (s) { res = strdup(s); - if (!res) - xbt_die("memory allocation error (strdup returned NULL)"); + xbt_assert(res, "memory allocation error (strdup returned NULL)"); } return res; } @@ -50,8 +49,7 @@ static XBT_ALWAYS_INLINE char *xbt_strdup(const char *s) { @hideinitializer */ static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) { void* res = malloc(n); - if (!res) - xbt_die("Memory allocation of %lu bytes failed", (unsigned long)n); + xbt_assert(res, "Memory allocation of %lu bytes failed", (unsigned long)n); return res; } @@ -59,8 +57,7 @@ static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) { @hideinitializer */ static XBT_ALWAYS_INLINE void *xbt_malloc0(size_t n) { void* res = calloc(n, 1); - if (!res) - xbt_die("Memory callocation of %lu bytes failed", (unsigned long)n); + xbt_assert(res, "Memory callocation of %lu bytes failed", (unsigned long)n); return res; } @@ -71,8 +68,7 @@ static XBT_ALWAYS_INLINE void *xbt_realloc(void *p, size_t s) { if (s) { if (p) { res = realloc(p, s); - if (!res) - xbt_die("memory (re)allocation of %lu bytes failed", (unsigned long)s); + xbt_assert(res, "memory (re)allocation of %lu bytes failed", (unsigned long)s); } else { res = xbt_malloc(s); } diff --git a/src/bindings/java/jmsg_task.cpp b/src/bindings/java/jmsg_task.cpp index 798d8f2ec5..fc8c867165 100644 --- a/src/bindings/java/jmsg_task.cpp +++ b/src/bindings/java/jmsg_task.cpp @@ -115,8 +115,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel(JNIEnv * env, jobject jt } msg_error_t rv = MSG_task_cancel(ptask); - if (rv != MSG_OK) - xbt_die("MSG_task_cancel() unexpectedly failed with error code %d. Please report this bug", rv); + xbt_assert(rv == MSG_OK, "MSG_task_cancel() unexpectedly failed with error code %d. Please report this bug", rv); } JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute(JNIEnv * env, jobject jtask) diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index d6c2d30f28..245e6092a7 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -297,12 +297,10 @@ static void instr_user_srcdst_variable(double time, const char *src, const char const char *father_type, double value, InstrUserVariable what) { simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src); - if (not src_elm) - xbt_die("Element '%s' not found!",src); + xbt_assert(src_elm, "Element '%s' not found!", src); simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst); - if (not dst_elm) - xbt_die("Element '%s' not found!",dst); + xbt_assert(dst_elm, "Element '%s' not found!", dst); std::vector route; simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr); diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 9e4594c841..0ae22190a4 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -75,9 +75,7 @@ static void linkContainers(simgrid::instr::Container* src, simgrid::instr::Conta // find common father simgrid::instr::Container* father = lowestCommonAncestor(src, dst); - if (not father) { - xbt_die("common father unknown, this is a tracing problem"); - } + xbt_assert(father, "common father unknown, this is a tracing problem"); // check if we already register this pair (we only need one direction) std::string aux1 = src->get_name() + dst->get_name(); diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index f51af06d4d..44dcf48599 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -290,8 +290,7 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activi double timeout) { if (MC_is_active() || MC_record_replay_is_active()) { - if (timeout > 0.0) - xbt_die("Timeout not implemented for waitany in the model-checker"); + xbt_assert(timeout <= 0.0, "Timeout not implemented for waitany in the model-checker"); int idx = simcall->mc_value_; auto* comm = comms[idx]; comm->simcalls_.push_back(simcall); diff --git a/src/kernel/activity/SynchroRaw.cpp b/src/kernel/activity/SynchroRaw.cpp index a54933725e..5b8950c250 100644 --- a/src/kernel/activity/SynchroRaw.cpp +++ b/src/kernel/activity/SynchroRaw.cpp @@ -76,8 +76,9 @@ void RawImpl::finish() XBT_DEBUG("RawImpl::finish(): host '%s' failed", simcall->issuer_->get_host()->get_cname()); simcall->issuer_->context_->set_wannadie(); simcall->issuer_->exception_ = std::make_exception_ptr(HostFailureException(XBT_THROW_POINT, "Host failed")); - } else if (state_ != State::SRC_TIMEOUT) { - xbt_die("Internal error in RawImpl::finish() unexpected synchro state %d", static_cast(state_)); + } else { + xbt_assert(state_ == State::SRC_TIMEOUT, "Internal error in RawImpl::finish() unexpected synchro state %d", + static_cast(state_)); } finish_callback_(); diff --git a/src/kernel/context/ContextSwapped.cpp b/src/kernel/context/ContextSwapped.cpp index bd913fb87c..d93d602159 100644 --- a/src/kernel/context/ContextSwapped.cpp +++ b/src/kernel/context/ContextSwapped.cpp @@ -97,25 +97,22 @@ SwappedContext::SwappedContext(std::function&& code, smx_actor_t actor, reinterpret_cast(stack_)[-1] = alloc; #elif !defined(_WIN32) void* alloc; - if (posix_memalign(&alloc, xbt_pagesize, size) != 0) - xbt_die("Failed to allocate stack."); + xbt_assert(posix_memalign(&alloc, xbt_pagesize, size) == 0, "Failed to allocate stack."); this->stack_ = static_cast(alloc); #else this->stack_ = static_cast(_aligned_malloc(size, xbt_pagesize)); #endif #ifndef _WIN32 - if (mprotect(this->stack_, smx_context_guard_size, PROT_NONE) == -1) { - xbt_die( - "Failed to protect stack: %s.\n" - "If you are running a lot of actors, you may be exceeding the amount of mappings allowed per process.\n" - "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n" - "Please see " - "https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization for more " - "information.", - strerror(errno)); - /* This is fatal. We are going to fail at some point when we try reusing this. */ - } + /* This is fatal. We are going to fail at some point when we try reusing this. */ + xbt_assert( + mprotect(this->stack_, smx_context_guard_size, PROT_NONE) != -1, + "Failed to protect stack: %s.\n" + "If you are running a lot of actors, you may be exceeding the amount of mappings allowed per process.\n" + "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n" + "Please see https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization " + "for more information.", + strerror(errno)); #endif this->stack_ = this->stack_ + smx_context_guard_size; } else { diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index 3a9fb8513f..88a52a419a 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -64,9 +64,8 @@ void ModelChecker::start() // The model-checked process SIGSTOP itself to signal it's ready: const pid_t pid = remote_process_->pid(); - pid_t res = waitpid(pid, &status, WAITPID_CHECKED_FLAGS); - if (res < 0 || not WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP) - xbt_die("Could not wait model-checked process"); + xbt_assert(waitpid(pid, &status, WAITPID_CHECKED_FLAGS) == pid && WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP, + "Could not wait model-checked process"); if (not _sg_mc_dot_output_file.get().empty()) MC_init_dot_output(); diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index 276fd779f0..ed9f98316d 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -236,8 +236,7 @@ void CommunicationDeterminismChecker::complete_comm_pattern(RemotePtrcomm_addr == comm_addr); }); - if (current_comm_pattern == std::end(incomplete_pattern)) - xbt_die("Corresponding communication not found!"); + xbt_assert(current_comm_pattern != std::end(incomplete_pattern), "Corresponding communication not found!"); update_comm_pattern(*current_comm_pattern, comm_addr); std::unique_ptr comm_pattern(*current_comm_pattern); diff --git a/src/mc/checker/simgrid_mc.cpp b/src/mc/checker/simgrid_mc.cpp index 767c0bf4d0..649562e6d6 100644 --- a/src/mc/checker/simgrid_mc.cpp +++ b/src/mc/checker/simgrid_mc.cpp @@ -31,8 +31,7 @@ char** argvdup(int argc, char** argv) int main(int argc, char** argv) { - if (argc < 2) - xbt_die("Missing arguments.\n"); + xbt_assert(argc >= 2, "Missing arguments"); // Currently, we need this before sg_config_init: _sg_do_model_check = 1; diff --git a/src/mc/inspect/LocationList.cpp b/src/mc/inspect/LocationList.cpp index 426b97b99a..7bfb61fed7 100644 --- a/src/mc/inspect/LocationList.cpp +++ b/src/mc/inspect/LocationList.cpp @@ -53,11 +53,10 @@ Location resolve(simgrid::dwarf::LocationList const& locations, simgrid::mc::Obj unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space) { unw_word_t ip = 0; - if (c && unw_get_reg(c, UNW_REG_IP, &ip)) - xbt_die("Could not resolve IP"); + if (c) + xbt_assert(unw_get_reg(c, UNW_REG_IP, &ip) == 0, "Could not resolve IP"); simgrid::dwarf::DwarfExpression const* expression = find_expression(locations, ip); - if (not expression) - xbt_die("Could not resolve location"); + xbt_assert(expression != nullptr, "Could not resolve location"); return simgrid::dwarf::resolve(*expression, object_info, c, frame_pointer_address, address_space); } @@ -76,8 +75,7 @@ LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Att if (offset == 0) break; - else if (offset == -1) - xbt_die("Error while loading location list"); + xbt_assert(offset != -1, "Error while loading location list"); auto base_address = reinterpret_cast(info.base_address()); diff --git a/src/mc/inspect/mc_dwarf.cpp b/src/mc/inspect/mc_dwarf.cpp index d7b1868895..90277e10f2 100644 --- a/src/mc/inspect/mc_dwarf.cpp +++ b/src/mc/inspect/mc_dwarf.cpp @@ -399,10 +399,10 @@ static void MC_dwarf_fill_member_location(const simgrid::mc::Type* type, simgrid xbt_assert(not dwarf_hasattr(child, DW_AT_data_bit_offset), "Can't groke DW_AT_data_bit_offset."); if (not dwarf_hasattr_integrate(child, DW_AT_data_member_location)) { - if (type->type == DW_TAG_union_type) - return; - xbt_die("Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%" PRIx64 ">%s", - member->name.c_str(), (uint64_t)type->id, type->name.c_str()); + xbt_assert(type->type == DW_TAG_union_type, + "Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%" PRIx64 ">%s", + member->name.c_str(), (uint64_t)type->id, type->name.c_str()); + return; } Dwarf_Attribute attr; diff --git a/src/mc/mc_config.cpp b/src/mc/mc_config.cpp index 39c3491dee..78c86b6153 100644 --- a/src/mc/mc_config.cpp +++ b/src/mc/mc_config.cpp @@ -25,10 +25,10 @@ simgrid::mc::ReductionMode reduction_mode = simgrid::mc::ReductionMode::unset; static void _mc_cfg_cb_check(const char* spec, bool more_check = true) { - if (_sg_cfg_init_status && not _sg_do_model_check && more_check) - xbt_die("You are specifying a %s after the initialization (through MSG_config?), but the program was not run under " - "the model-checker (with simgrid-mc)). This won't work, sorry.", - spec); + xbt_assert(_sg_cfg_init_status == 0 || _sg_do_model_check || not more_check, + "You are specifying a %s after the initialization (through MSG_config?), but the program was not run " + "under the model-checker (with simgrid-mc)). This won't work, sorry.", + spec); } /* Replay (this part is enabled even if MC it disabled) */ diff --git a/src/mc/mc_record.cpp b/src/mc/mc_record.cpp index d8be67491a..bc2b30c4a8 100644 --- a/src/mc/mc_record.cpp +++ b/src/mc/mc_record.cpp @@ -30,13 +30,10 @@ void replay(RecordTrace const& trace) // Choose a request: kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(transition.aid_); - if (actor == nullptr) - xbt_die("Unexpected actor (id:%ld).", transition.aid_); + xbt_assert(actor != nullptr, "Unexpected actor (id:%ld).", transition.aid_); const s_smx_simcall* simcall = &(actor->simcall_); - if (simcall->call_ == simix::Simcall::NONE) - xbt_die("No simcall for process %ld.", transition.aid_); - if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(actor)) - xbt_die("Unexpected simcall."); + xbt_assert(simcall->call_ != simix::Simcall::NONE, "No simcall for process %ld.", transition.aid_); + xbt_assert(simgrid::mc::request_is_visible(simcall) && simgrid::mc::actor_is_enabled(actor), "Unexpected simcall."); // Execute the request: simcall->issuer_->simcall_handle(transition.times_considered_); diff --git a/src/mc/remote/AppSide.cpp b/src/mc/remote/AppSide.cpp index b19fd09ffc..27c7277e8c 100644 --- a/src/mc/remote/AppSide.cpp +++ b/src/mc/remote/AppSide.cpp @@ -46,8 +46,7 @@ AppSide* AppSide::initialize() // Check the socket type/validity: int type; socklen_t socklen = sizeof(type); - if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &socklen) != 0) - xbt_die("Could not check socket type"); + xbt_assert(getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &socklen) == 0, "Could not check socket type"); xbt_assert(type == SOCK_SEQPACKET, "Unexpected socket type %i", type); XBT_DEBUG("Model-checked application found expected socket type"); @@ -62,8 +61,8 @@ AppSide* AppSide::initialize() #else #error "no ptrace equivalent coded for this platform" #endif - if (errno != 0 || raise(SIGSTOP) != 0) - xbt_die("Could not wait for the model-checker (errno = %d: %s)", errno, strerror(errno)); + xbt_assert(errno == 0 && raise(SIGSTOP) == 0, "Could not wait for the model-checker (errno = %d: %s)", errno, + strerror(errno)); s_mc_message_initial_addresses_t message{ MessageType::INITIAL_ADDRESSES, mmalloc_preinit(), simgrid::kernel::actor::get_maxpid_addr(), @@ -97,8 +96,7 @@ void AppSide::handle_simcall_execute(const s_mc_message_simcall_handle_t* messag kernel::actor::ActorImpl* process = kernel::actor::ActorImpl::by_pid(message->aid_); xbt_assert(process != nullptr, "Invalid pid %lu", message->aid_); process->simcall_handle(message->times_considered_); - if (channel_.send(MessageType::WAITING)) - xbt_die("Could not send MESSAGE_WAITING to model-checker"); + xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send MESSAGE_WAITING to model-checker"); } void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const @@ -231,8 +229,7 @@ void AppSide::main_loop() const void AppSide::report_assertion_failure() const { - if (channel_.send(MessageType::ASSERTION_FAILED)) - xbt_die("Could not send assertion to model-checker"); + xbt_assert(channel_.send(MessageType::ASSERTION_FAILED) == 0, "Could not send assertion to model-checker"); this->handle_messages(); } @@ -242,8 +239,7 @@ void AppSide::ignore_memory(void* addr, std::size_t size) const message.type = MessageType::IGNORE_MEMORY; message.addr = (std::uintptr_t)addr; message.size = size; - if (channel_.send(message)) - xbt_die("Could not send IGNORE_MEMORY message to model-checker"); + xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_MEMORY message to model-checker"); } void AppSide::ignore_heap(void* address, std::size_t size) const @@ -263,8 +259,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) const heap->heapinfo[message.block].busy_frag.ignore[message.fragment]++; } - if (channel_.send(message)) - xbt_die("Could not send ignored region to MCer"); + xbt_assert(channel_.send(message) == 0, "Could not send ignored region to MCer"); } void AppSide::unignore_heap(void* address, std::size_t size) const @@ -273,21 +268,18 @@ void AppSide::unignore_heap(void* address, std::size_t size) const message.type = MessageType::UNIGNORE_HEAP; message.addr = (std::uintptr_t)address; message.size = size; - if (channel_.send(message)) - xbt_die("Could not send IGNORE_HEAP message to model-checker"); + xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_HEAP message to model-checker"); } void AppSide::declare_symbol(const char* name, int* value) const { s_mc_message_register_symbol_t message; message.type = MessageType::REGISTER_SYMBOL; - if (strlen(name) + 1 > message.name.size()) - xbt_die("Symbol is too long"); + xbt_assert(strlen(name) + 1 <= message.name.size(), "Symbol is too long"); strncpy(message.name.data(), name, message.name.size()); message.callback = nullptr; message.data = value; - if (channel_.send(message)) - xbt_die("Could send REGISTER_SYMBOL message to model-checker"); + xbt_assert(channel_.send(message) == 0, "Could send REGISTER_SYMBOL message to model-checker"); } void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const @@ -304,8 +296,7 @@ void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const s_mc_message_stack_region_t message; message.type = MessageType::STACK_REGION; message.stack_region = region; - if (channel_.send(message)) - xbt_die("Could not send STACK_REGION to model-checker"); + xbt_assert(channel_.send(message) == 0, "Could not send STACK_REGION to model-checker"); } } // namespace mc } // namespace simgrid diff --git a/src/mc/remote/RemoteProcess.cpp b/src/mc/remote/RemoteProcess.cpp index 64b83b5a92..eef3b180f5 100644 --- a/src/mc/remote/RemoteProcess.cpp +++ b/src/mc/remote/RemoteProcess.cpp @@ -444,8 +444,8 @@ std::string RemoteProcess::read_string(RemotePtr address) const void* RemoteProcess::read_bytes(void* buffer, std::size_t size, RemotePtr address, ReadOptions /*options*/) const { - if (pread_whole(this->memory_file, buffer, size, (size_t)address.address()) < 0) - xbt_die("Read at %p from process %lli failed", (void*)address.address(), (long long)this->pid_); + xbt_assert(pread_whole(this->memory_file, buffer, size, (size_t)address.address()) != -1, + "Read at %p from process %lli failed", (void*)address.address(), (long long)this->pid_); return buffer; } @@ -457,8 +457,8 @@ void* RemoteProcess::read_bytes(void* buffer, std::size_t size, RemotePtr */ void RemoteProcess::write_bytes(const void* buffer, size_t len, RemotePtr address) const { - if (pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) < 0) - xbt_die("Write to process %lli failed", (long long)this->pid_); + xbt_assert(pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) != -1, + "Write to process %lli failed", (long long)this->pid_); } static void zero_buffer_init(const void** zero_buffer, size_t zero_buffer_size) diff --git a/src/mc/sosp/PageStore.cpp b/src/mc/sosp/PageStore.cpp index 58fe2436c8..07ff2872e1 100644 --- a/src/mc/sosp/PageStore.cpp +++ b/src/mc/sosp/PageStore.cpp @@ -42,8 +42,7 @@ PageStore::PageStore(std::size_t size) : capacity_(size) // Using mmap in order to be able to expand the region by relocating it somewhere else in the virtual memory space: void* memory = ::mmap(nullptr, size << xbt_pagebits, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); - if (memory == MAP_FAILED) - xbt_die("Could not mmap initial snapshot pages."); + xbt_assert(memory != MAP_FAILED, "Could not mmap initial snapshot pages."); this->top_index_ = 0; this->memory_ = memory; @@ -65,15 +64,13 @@ void PageStore::resize(std::size_t size) // virtual memory address if necessary: #if HAVE_MREMAP new_memory = mremap(this->memory_, old_bytesize, new_bytesize, MREMAP_MAYMOVE); - if (new_memory == MAP_FAILED) - xbt_die("Could not mremap snapshot pages."); + xbt_assert(new_memory != MAP_FAILED, "Could not mremap snapshot pages."); #else if (new_bytesize > old_bytesize) { // Grow: first try to add new space after current map new_memory = mmap((char*)this->memory_ + old_bytesize, new_bytesize - old_bytesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); - if (new_memory == MAP_FAILED) - xbt_die("Could not mremap snapshot pages."); + xbt_assert(new_memory != MAP_FAILED, "Could not mremap snapshot pages."); // Check if expanding worked if (new_memory != (char*)this->memory_ + old_bytesize) { // New memory segment could not be put at the end of this->memory_, @@ -81,8 +78,7 @@ void PageStore::resize(std::size_t size) munmap(new_memory, new_bytesize - old_bytesize); new_memory = mmap(nullptr, new_bytesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); - if (new_memory == MAP_FAILED) - xbt_die("Could not mremap snapshot pages."); + xbt_assert(new_memory != MAP_FAILED, "Could not mremap snapshot pages."); memcpy(new_memory, this->memory_, old_bytesize); munmap(this->memory_, old_bytesize); } diff --git a/src/mc/sosp/Snapshot.cpp b/src/mc/sosp/Snapshot.cpp index 82702f907b..b195356949 100644 --- a/src/mc/sosp/Snapshot.cpp +++ b/src/mc/sosp/Snapshot.cpp @@ -72,8 +72,7 @@ static void fill_local_variables_values(mc_stack_frame_t stack_frame, Frame* sco &(stack_frame->unw_cursor), (void*)stack_frame->frame_base, &mc_model_checker->get_remote_process()); - if (not location.in_memory()) - xbt_die("Cannot handle non-address variable"); + xbt_assert(location.in_memory(), "Cannot handle non-address variable"); new_var.address = location.address(); } else xbt_die("No address"); @@ -137,10 +136,8 @@ static std::vector unwind_stack_frames(UnwindContext* stack_ break; int ret = unw_step(&c); - if (ret == 0) - xbt_die("Unexpected end of stack."); - else if (ret < 0) - xbt_die("Error while unwinding stack"); + xbt_assert(ret >= 0, "Error while unwinding stack"); + xbt_assert(ret != 0, "Unexpected end of stack."); } xbt_assert(not result.empty(), "unw_init_local failed"); diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 46dcac8c7f..1807a0d392 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -53,15 +53,15 @@ Disk* File::find_local_disk_on(const Host* host) longest_prefix_length = current_mount.length(); d = disk; } - if (longest_prefix_length > 0) { /* Mount point found, split fullpath_ into mount_name and path+filename*/ - mount_point_ = fullpath_.substr(0, longest_prefix_length); - if (mount_point_ == std::string("/")) - path_ = fullpath_; - else - path_ = fullpath_.substr(longest_prefix_length, fullpath_.length()); - XBT_DEBUG("%s + %s", mount_point_.c_str(), path_.c_str()); - } else - xbt_die("Can't find mount point for '%s' on '%s'", fullpath_.c_str(), host->get_cname()); + xbt_assert(longest_prefix_length > 0, "Can't find mount point for '%s' on '%s'", fullpath_.c_str(), + host->get_cname()); + /* Mount point found, split fullpath_ into mount_name and path+filename*/ + mount_point_ = fullpath_.substr(0, longest_prefix_length); + if (mount_point_ == std::string("/")) + path_ = fullpath_; + else + path_ = fullpath_.substr(longest_prefix_length, fullpath_.length()); + XBT_DEBUG("%s + %s", mount_point_.c_str(), path_.c_str()); } return d; } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 81aa55530b..fdaf2cad78 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -69,8 +69,7 @@ Host* Host::by_name_or_null(const std::string& name) Host* Host::current() { kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self(); - if (self == nullptr) - xbt_die("Cannot call Host::current() from the maestro context"); + xbt_assert(self != nullptr, "Cannot call Host::current() from the maestro context"); return self->get_host(); } diff --git a/src/simdag/sd_daxloader.cpp b/src/simdag/sd_daxloader.cpp index 61383ba88a..af8a699b66 100644 --- a/src/simdag/sd_daxloader.cpp +++ b/src/simdag/sd_daxloader.cpp @@ -154,9 +154,7 @@ xbt_dynar_t SD_daxload(const char *filename) xbt_dynar_push(result, &root_task); SD_task_t end_task = SD_task_create_comp_seq("end", nullptr, 0); - int res = dax_lex(); - if (res != 0) - xbt_die("Parse error in %s: %s", filename, dax__parse_err_msg()); + xbt_assert(dax_lex() == 0, "Parse error in %s: %s", filename, dax__parse_err_msg()); dax__delete_buffer(input_buffer); fclose(in_file); dax_lex_destroy(); diff --git a/src/smpi/bindings/smpi_pmpi.cpp b/src/smpi/bindings/smpi_pmpi.cpp index 39846efc5a..73a9d6b1ee 100644 --- a/src/smpi/bindings/smpi_pmpi.cpp +++ b/src/smpi/bindings/smpi_pmpi.cpp @@ -152,15 +152,13 @@ int PMPI_Get_address(const void *location, MPI_Aint * address) MPI_Aint PMPI_Aint_add(MPI_Aint address, MPI_Aint disp) { - if(address > PTRDIFF_MAX - disp) - xbt_die("overflow in MPI_Aint_add"); + xbt_assert(address <= PTRDIFF_MAX - disp, "overflow in MPI_Aint_add"); return address + disp; } MPI_Aint PMPI_Aint_diff(MPI_Aint address, MPI_Aint disp) { - if(address < PTRDIFF_MIN + disp) - xbt_die("underflow in MPI_Aint_diff"); + xbt_assert(address >= PTRDIFF_MIN + disp, "underflow in MPI_Aint_diff"); return address - disp; } diff --git a/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp b/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp index 8f2d24d9f5..70c043a52a 100644 --- a/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp +++ b/src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp @@ -164,8 +164,7 @@ int bcast__scatter_rdb_allgather( position = 0; if (rank == root) { mpi_errno = datatype->pack(buffer, count, tmp_buf, nbytes, &position, comm); - if (mpi_errno) - xbt_die("crash while packing %d", mpi_errno); + xbt_assert(mpi_errno == 0, "crash while packing %d", mpi_errno); } } @@ -174,9 +173,7 @@ int bcast__scatter_rdb_allgather( mpi_errno = scatter_for_bcast(root, comm, nbytes, tmp_buf); - if (mpi_errno) { - xbt_die("crash while scattering %d", mpi_errno); - } + xbt_assert(mpi_errno == 0, "crash while scattering %d", mpi_errno); /* curr_size is the amount of data that this process now has stored in * buffer at byte offset (relative_rank*scatter_size) */ @@ -316,16 +313,13 @@ int bcast__scatter_rdb_allgather( /* check that we received as much as we expected */ /* recvd_size may not be accurate for packed heterogeneous data */ - if (is_homogeneous && curr_size != nbytes) { - xbt_die("we didn't receive enough !"); - } + xbt_assert(not is_homogeneous || curr_size == nbytes, "we didn't receive enough !"); if (not is_contig || not is_homogeneous) { if (rank != root) { position = 0; mpi_errno = MPI_Unpack(tmp_buf, nbytes, &position, buffer, count, datatype, comm); - if (mpi_errno) - xbt_die("error when unpacking %d", mpi_errno); + xbt_assert(mpi_errno == 0, "error when unpacking %d", mpi_errno); } } diff --git a/src/smpi/colls/smpi_coll.cpp b/src/smpi/colls/smpi_coll.cpp index 5d75930996..6e78241e77 100644 --- a/src/smpi/colls/smpi_coll.cpp +++ b/src/smpi/colls/smpi_coll.cpp @@ -237,16 +237,14 @@ std::map, std::less<>> smpi_c std::vector* colls::get_smpi_coll_descriptions(const std::string& name) { auto iter = smpi_coll_descriptions.find(name); - if (iter == smpi_coll_descriptions.end()) - xbt_die("No collective named %s. This is a bug.", name.c_str()); + xbt_assert(iter != smpi_coll_descriptions.end(), "No collective named %s. This is a bug.", name.c_str()); return &iter->second; } static s_mpi_coll_description_t* find_coll_description(const std::string& collective, const std::string& algo) { std::vector* table = colls::get_smpi_coll_descriptions(collective); - if (table->empty()) - xbt_die("No registered algorithm for collective '%s'! This is a bug.", collective.c_str()); + xbt_assert(not table->empty(), "No registered algorithm for collective '%s'! This is a bug.", collective.c_str()); for (auto& desc : *table) { if (algo == desc.name) { @@ -289,8 +287,7 @@ void (*colls::smpi_coll_cleanup_callback)(); { \ auto desc = find_coll_description(_XBT_STRINGIFY(cat), name); \ cat = reinterpret_cast(desc->coll); \ - if (cat == nullptr) \ - xbt_die("Collective " _XBT_STRINGIFY(cat) " set to nullptr!"); \ + xbt_assert(cat != nullptr, "Collective " _XBT_STRINGIFY(cat) " set to nullptr!"); \ } COLL_APPLY(COLL_SETTER, COLL_GATHER_SIG, "") COLL_APPLY(COLL_SETTER,COLL_ALLGATHER_SIG,"") diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 0e4e8524e5..b3cf6c813d 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -90,9 +90,9 @@ void smpi_bench_begin() if (not smpi_cfg_papi_events_file().empty()) { int event_set = smpi_process()->papi_event_set(); // PAPI_start sets everything to 0! See man(3) PAPI_start - if (PAPI_LOW_LEVEL_INITED == PAPI_is_initialized() && event_set && PAPI_start(event_set) != PAPI_OK) { - xbt_die("Could not start PAPI counters (TODO: this needs some proper handling)."); - } + if (PAPI_LOW_LEVEL_INITED == PAPI_is_initialized() && event_set) + xbt_assert(PAPI_start(event_set) == PAPI_OK, + "Could not start PAPI counters (TODO: this needs some proper handling)."); } #endif xbt_os_threadtimer_start(smpi_process()->timer()); @@ -129,8 +129,8 @@ void smpi_bench_end() int event_set = smpi_process()->papi_event_set(); std::vector event_values(counter_data.size()); - if (event_set && PAPI_stop(event_set, &event_values[0]) != PAPI_OK) // Error - xbt_die("Could not stop PAPI counters."); + if (event_set) + xbt_assert(PAPI_stop(event_set, &event_values[0]) == PAPI_OK, "Could not stop PAPI counters."); for (unsigned int i = 0; i < counter_data.size(); i++) counter_data[i].second += event_values[i]; } @@ -364,8 +364,8 @@ int smpi_sample_2(int global, const char *file, int line, int iter_count) XBT_DEBUG("sample2 %s %d", loc.c_str(), iter_count); auto sample = samples.find(loc); - if (sample == samples.end()) - xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); + xbt_assert(sample != samples.end(), + "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); const LocalData& data = sample->second; if (data.benching) { @@ -400,8 +400,8 @@ void smpi_sample_3(int global, const char *file, int line) XBT_DEBUG("sample3 %s", loc.c_str()); auto sample = samples.find(loc); - if (sample == samples.end()) - xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); + xbt_assert(sample != samples.end(), + "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); LocalData& data = sample->second; if (not data.benching) @@ -432,9 +432,9 @@ int smpi_sample_exit(int global, const char *file, int line, int iter_count){ XBT_DEBUG("sample exit %s", loc.c_str()); auto sample = samples.find(loc); - if (sample == samples.end()) - xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); - + xbt_assert(sample != samples.end(), + "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!"); + if (smpi_process()->sampling()){//end of loop, but still sampling needed const LocalData& data = sample->second; smpi_process()->set_sampling(0); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 72c54250b2..30d81d3027 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -363,10 +363,10 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of close(fdin); close(fdout); return; - } else if (sent_size != -1 || errno != ENOSYS) { - xbt_die("Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(), - sent_size, static_cast(fdin_size), errno, strerror(errno)); } + xbt_assert(sent_size == -1 && errno == ENOSYS, + "Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(), + sent_size, static_cast(fdin_size), errno, strerror(errno)); #endif // If this point is reached, sendfile() actually is not available. Copy file by hand. std::vector buf(1024 * 1024 * 4); diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index f425e22359..c542a20f03 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -159,20 +159,18 @@ Ask the Internet about tutorials on how to increase the files limit such as: htt void* smpi_temp_shm_mmap(int fd, size_t size) { struct stat st; - if (fstat(fd, &st) != 0) - xbt_die("Could not stat fd %d: %s", fd, strerror(errno)); - if (static_cast(size) > st.st_size && ftruncate(fd, static_cast(size)) != 0) - xbt_die("Could not truncate fd %d to %zu: %s", fd, size, strerror(errno)); + xbt_assert(fstat(fd, &st) == 0, "Could not stat fd %d: %s", fd, strerror(errno)); + xbt_assert(static_cast(size) <= st.st_size || ftruncate(fd, static_cast(size)) == 0, + "Could not truncate fd %d to %zu: %s", fd, size, strerror(errno)); void* mem = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (mem == MAP_FAILED) { - xbt_die("Failed to map fd %d with size %zu: %s\n" - "If you are running a lot of ranks, you may be exceeding the amount of mappings allowed per process.\n" - "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n" - "Please see " - "https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization for more " - "information.", - fd, size, strerror(errno)); - } + xbt_assert( + mem != MAP_FAILED, + "Failed to map fd %d with size %zu: %s\n" + "If you are running a lot of ranks, you may be exceeding the amount of mappings allowed per process.\n" + "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n" + "Please see https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization for " + "more information.", + fd, size, strerror(errno)); return mem; } @@ -194,9 +192,9 @@ void smpi_switch_data_segment(simgrid::s4u::ActorPtr actor) XBT_DEBUG("Switching data frame to the one of process %ld", actor->get_pid()); const simgrid::smpi::ActorExt* process = smpi_process_remote(actor); int current = process->privatized_region()->file_descriptor; - const void* tmp = mmap(TOPAGE(smpi_data_exe_start), smpi_data_exe_size, PROT_RW, MAP_FIXED | MAP_SHARED, current, 0); - if (tmp != TOPAGE(smpi_data_exe_start)) - xbt_die("Couldn't map the new region (errno %d): %s", errno, strerror(errno)); + xbt_assert(mmap(TOPAGE(smpi_data_exe_start), smpi_data_exe_size, PROT_RW, MAP_FIXED | MAP_SHARED, current, 0) == + TOPAGE(smpi_data_exe_start), + "Couldn't map the new region (errno %d): %s", errno, strerror(errno)); smpi_loaded_page = actor->get_pid(); #endif } diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index 34e70d267f..b495246201 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -208,9 +208,8 @@ void* smpi_shared_malloc_partial(size_t size, const size_t* shared_block_offsets smpi_shared_malloc_bogusfile = mkstemp(name); XBT_DEBUG("bogusfile : %s\n", name); unlink(name); - int err = ftruncate(smpi_shared_malloc_bogusfile, smpi_shared_malloc_blocksize); - if (err != 0) - xbt_die("Could not write bogus file for shared malloc"); + xbt_assert(ftruncate(smpi_shared_malloc_bogusfile, smpi_shared_malloc_blocksize) == 0, + "Could not write bogus file for shared malloc"); } int mmap_base_flag = MAP_FIXED | MAP_SHARED | MAP_POPULATE; diff --git a/src/smpi/internals/smpi_utils.cpp b/src/smpi/internals/smpi_utils.cpp index a8cbb44c23..784db99396 100644 --- a/src/smpi/internals/smpi_utils.cpp +++ b/src/smpi/internals/smpi_utils.cpp @@ -58,9 +58,8 @@ std::vector parse_factor(const std::string& smpi_coef_string) XBT_DEBUG("token : %s", token_iter->c_str()); Tokenizer factor_values(*token_iter, factor_separator); s_smpi_factor_t fact; - if (factor_values.begin() == factor_values.end()) { - xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string.c_str()); - } + xbt_assert(factor_values.begin() != factor_values.end(), "Malformed radical for smpi factor: '%s'", + smpi_coef_string.c_str()); unsigned int iteration = 0; for (Tokenizer::iterator factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) { iteration++; diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp index 911ee5848b..48647a5637 100644 --- a/src/smpi/mpi/smpi_file.cpp +++ b/src/smpi/mpi/smpi_file.cpp @@ -30,8 +30,8 @@ namespace smpi{ if (info_ != MPI_INFO_NULL) info_->ref(); std::string fullname=filename; - if (simgrid::s4u::Host::current()->get_disks().empty()) - xbt_die("SMPI/IO : Trying to open file on a diskless host ! Add one to your platform file"); + xbt_assert(not simgrid::s4u::Host::current()->get_disks().empty(), + "SMPI/IO : Trying to open file on a diskless host ! Add one to your platform file"); size_t found=fullname.find('/'); //in case no fullpath is provided ... just pick the first mountpoint. diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 14bc5ce8ec..633fcd7e7b 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -73,31 +73,29 @@ void Request::ref(){ void Request::unref(MPI_Request* request) { - if((*request) != MPI_REQUEST_NULL){ - (*request)->refcount_--; - if((*request)->refcount_ < 0) { - (*request)->print_request("wrong refcount"); - xbt_die("Whoops, wrong refcount"); - } - if((*request)->refcount_==0){ - if ((*request)->flags_ & MPI_REQ_GENERALIZED){ - ((*request)->generalized_funcs)->free_fn(((*request)->generalized_funcs)->extra_state); - }else{ - Comm::unref((*request)->comm_); - Datatype::unref((*request)->old_type_); - } - if ((*request)->op_!=MPI_REPLACE && (*request)->op_!=MPI_OP_NULL) - Op::unref(&(*request)->op_); + xbt_assert(*request != MPI_REQUEST_NULL, "freeing an already free request"); - (*request)->print_request("Destroying"); - F2C::free_f((*request)->c2f()); - delete *request; - *request = MPI_REQUEST_NULL; - }else{ - (*request)->print_request("Decrementing"); + (*request)->refcount_--; + if ((*request)->refcount_ < 0) { + (*request)->print_request("wrong refcount"); + xbt_die("Whoops, wrong refcount"); + } + if ((*request)->refcount_ == 0) { + if ((*request)->flags_ & MPI_REQ_GENERALIZED) { + ((*request)->generalized_funcs)->free_fn(((*request)->generalized_funcs)->extra_state); + } else { + Comm::unref((*request)->comm_); + Datatype::unref((*request)->old_type_); } - }else{ - xbt_die("freeing an already free request"); + if ((*request)->op_ != MPI_REPLACE && (*request)->op_ != MPI_OP_NULL) + Op::unref(&(*request)->op_); + + (*request)->print_request("Destroying"); + F2C::free_f((*request)->c2f()); + delete *request; + *request = MPI_REQUEST_NULL; + } else { + (*request)->print_request("Decrementing"); } } diff --git a/src/smpi/mpi/smpi_win.cpp b/src/smpi/mpi/smpi_win.cpp index bc350126b8..b04f1b7c3f 100644 --- a/src/smpi/mpi/smpi_win.cpp +++ b/src/smpi/mpi/smpi_win.cpp @@ -520,8 +520,7 @@ int Win::post(MPI_Group group, int /*assert*/) } int Win::complete(){ - if(opened_==0) - xbt_die("Complete called on already opened MPI_Win"); + xbt_assert(opened_ != 0, "Complete called on already opened MPI_Win"); XBT_DEBUG("Entering MPI_Win_Complete"); int i = 0; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index bce17e5c21..b51fe9c665 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -56,11 +56,10 @@ CpuTiProfile::CpuTiProfile(const profile::Profile* profile) */ double CpuTiTmgr::integrate(double a, double b) const { - if ((a < 0.0) || (a > b)) { - xbt_die("Error, invalid integration interval [%.2f,%.2f]. " - "You probably have a task executing with negative computation amount. Check your code.", - a, b); - } + xbt_assert(a >= 0.0 && a <= b, + "Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative " + "computation amount. Check your code.", + a, b); if (fabs(a - b) < EPSILON) return 0.0; diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 0dbd1ef78e..1195cc736b 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -105,8 +105,8 @@ static void zoneCreation_cb(simgrid::s4u::NetZone const& zone) int mcs_value = mcs ? atoi(mcs) : 3; int nss_value = nss ? atoi(nss) : 1; #if NS3_MINOR_VERSION < 30 - if (nss_value != 1 + (mcs_value / 8)) - xbt_die("On NS3 < 3.30, NSS value has to satisfy NSS == 1+(MCS/8) constraint. Bailing out"); + xbt_assert(nss_value == 1 + (mcs_value / 8), + "On NS3 < 3.30, NSS value has to satisfy NSS == 1+(MCS/8) constraint. Bailing out"); #endif wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "ControlMode", ns3::StringValue("HtMcs0"), "DataMode", ns3::StringValue("HtMcs" + std::to_string(mcs_value))); @@ -574,33 +574,32 @@ void ns3_add_direct_route(simgrid::kernel::routing::NetPoint* src, simgrid::kern xbt_assert(host_src != nullptr, "Network element %s does not seem to be ns-3-ready", src->get_cname()); xbt_assert(host_dst != nullptr, "Network element %s does not seem to be ns-3-ready", dst->get_cname()); - if (policy == simgrid::s4u::Link::SharingPolicy::WIFI) { - xbt_die("The wifi sharing policy is not supported for links. You want to use a wifi zone (see documentation)."); - } else { - ns3::PointToPointHelper pointToPoint; + xbt_assert(policy != simgrid::s4u::Link::SharingPolicy::WIFI, + "The wifi sharing policy is not supported for links. You want to use a wifi zone (see documentation)."); - XBT_DEBUG("\tAdd PTP from %s to %s bw:'%f Bps' lat:'%fs'", src->get_cname(), dst->get_cname(), bw, lat); - pointToPoint.SetDeviceAttribute("DataRate", - ns3::DataRateValue(ns3::DataRate(bw * 8))); // ns-3 takes bps, but we provide Bps - pointToPoint.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat))); + ns3::PointToPointHelper pointToPoint; - netA.Add(pointToPoint.Install(host_src->ns3_node_, host_dst->ns3_node_)); + XBT_DEBUG("\tAdd PTP from %s to %s bw:'%f Bps' lat:'%fs'", src->get_cname(), dst->get_cname(), bw, lat); + pointToPoint.SetDeviceAttribute("DataRate", + ns3::DataRateValue(ns3::DataRate(bw * 8))); // ns-3 takes bps, but we provide Bps + pointToPoint.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat))); - std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links); - address.SetBase(addr.c_str(), "255.255.0.0"); - XBT_DEBUG("\tInterface stack '%s'", addr.c_str()); + netA.Add(pointToPoint.Install(host_src->ns3_node_, host_dst->ns3_node_)); - auto addresses = address.Assign(netA); + std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links); + address.SetBase(addr.c_str(), "255.255.0.0"); + XBT_DEBUG("\tInterface stack '%s'", addr.c_str()); - host_src->ipv4_address_ = transformIpv4Address(addresses.GetAddress(0)); - host_dst->ipv4_address_ = transformIpv4Address(addresses.GetAddress(1)); + auto addresses = address.Assign(netA); - if (number_of_links == 255) { - xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255"); - number_of_links = 1; - number_of_networks++; - } else { - number_of_links++; - } + host_src->ipv4_address_ = transformIpv4Address(addresses.GetAddress(0)); + host_dst->ipv4_address_ = transformIpv4Address(addresses.GetAddress(1)); + + if (number_of_links == 255) { + xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255"); + number_of_links = 1; + number_of_networks++; + } else { + number_of_links++; } } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 4eec01adc6..3e020d7451 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -194,8 +194,7 @@ int find_model_description(const std::vector& table, c if (pos != table.end()) return static_cast(std::distance(table.begin(), pos)); - if (table.empty()) - xbt_die("No model is valid! This is a bug."); + xbt_assert(not table.empty(), "No model is valid! This is a bug."); std::string sep; std::string name_list; diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 59e24dbdcc..52019960a3 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -78,10 +78,8 @@ void parse_platform_file(const std::string& file) luaL_loadfile(L, cfile); // This loads the file without executing it. /* Run the script */ - if (lua_pcall(L, 0, 0, 0)) { - XBT_ERROR("FATAL ERROR:\n %s: %s\n\n", "Lua call failed. Error message:", lua_tostring(L, -1)); - xbt_die("Lua call failed. See Log"); - } + xbt_assert(lua_pcall(L, 0, 0, 0) == 0, "FATAL ERROR:\n %s: %s\n\n", "Lua call failed. Error message:", + lua_tostring(L, -1)); lua_close(L); return; #else diff --git a/src/xbt/automaton/automatonparse_promela.c b/src/xbt/automaton/automatonparse_promela.c index 7c7c90ac12..a257d01c4b 100644 --- a/src/xbt/automaton/automatonparse_promela.c +++ b/src/xbt/automaton/automatonparse_promela.c @@ -64,8 +64,7 @@ void xbt_automaton_load(xbt_automaton_t a, const char *file) { parsed_automaton = a; yyin = fopen(file, "r"); - if (yyin == NULL) - xbt_die("Failed to open automaton file `%s': %s", file, strerror(errno)); + xbt_assert(yyin != NULL, "Failed to open automaton file `%s': %s", file, strerror(errno)); yyparse(); fclose(yyin); } diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index f213bb112c..7cb1f63774 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -56,12 +56,10 @@ double parse_double(const char* value) double res = std::strtod(value, &end); if (errno == ERANGE) throw std::range_error("out of range"); - else if (errno) - xbt_die("Unexpected errno"); + xbt_assert(errno == 0, "Unexpected errno: %d", errno); if (end == value || *end != '\0') throw std::range_error("invalid double"); - else - return res; + return res; } long int parse_long(const char* value) @@ -69,17 +67,12 @@ long int parse_long(const char* value) char* end; errno = 0; long int res = std::strtol(value, &end, 0); - if (errno) { - if (res == LONG_MIN && errno == ERANGE) - throw std::range_error("underflow"); - else if (res == LONG_MAX && errno == ERANGE) - throw std::range_error("overflow"); - xbt_die("Unexpected errno"); - } + if (errno == ERANGE) + throw std::range_error(res == LONG_MIN ? "underflow" : "overflow"); + xbt_assert(errno == 0, "Unexpected errno: %d", errno); if (end == value || *end != '\0') throw std::range_error("invalid integer"); - else - return res; + return res; } // ***** ConfigType ***** diff --git a/src/xbt/string.cpp b/src/xbt/string.cpp index 1b112197d0..7468c3b095 100644 --- a/src/xbt/string.cpp +++ b/src/xbt/string.cpp @@ -26,14 +26,13 @@ std::string string_vprintf(const char *fmt, va_list ap) va_copy(ap2, ap); int size = std::vsnprintf(nullptr, 0, fmt, ap2); va_end(ap2); - if (size < 0) - xbt_die("string_vprintf error"); + xbt_assert(size >= 0, "string_vprintf error"); // Allocate the string and format: std::string res; res.resize(size); - if (size != 0 && std::vsnprintf(&res[0], size + 1, fmt, ap) != size) - xbt_die("string_vprintf error"); + if (size != 0) + xbt_assert(std::vsnprintf(&res[0], size + 1, fmt, ap) == size, "string_vprintf error"); return res; } diff --git a/src/xbt/xbt_log_appender_file.cpp b/src/xbt/xbt_log_appender_file.cpp index 928ef1884f..e014939097 100644 --- a/src/xbt/xbt_log_appender_file.cpp +++ b/src/xbt/xbt_log_appender_file.cpp @@ -41,8 +41,7 @@ xbt_log_appender_t xbt_log_appender_file_new(const char* arg) res->do_append = &append_file; res->free_ = &free_; res->data = static_cast(fopen(arg, "w")); - if (res->data == nullptr) - xbt_die("Cannot open file: %s: %s", arg, strerror(errno)); + xbt_assert(res->data != nullptr, "Cannot open file: %s: %s", arg, strerror(errno)); return res; } @@ -62,8 +61,7 @@ static void open_append2_file(xbt_log_append2_file_t data){ //Roll if (!data->file) { data->file= fopen(data->filename, "w"); - if (data->file == nullptr) - xbt_die("Cannot open file: %s: %s", data->filename, strerror(errno)); + xbt_assert(data->file != nullptr, "Cannot open file: %s: %s", data->filename, strerror(errno)); } else { fputs(APPEND2_END_TOKEN_CLEAR,data->file); fseek(data->file,0,SEEK_SET); @@ -81,8 +79,7 @@ static void open_append2_file(xbt_log_append2_file_t data){ std::string newname = pre + std::to_string(data->count) + post; data->count++; data->file = fopen(newname.c_str(), "w"); - if (data->file == nullptr) - xbt_die("Cannot open file: %s: %s", newname.c_str(), strerror(errno)); + xbt_assert(data->file != nullptr, "Cannot open file: %s: %s", newname.c_str(), strerror(errno)); xbt_free(pre); } } diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index 46668da675..44583a157c 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -202,8 +202,8 @@ int main(int argc, char** argv) sg4::Engine e(&argc, argv); - if (not parse_cmdline(&timings, &platformFile, argc, argv) || not platformFile) - xbt_die("Invalid command line arguments: expected [--timings] platformFile"); + xbt_assert(parse_cmdline(&timings, &platformFile, argc, argv) && platformFile, + "Invalid command line arguments: expected [--timings] platformFile"); XBT_DEBUG("%d,%s", timings, platformFile); diff --git a/teshsuite/smpi/coll-allreduce-with-leaks/coll-allreduce-with-leaks.tesh b/teshsuite/smpi/coll-allreduce-with-leaks/coll-allreduce-with-leaks.tesh index db31cd0a08..a4ac497845 100644 --- a/teshsuite/smpi/coll-allreduce-with-leaks/coll-allreduce-with-leaks.tesh +++ b/teshsuite/smpi/coll-allreduce-with-leaks/coll-allreduce-with-leaks.tesh @@ -20,7 +20,7 @@ $ $VALGRIND_NO_LEAK_CHECK ${bindir:=.}/../../../smpi_script/bin/smpirun -map -ho > [rank 14] -> Ginette > [rank 15] -> Ginette > If this is too much, consider sharing allocations for computation buffers. -> Largest allocation at once from a single process was 64 bytes, at sysdep.h:61. It was called 32 times during the whole simulation. +> Largest allocation at once from a single process was 64 bytes, at sysdep.h:59. It was called 32 times during the whole simulation. > Running smpirun with -wrapper "valgrind --leak-check=full" can provide more information > This can be done automatically by setting --cfg=smpi/auto-shared-malloc-thresh to the minimum size wanted size (this can alter execution if data content is necessary) > [0.023768] [smpi_utils/INFO] Probable memory leaks in your code: SMPI detected 31 unfreed MPI handles : display types and addresses (n max) with --cfg=smpi/list-leaks:n. diff --git a/teshsuite/xbt/mmalloc/mmalloc_test.cpp b/teshsuite/xbt/mmalloc/mmalloc_test.cpp index b610e1f042..1a370eb196 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_test.cpp +++ b/teshsuite/xbt/mmalloc/mmalloc_test.cpp @@ -27,8 +27,7 @@ constexpr int TESTSIZE = 100; static void check_block(const unsigned char* p, unsigned char b, int n) { for (int i = 0; i < n; i++) - if (p[i] != b) - xbt_die("value mismatch: %p[%d] = %#hhx, expected %#hhx", p, i, p[i], b); + xbt_assert(p[i] == b, "value mismatch: %p[%d] = %#hhx, expected %#hhx", p, i, p[i], b); } int main(int argc, char**argv) @@ -80,8 +79,7 @@ int main(int argc, char**argv) } catch (const simgrid::Exception&) { gotit = true; } - if (not gotit) - xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i)); + xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i)); } XBT_INFO("free again all blocks (to really check that double free are correctly caught)"); @@ -92,8 +90,7 @@ int main(int argc, char**argv) } catch (const simgrid::Exception&) { gotit = true; } - if (not gotit) - xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i)); + xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i)); } XBT_INFO("Let's try different codepaths for mrealloc"); -- 2.20.1