Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add msg process test and fix ppid of created processes
authorPaul Bédaride <paul.bedaride@gmail.com>
Fri, 7 Mar 2014 09:30:17 +0000 (10:30 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Fri, 7 Mar 2014 10:42:27 +0000 (11:42 +0100)
buildtools/Cmake/AddTests.cmake
src/simix/smx_process.c
src/simix/smx_process_private.h
teshsuite/msg/CMakeLists.txt
teshsuite/msg/host_on_off.tesh
teshsuite/msg/process.c [new file with mode: 0644]
teshsuite/msg/process.tesh [new file with mode: 0644]
teshsuite/msg/process.xml [new file with mode: 0644]

index 8e85c16..1d6641a 100644 (file)
@@ -118,7 +118,6 @@ if(NOT enable_memcheck)
     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()
 
-
   ADD_TEST(tesh-msg-task-destroy-cancel-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/task_destroy_cancel.tesh)
   if(HAVE_RAWCTX)
     ADD_TEST(tesh-msg-task-destroy-cancel-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/task_destroy_cancel.tesh)
@@ -127,6 +126,15 @@ if(NOT enable_memcheck)
     ADD_TEST(tesh-msg-task-destroy-cancel-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/task_destroy_cancel.tesh)
   endif()
 
+  ADD_TEST(tesh-msg-process-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/process.tesh)
+  if(HAVE_RAWCTX)
+    ADD_TEST(tesh-msg-process-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/process.tesh)
+  endif()
+  if(CONTEXT_UCONTEXT)
+    ADD_TEST(tesh-msg-process-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/process.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 b71da54..1444dc0 100644 (file)
@@ -211,8 +211,9 @@ void SIMIX_pre_process_create(smx_simcall_t simcall,
                           int argc, char **argv,
                           xbt_dict_t properties,
                           int auto_restart){
-  SIMIX_process_create(process, name, code, data, hostname,
-                       kill_time, argc, argv, properties, auto_restart);
+  SIMIX_process_create_with_parent(process, name, code, data, hostname,
+                              kill_time, argc, argv, properties, auto_restart,
+                              simcall->issuer);
 }
 /**
  * \brief Internal function to create a process.
@@ -232,7 +233,20 @@ void SIMIX_process_create(smx_process_t *process,
                           int argc, char **argv,
                           xbt_dict_t properties,
                           int auto_restart) {
-
+  SIMIX_process_create_with_parent(process, name, code, data, hostname,
+                                   kill_time, argc, argv, properties, auto_restart, NULL);
+}
+
+void SIMIX_process_create_with_parent(smx_process_t *process,
+                                 const char *name,
+                                 xbt_main_func_t code,
+                                 void *data,
+                                 const char *hostname,
+                                 double kill_time,
+                                 int argc, char **argv,
+                                 xbt_dict_t properties,
+                                 int auto_restart,
+                                 smx_process_t parent_process) {
   *process = NULL;
   smx_host_t host = SIMIX_host_get_by_name(hostname);
 
@@ -258,8 +272,8 @@ void SIMIX_process_create(smx_process_t *process,
     (*process)->comms = xbt_fifo_new();
     (*process)->simcall.issuer = *process;
     
-     if (SIMIX_process_self()) {
-       (*process)->ppid = SIMIX_process_get_PID(SIMIX_process_self());
+     if (parent_process) {
+       (*process)->ppid = SIMIX_process_get_PID(parent_process);
      } else {
        (*process)->ppid = -1;
      }
@@ -722,7 +736,7 @@ void SIMIX_post_process_sleep(smx_action_t action)
 {
   smx_simcall_t simcall;
   e_smx_state_t state;
-
+  smx_process_t issuer;
   xbt_assert(action->type == SIMIX_ACTION_SLEEP);
 
   while ((simcall = xbt_fifo_shift(action->simcalls))) {
@@ -748,9 +762,13 @@ void SIMIX_post_process_sleep(smx_action_t action)
     simcall_process_sleep__set__result(simcall, state);
     simcall->issuer->waiting_action = NULL;
     SIMIX_simcall_answer(simcall);
+    issuer = simcall->issuer;
 
   }
+
   SIMIX_process_sleep_destroy(action);
+  if (issuer->suspended)
+       simcall_process_suspend(issuer);
 }
 
 void SIMIX_process_sleep_destroy(smx_action_t action)
index ac0126e..0d24943 100644 (file)
@@ -71,6 +71,16 @@ void SIMIX_process_create(smx_process_t *process,
                           int argc, char **argv,
                           xbt_dict_t properties,
                           int auto_restart);
+void SIMIX_process_create_with_parent(smx_process_t *process,
+                                 const char *name,
+                                 xbt_main_func_t code,
+                                 void *data,
+                                 const char *hostname,
+                                 double kill_time,
+                                 int argc, char **argv,
+                                 xbt_dict_t properties,
+                                 int auto_restart,
+                                 smx_process_t parent_process);
 void SIMIX_process_runall(void);
 void SIMIX_process_kill(smx_process_t process, smx_process_t issuer);
 void SIMIX_process_killall(smx_process_t issuer, int reset_pid);
index 1656f25..983748b 100644 (file)
@@ -6,12 +6,14 @@ 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_executable(task_destroy_cancel ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/task_destroy_cancel.c)
+add_executable(process ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process.c)
 
 
 ### Add definitions for compile
 target_link_libraries(get_sender simgrid)
 target_link_libraries(host_on_off simgrid)
 target_link_libraries(task_destroy_cancel simgrid)
+target_link_libraries(process simgrid)
 if(NOT WIN32)
   target_link_libraries(pid simgrid m pthread)
 else()
@@ -24,6 +26,7 @@ set(tesh_files
   ${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
   ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh
   ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.tesh
+  ${CMAKE_CURRENT_SOURCE_DIR}/process.tesh
   PARENT_SCOPE
   )
 set(xml_files
@@ -36,6 +39,7 @@ set(xml_files
   ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off_p.xml
   ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel_d.xml
   ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel_p.xml
+  ${CMAKE_CURRENT_SOURCE_DIR}/process.xml
   PARENT_SCOPE
   )
 set(teshsuite_src
@@ -44,6 +48,7 @@ set(teshsuite_src
   ${CMAKE_CURRENT_SOURCE_DIR}/pid.c
   ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c
   ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.c
+  ${CMAKE_CURRENT_SOURCE_DIR}/process.c
   PARENT_SCOPE
   )
 set(bin_files
index 7b613bc..2e3e456 100644 (file)
@@ -10,3 +10,4 @@ $ msg/host_on_off ${srcdir:=.}/msg/host_on_off_p.xml ${srcdir:=.}/msg/host_on_of
 > [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/process.c b/teshsuite/msg/process.c
new file mode 100644 (file)
index 0000000..e01112b
--- /dev/null
@@ -0,0 +1,103 @@
+/* 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[])
+{
+  xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
+  msg_process_t process = NULL;
+  MSG_process_sleep(1);
+  xbt_swag_foreach(process, process_list) {
+       XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), MSG_process_get_name(process));
+    if (MSG_process_self_PID()!=MSG_process_get_PID(process))
+      MSG_process_kill(process);
+  }
+  process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
+  MSG_process_sleep(2);
+
+  XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
+  MSG_process_suspend(process);
+
+  XBT_INFO("Process(pid=%d) is %ssuspended"
+                 ,MSG_process_get_PID(process)
+                 ,(MSG_process_is_suspended(process)) ? "" : "not ");
+  MSG_process_sleep(2);
+
+  XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
+  MSG_process_resume(process);
+
+  XBT_INFO("Process(pid=%d) is %ssuspended"
+                 ,MSG_process_get_PID(process)
+                 ,(MSG_process_is_suspended(process)) ? "" : "not ");
+  MSG_process_sleep(2);
+  MSG_process_kill(process);
+
+  XBT_INFO("Goodbye now!");
+  return 0;
+}                               /* end_of_master */
+
+/** Receiver function  */
+int slave(int argc, char *argv[])
+{
+  MSG_process_sleep(.5);
+  XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
+  while(1){
+       XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
+    MSG_process_sleep(1);
+    //MSG_process_suspend(MSG_process_self());
+  }
+  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/process.tesh b/teshsuite/msg/process.tesh
new file mode 100644 (file)
index 0000000..90a2575
--- /dev/null
@@ -0,0 +1,17 @@
+
+$ msg/process ${srcdir:=.}/msg/process.xml
+> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Slave started (PID:2, PPID:0)
+> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=1, ppid=0, name=master)
+> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=2, ppid=0, name=slave)
+> [Tremblay:slave from master:(3) 1.500000] [msg_test/INFO] Slave started (PID:3, PPID:1)
+> [Tremblay:slave from master:(3) 1.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:slave from master:(3) 2.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Suspend Process(pid=3)
+> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Process(pid=3) is suspended
+> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Resume Process(pid=3)
+> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Process(pid=3) is not suspended
+> [Tremblay:slave from master:(3) 5.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:slave from master:(3) 6.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:master:(1) 7.000000] [msg_test/INFO] Goodbye now!
+> [7.000000] [msg_test/INFO] Simulation time 7
diff --git a/teshsuite/msg/process.xml b/teshsuite/msg/process.xml
new file mode 100644 (file)
index 0000000..f0c3dae
--- /dev/null
@@ -0,0 +1,16 @@
+<?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"/>
+  </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="Tremblay" function="slave">
+  </process>
+ </platform>
\ No newline at end of file