Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
do not promote bad practices: use "accessor" to get task name
[simgrid.git] / teshsuite / msg / host_on_off / host_on_off.c
index fcb42c6..db526a4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2015. The SimGrid Team.
+/* Copyright (c) 2010-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -17,6 +17,10 @@ static int slave(int argc, char *argv[])
 
   while (1) {
     res = MSG_task_receive(&(task), mailbox);
+    if (res == MSG_HOST_FAILURE) {
+      XBT_DEBUG("The host has been turned off, this was expected");
+      return 1;
+    }
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
 
     if (!strcmp(MSG_task_get_name(task), "finalize")) {
@@ -40,11 +44,10 @@ static int master(int argc, char *argv[])
   double task_comm_size = 1E6;
 
   const char * mailbox = "jupi";
-  msg_task_t task = NULL;
   msg_host_t jupiter = MSG_host_by_name("Jupiter");
 
-  task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL);
-  XBT_INFO("Sending \"%s\"", task->name);
+  msg_task_t task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL);
+  XBT_INFO("Sending \"%s\"", MSG_task_get_name(task));
   if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
     MSG_task_destroy(task);
 
@@ -52,19 +55,23 @@ static int master(int argc, char *argv[])
   MSG_host_off(jupiter);
 
   task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL);
-  XBT_INFO("Sending \"%s\"", task->name);
+  XBT_INFO("Sending \"%s\"", MSG_task_get_name(task));
   if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
     MSG_task_destroy(task);
 
   MSG_host_on(jupiter);
-  xbt_swag_t jupi_processes = MSG_host_get_process_list(jupiter);
-  void *process;
-  xbt_swag_foreach(process, jupi_processes) {
+
+  xbt_dynar_t jupi_processes = xbt_dynar_new(sizeof(msg_process_t), NULL);
+  MSG_host_get_process_list(jupiter, jupi_processes);
+  msg_process_t process = NULL;
+  unsigned int cursor;
+  xbt_dynar_foreach (jupi_processes, cursor, process) {
     MSG_process_kill(process);
   }
+  xbt_dynar_free(&jupi_processes);
 
   task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL);
-  XBT_INFO("Sending \"%s\"", task->name);
+  XBT_INFO("Sending \"%s\"", MSG_task_get_name(task));
   if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
     MSG_task_destroy(task);
 
@@ -73,12 +80,12 @@ static int master(int argc, char *argv[])
   MSG_process_create_with_arguments("slave", slave, NULL, MSG_host_by_name("Jupiter"), 1, argvF);
 
   task = MSG_task_create("task on with proc", task_comp_size, task_comm_size, NULL);
-  XBT_INFO("Sending \"%s\"", task->name);
+  XBT_INFO("Sending \"%s\"", MSG_task_get_name(task));
   if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
     MSG_task_destroy(task);
 
   task = MSG_task_create("finalize", 0, 0, 0);
-  XBT_INFO("Sending \"%s\"", task->name);
+  XBT_INFO("Sending \"%s\"", MSG_task_get_name(task));
   if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
     MSG_task_destroy(task);