X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4c6a19b8e36d30979362b3762766ef33d74edd01..8d0b1f2f1840a16bb9551f1cfd74f2488599f95b:/teshsuite/s4u/comm-fault-scenarios/comm-fault-scenarios.cpp diff --git a/teshsuite/s4u/comm-fault-scenarios/comm-fault-scenarios.cpp b/teshsuite/s4u/comm-fault-scenarios/comm-fault-scenarios.cpp index 0b896cc8a8..b996076738 100644 --- a/teshsuite/s4u/comm-fault-scenarios/comm-fault-scenarios.cpp +++ b/teshsuite/s4u/comm-fault-scenarios/comm-fault-scenarios.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -117,7 +117,7 @@ class SendAgent { const MBoxes& mbox_; const ScenarioContext& ctx_; - sg4::CommPtr do_put(CommType type, double& send_value) + sg4::CommPtr do_put(CommType type, double& send_value) const { switch (type) { case CommType::EAGER_SYNC: @@ -145,7 +145,7 @@ class SendAgent { DIE_IMPOSSIBLE; } - void send_message(const Scenario& s) + void send_message(const Scenario& s) const { std::string scenario_string = to_string(s); XBT_DEBUG("Will try: %s", scenario_string.c_str()); @@ -159,21 +159,23 @@ class SendAgent { // Make sure we have a clean slate xbt_assert(not mbox_.eager->listen(), "Eager mailbox should be empty when starting a test"); xbt_assert(not mbox_.rdv->listen(), "RDV mailbox should be empty when starting a test"); - for (; step_index < s.steps.size(); step_index++) { - const Step& step = s.steps[step_index]; - if (step.entity != Step::Entity::SND || step.type != Step::Type::ACTION) - continue; - try { + + Action current_action; + try { + for (; step_index < s.steps.size(); step_index++) { + const Step& step = s.steps[step_index]; + if (step.entity != Step::Entity::SND || step.type != Step::Type::ACTION) + continue; + + current_action = Action::SLEEP; sg4::this_actor::sleep_until(s.start_time + step.rel_time); - } catch (const simgrid::Exception& e) { - XBT_DEBUG("During Sleep, failed to send message because of a %s exception (%s)", typeid(e).name(), e.what()); - break; - } - // Check if the other host is still OK. - if (not other_host_->is_on()) - break; - // Perform the action - try { + + // Check if the other host is still OK. + if (not other_host_->is_on()) + break; + + // Perform the action + current_action = step.action_type; switch (step.action_type) { case Action::PUT: comm = do_put(s.type, send_value); @@ -187,11 +189,10 @@ class SendAgent { default: xbt_die("Not a valid action for SND"); } - } catch (const simgrid::Exception& e) { - XBT_DEBUG("During %s, failed to send message because of a %s exception (%s)", to_c_str(step.action_type), - typeid(e).name(), e.what()); - break; } + } catch (const simgrid::Exception& e) { + XBT_DEBUG("During %s, failed to send message because of a %s exception (%s)", to_c_str(current_action), + typeid(e).name(), e.what()); } try { sg4::this_actor::sleep_until(end_time); @@ -220,7 +221,7 @@ public: { } - void operator()() + void operator()() const { run_++; XBT_DEBUG("Host %i starts run %i and scenario %zu.", id_, run_, scenario_); @@ -283,21 +284,21 @@ class ReceiveAgent { // Make sure we have a clean slate xbt_assert(not mbox_.eager->listen(), "Eager mailbox should be empty when starting a test"); xbt_assert(not mbox_.rdv->listen(), "RDV mailbox should be empty when starting a test"); - for (; step_index < s.steps.size(); step_index++) { - const Step& step = s.steps[step_index]; - if (step.entity != Step::Entity::RCV || step.type != Step::Type::ACTION) - continue; - try { + + Action current_action; + try { + for (; step_index < s.steps.size(); step_index++) { + const Step& step = s.steps[step_index]; + if (step.entity != Step::Entity::RCV || step.type != Step::Type::ACTION) + continue; + + current_action = Action::SLEEP; sg4::this_actor::sleep_until(s.start_time + step.rel_time); - } catch (const simgrid::Exception& e) { - XBT_DEBUG("During Sleep, failed to receive message because of a %s exception (%s)", typeid(e).name(), e.what()); - break; - } - // Check if the other host is still OK. - if (not other_host_->is_on()) - break; - // Perform the action - try { + + // Check if the other host is still OK. + if (not other_host_->is_on()) + break; + // Perform the action switch (step.action_type) { case Action::GET: comm = do_get(type, receive_ptr); @@ -311,11 +312,10 @@ class ReceiveAgent { default: xbt_die("Not a valid action for RCV"); } - } catch (const simgrid::Exception& e) { - XBT_DEBUG("During %s, failed to receive message because of a %s exception (%s)", to_c_str(step.action_type), - typeid(e).name(), e.what()); - break; } + } catch (const simgrid::Exception& e) { + XBT_DEBUG("During %s, failed to receive message because of a %s exception (%s)", to_c_str(current_action), + typeid(e).name(), e.what()); } try { sg4::this_actor::sleep_until(end_time - .1); @@ -352,7 +352,7 @@ public: : id_(id), other_host_(other_host), mbox_(mbox), ctx_(ctx) { } - void operator()() + void operator()() const { run_++; XBT_DEBUG("Host %i starts run %i and scenario %zu.", id_, run_, scenario_); @@ -409,11 +409,10 @@ int main(int argc, char* argv[]) pr::Profile* profile_link = pr::ProfileBuilder::from_string("link_profile", ctx.link_profile.str(), 0); sg4::Link const* link = zone->create_link("link", LinkBandwidth)->set_latency(LinkLatency)->set_state_profile(profile_link)->seal(); - zone->add_route(sender_host->get_netpoint(), receiver_host->get_netpoint(), nullptr, nullptr, - {sg4::LinkInRoute{link}}, false); + zone->add_route(sender_host, receiver_host, {link}); zone->seal(); - sg4::Host::on_state_change_cb([mbox](sg4::Host const& host) { + sg4::Host::on_onoff_cb([mbox](sg4::Host const& host) { XBT_DEBUG("Host %s is now %s", host.get_cname(), host.is_on() ? "ON " : "OFF"); if (not host.is_on()) { mbox.eager->clear(); @@ -421,7 +420,7 @@ int main(int argc, char* argv[]) } }); - sg4::Link::on_state_change_cb( + sg4::Link::on_onoff_cb( [](sg4::Link const& lnk) { XBT_DEBUG("Link %s is now %s", lnk.get_cname(), lnk.is_on() ? "ON " : "OFF"); }); e.run_until(end_time); @@ -457,7 +456,8 @@ static void prepareScenario(ScenarioContext& ctx, CommType type, double duration DIE_IMPOSSIBLE; } } - ctx.scenarios.push_back({type, ctx.start_time, duration, sender_expected, receiver_expected, steps, ctx.index}); + Scenario scen{type, ctx.start_time, duration, sender_expected, receiver_expected, steps, ctx.index}; + ctx.scenarios.push_back(scen); ctx.active++; } ctx.index++;