Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add msg host on/off test
authorPaul Bédaride <paul.bedaride@gmail.com>
Tue, 4 Mar 2014 16:17:21 +0000 (17:17 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 5 Mar 2014 16:34:36 +0000 (17:34 +0100)
buildtools/Cmake/AddTests.cmake
src/simix/smx_host.c
teshsuite/msg/CMakeLists.txt
teshsuite/msg/host_on_off.c [new file with mode: 0644]
teshsuite/msg/host_on_off.tesh [new file with mode: 0644]
teshsuite/msg/host_on_off.xml [new file with mode: 0644]

index aa7a9b2..cc1ceb5 100644 (file)
@@ -110,6 +110,15 @@ if(NOT enable_memcheck)
     ADD_TEST(tesh-msg-pid-ucontext              ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:ucontext --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid.tesh)
   endif()
 
+  ADD_TEST(tesh-msg-host-on-off-thread          ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:thread --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.tesh)
+  if(HAVE_RAWCTX)
+    ADD_TEST(tesh-msg-host-on-off-raw           ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:raw --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.tesh)
+  endif()
+  if(CONTEXT_UCONTEXT)
+    ADD_TEST(tesh-msg-host-on-off-ucontext      ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:ucontext --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.tesh)
+  endif()
+
+
   # these tests need the assertion mechanism
   # exclude them from memcheck, as they normally die, leaving lots of unfree'd objects
   IF(enable_debug AND NOT enable_memcheck)
index 2f88f82..80c5d6c 100644 (file)
@@ -103,8 +103,8 @@ void SIMIX_host_off(smx_host_t h, smx_process_t issuer)
 
   xbt_assert((host != NULL), "Invalid parameters");
   
-  if (surf_resource_get_state(surf_workstation_resource_priv(h))==SURF_RESOURCE_OFF) {
-       surf_resource_set_state(surf_workstation_resource_priv(h), SURF_RESOURCE_ON);
+  if (surf_resource_get_state(surf_workstation_resource_priv(h))==SURF_RESOURCE_ON) {
+       surf_resource_set_state(surf_workstation_resource_priv(h), SURF_RESOURCE_OFF);
 
     /* Clean Simulator data */
     if (xbt_swag_size(host->process_list) != 0) {
index 065b8f6..ec4f4f1 100644 (file)
@@ -4,13 +4,15 @@ set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}")
 
 add_executable(get_sender ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/get_sender.c)
 add_executable(pid ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid.c)
+add_executable(host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.c)
+
 
 ### Add definitions for compile
+target_link_libraries(get_sender simgrid)
+target_link_libraries(host_on_off simgrid)
 if(NOT WIN32)
-  target_link_libraries(get_sender simgrid)
   target_link_libraries(pid simgrid m pthread)
 else()
-  target_link_libraries(get_sender simgrid)
   target_link_libraries(pid simgrid)
 endif()
 
@@ -18,6 +20,7 @@ set(tesh_files
   ${tesh_files}
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.tesh
   ${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
+  ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh
   PARENT_SCOPE
   )
 set(xml_files
@@ -26,12 +29,14 @@ set(xml_files
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender_p.xml
   ${CMAKE_CURRENT_SOURCE_DIR}/pid_d.xml
   ${CMAKE_CURRENT_SOURCE_DIR}/pid_p.xml
+  ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.xml
   PARENT_SCOPE
   )
 set(teshsuite_src
   ${teshsuite_src}
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.c
   ${CMAKE_CURRENT_SOURCE_DIR}/pid.c
+  ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c
   PARENT_SCOPE
   )
 set(bin_files
diff --git a/teshsuite/msg/host_on_off.c b/teshsuite/msg/host_on_off.c
new file mode 100644 (file)
index 0000000..a26d7e0
--- /dev/null
@@ -0,0 +1,128 @@
+/* Copyright (c) 2010-2014. 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. */
+
+#include <stdio.h>
+#include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
+#include "xbt/sysdep.h"         /* calloc, printf */
+
+/* Create a log channel to have nice outputs. */
+#include "xbt/log.h"
+#include "xbt/asserts.h"
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
+                             "Messages specific for this msg example");
+
+int master(int argc, char *argv[]);
+int slave(int argc, char *argv[]);
+
+/** Emitter function  */
+int master(int argc, char *argv[])
+{
+  double task_comp_size = 5E7;
+  double task_comm_size = 1E6;
+
+  char mailbox[256];
+  msg_task_t task = NULL;
+
+  sprintf(mailbox, "jupi");
+
+  task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL);
+  XBT_INFO("Sending \"%s\"", task->name);
+  MSG_task_send_with_timeout(task, mailbox, 1);
+
+  MSG_process_sleep(1);
+  MSG_host_off(MSG_get_host_by_name("Jupiter"));
+
+  task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL);
+  XBT_INFO("Sending \"%s\"", task->name);
+  MSG_task_send_with_timeout(task, mailbox, 1);
+
+  MSG_host_on(MSG_get_host_by_name("Jupiter"));
+
+  task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL);
+  XBT_INFO("Sending \"%s\"", task->name);
+  MSG_task_send_with_timeout(task, mailbox, 1);
+
+  char **argvF = xbt_new(char*, 2);
+  argvF[0] = xbt_strdup("slave");
+  MSG_process_create_with_arguments("slave", slave, NULL, MSG_get_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);
+  MSG_task_send_with_timeout(task, mailbox, 1);
+
+  task = MSG_task_create("finalize", 0, 0, 0);
+  XBT_INFO("Sending \"%s\"", task->name);
+  MSG_task_send_with_timeout(task, mailbox, 1);
+
+  XBT_INFO("Goodbye now!");
+  return 0;
+}                               /* end_of_master */
+
+/** Receiver function  */
+int slave(int argc, char *argv[])
+{
+  msg_task_t task = NULL;
+  _XBT_GNUC_UNUSED int res;
+  int id = -1;
+  char mailbox[80];
+  _XBT_GNUC_UNUSED int read;
+
+  sprintf(mailbox, "jupi");
+
+  while (1) {
+    res = MSG_task_receive(&(task), mailbox);
+    xbt_assert(res == MSG_OK, "MSG_task_get failed");
+
+    if (!strcmp(MSG_task_get_name(task), "finalize")) {
+      MSG_task_destroy(task);
+      break;
+    }
+    MSG_task_execute(task);
+    XBT_INFO("Task \"%s\" done", MSG_task_get_name(task));
+
+    MSG_task_destroy(task);
+    task = NULL;
+    id--;
+  }
+  XBT_INFO("I'm done. See you!");
+  return 0;
+}                               /* end_of_slave */
+
+/** Main function */
+int main(int argc, char *argv[])
+{
+  msg_error_t res;
+  const char *platform_file;
+  const char *application_file;
+
+  MSG_init(&argc, argv);
+  if (argc < 2) {
+    printf("Usage: %s platform_file deployment_file\n", argv[0]);
+    printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
+    exit(1);
+  }
+  platform_file = argv[1];
+  application_file = argv[1];
+
+  /* MSG_config("workstation/model","KCCFLN05"); */
+  {                             /*  Simulation setting */
+    MSG_create_environment(platform_file);
+  }
+  {                             /*   Application deployment */
+    MSG_function_register("master", master);
+    MSG_function_register("slave", slave);
+
+    MSG_launch_application(application_file);
+  }
+  res = MSG_main();
+
+  XBT_INFO("Simulation time %g", MSG_get_clock());
+
+  if (res == MSG_OK)
+    return 0;
+  else
+    return 1;
+}                               /* end_of_main */
diff --git a/teshsuite/msg/host_on_off.tesh b/teshsuite/msg/host_on_off.tesh
new file mode 100644 (file)
index 0000000..403d26d
--- /dev/null
@@ -0,0 +1,12 @@
+
+$ msg/host_on_off  ${srcdir:=.}/msg/host_on_off.xml
+> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Sending "task on"
+> [Jupiter:slave:(2) 0.682345] [msg_test/INFO] Task "task on" done
+> [Tremblay:master:(1) 1.027003] [msg_test/INFO] Sending "task off"
+> [Tremblay:master:(1) 2.027003] [msg_test/INFO] Sending "task on without proc"
+> [Tremblay:master:(1) 3.027003] [msg_test/INFO] Sending "task on with proc"
+> [Tremblay:master:(1) 3.054005] [msg_test/INFO] Sending "finalize"
+> [Jupiter:slave:(3) 3.709348] [msg_test/INFO] Task "task on with proc" done
+> [Tremblay:master:(1) 3.710127] [msg_test/INFO] Goodbye now!
+> [Jupiter:slave:(3) 3.710127] [msg_test/INFO] I'm done. See you!
+> [3.710127] [msg_test/INFO] Simulation time 3.71013
diff --git a/teshsuite/msg/host_on_off.xml b/teshsuite/msg/host_on_off.xml
new file mode 100644 (file)
index 0000000..d57e0f3
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+  <!-- The hosts -->
+  <AS  id="AS0"  routing="Full">
+   <host id="Tremblay" power="98.095Mf"/>
+   <host id="Jupiter" power="76.296Mf"/>
+   <link id="1" bandwidth="41.279125MBps" latency="59.904us"/>
+   <route src="Tremblay" dst="Jupiter">
+    <link_ctn id="1"/>
+   </route>
+  </AS>
+
+  <!-- The master process (with some arguments) -->
+  <process host="Tremblay" function="master">
+  </process>
+  
+  <!-- The slave processes (with mailbox to listen on as argument) -->
+  <process host="Jupiter" function="slave">
+  </process>
+ </platform>
\ No newline at end of file