Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar
[simgrid.git] / examples / s4u / platform-failures / s4u-platform-failures.cpp
index d0b33fd..941ea2a 100644 (file)
@@ -11,6 +11,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example")
 
 static int master(int argc, char* argv[])
 {
+  xbt_assert(argc == 5, "Expecting one parameter");
+
   simgrid::s4u::MailboxPtr mailbox;
   long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
   double comp_size     = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
@@ -75,10 +77,11 @@ static int master(int argc, char* argv[])
 
 static int worker(int argc, char* argv[])
 {
+  xbt_assert(argc == 2, "Expecting one parameter");
   long id                          = xbt_str_parse_int(argv[1], "Invalid argument %s");
   simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::by_name(std::string("worker-") + std::to_string(id));
   double* payload                  = nullptr;
-  double comp_size;
+  double comp_size                 = -1;
   while (1) {
     try {
       payload   = static_cast<double*>(mailbox->get());
@@ -105,13 +108,11 @@ static int worker(int argc, char* argv[])
     try {
       simgrid::s4u::this_actor::execute(comp_size);
     } catch (xbt_ex& e) {
-      switch (e.category) {
-        case host_error:
-          XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
-          return -1;
-        default:
-          xbt_die("Unexpected behavior");
-      }
+      if (e.category == host_error) {
+        XBT_INFO("Gloups. The cpu on which I'm running just turned off!. See you!");
+        return -1;
+      } else
+        xbt_die("Unexpected behavior");
     }
   }
   XBT_INFO("I'm done. See you!");