Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add test for msg pid
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 30 Jan 2013 10:27:42 +0000 (11:27 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 30 Jan 2013 15:18:57 +0000 (16:18 +0100)
buildtools/Cmake/AddTests.cmake
teshsuite/msg/CMakeLists.txt
teshsuite/msg/pid.c [new file with mode: 0644]
teshsuite/msg/pid.tesh [new file with mode: 0644]
teshsuite/msg/pid.xml [new file with mode: 0644]

index 7e59b1b..25c58ca 100644 (file)
@@ -68,6 +68,15 @@ if(NOT enable_memcheck)
     ADD_TEST(tesh-msg-get-sender-ucontext       ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/get_sender.tesh)
   endif()
 
+  ADD_TEST(tesh-msg-pid-thread           ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:thread --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid.tesh)
+  if(HAVE_RAWCTX)
+    ADD_TEST(tesh-msg-pid-raw            ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:raw --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid.tesh)
+  endif()
+  if(CONTEXT_UCONTEXT)
+    ADD_TEST(tesh-msg-pid-ucontext       ${CMAKE_BINARY_DIR}/bin/tesh ${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()
+
+
   IF(enable_debug) # these tests need the assertion mechanism
     ADD_TEST(tesh-simdag-parser-bogus-symmetric ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/simdag/platforms --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/simdag/platforms two_hosts_asymetric.tesh)
   ENDIF()
index 4f22b3c..eeb9d84 100644 (file)
@@ -3,17 +3,21 @@ cmake_minimum_required(VERSION 2.6)
 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 definitions for compile
 if(NOT WIN32)
-  target_link_libraries(get_sender simgrid m pthread )
+  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()
 
 set(tesh_files
   ${tesh_files}
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.tesh
+  ${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
   PARENT_SCOPE
   )
 set(xml_files
@@ -21,11 +25,13 @@ set(xml_files
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.xml
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender_d.xml
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender_p.xml
+  ${CMAKE_CURRENT_SOURCE_DIR}/pid.xml
   PARENT_SCOPE
   )
 set(teshsuite_src
   ${teshsuite_src}
   ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.c
+  ${CMAKE_CURRENT_SOURCE_DIR}/pid.c
   PARENT_SCOPE
   )
 set(bin_files
diff --git a/teshsuite/msg/pid.c b/teshsuite/msg/pid.c
new file mode 100644 (file)
index 0000000..1f04fb2
--- /dev/null
@@ -0,0 +1,65 @@
+/* Copyright (c) 2009, 2010. 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 "msg/msg.h"
+#include "xbt/sysdep.h"        
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
+                             "Messages specific for this msg example");
+char* mailbox = "mailbox";
+#define task_comp_size 1000
+#define task_comm_size 100000
+
+int onexit(void* data){
+  XBT_INFO("Process \"%d\" killed.", *((int*)data));  
+}
+
+int sendpid(int argc, char *argv[])
+{
+  int pid = MSG_process_self_PID();
+  MSG_process_on_exit(onexit, &pid);  
+  msg_task_t task = MSG_task_create("pid", task_comp_size, task_comm_size, &pid);
+  XBT_INFO("Sending pid of \"%d\".", pid);
+  MSG_task_send(task, mailbox);
+  XBT_INFO("Send of pid \"%d\" done.", pid);
+  MSG_process_suspend(MSG_process_self());
+}
+
+int killall(int argc, char *argv[]){
+  msg_task_t task = NULL;
+  _XBT_GNUC_UNUSED int res;
+  int i;
+  for (i=0; i<3;i++) {
+    res = MSG_task_receive(&(task), mailbox);
+    int pid = *((int*)MSG_task_get_data(task));
+    XBT_INFO("Killing process \"%d\".", pid);
+    MSG_process_kill(MSG_process_from_PID(pid));
+    task = NULL;
+  }
+}
+
+/** Main function */
+int main(int argc, char *argv[])
+{
+  msg_error_t res = MSG_OK;
+
+  MSG_init(&argc, argv);
+
+  /*   Application deployment */
+  MSG_function_register("sendpid", &sendpid);
+  MSG_function_register("killall", &killall);
+
+  MSG_process_killall(atoi(argv[2]));
+
+  MSG_create_environment(argv[1]);
+  MSG_launch_application(argv[1]);
+  res = MSG_main();
+
+  if (res == MSG_OK)
+    return 0;
+  else
+    return 1;
+}
diff --git a/teshsuite/msg/pid.tesh b/teshsuite/msg/pid.tesh
new file mode 100644 (file)
index 0000000..c91fedf
--- /dev/null
@@ -0,0 +1,28 @@
+! output sort
+$ msg/pid ${srcdir:=.}/msg/pid.xml 0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:sendpid@toto) Sending pid of "1".
+> [  0.000000] (2:sendpid@toto) Sending pid of "2".
+> [  0.000000] (3:sendpid@toto) Sending pid of "3".
+> [  0.001082] (4:killall@toto) Killing process "1".
+> [  0.001082] (1:sendpid@toto) Send of pid "1" done.
+> [  0.001082] (1:sendpid@toto) Process "1" killed.
+> [  0.002165] (2:sendpid@toto) Send of pid "2" done.
+> [  0.002165] (4:killall@toto) Killing process "2".
+> [  0.002165] (2:sendpid@toto) Process "2" killed.
+> [  0.003247] (3:sendpid@toto) Send of pid "3" done.
+> [  0.003247] (4:killall@toto) Killing process "3".
+> [  0.003247] (3:sendpid@toto) Process "3" killed.
+
+$ msg/pid ${srcdir:=.}/msg/pid.xml 2 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (10:sendpid@toto) Sending pid of "2".
+> [  0.000000] (11:sendpid@toto) Sending pid of "3".
+> [  0.000000] (12:sendpid@toto) Sending pid of "4".
+> [  0.001082] (13:killall@toto) Killing process "2".
+> [  0.001082] (1:sendpid@toto) Send of pid "2" done.
+> [  0.001082] (1:sendpid@toto) Process "2" killed.
+> [  0.002165] (2:sendpid@toto) Send of pid "3" done.
+> [  0.002165] (4:killall@toto) Killing process "3".
+> [  0.002165] (2:sendpid@toto) Process "3" killed.
+> [  0.003247] (3:sendpid@toto) Send of pid "4" done.
+> [  0.003247] (4:killall@toto) Killing process "4".
+> [  0.003247] (3:sendpid@toto) Process "4" killed.
diff --git a/teshsuite/msg/pid.xml b/teshsuite/msg/pid.xml
new file mode 100644 (file)
index 0000000..8b7d1d8
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version='1.0'?>
+ <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+ <platform version="3">
+   <!-- Platform -->
+ <AS  id="AS0"  routing="Full">
+   <host id="toto" power="1000000"/>
+   <link id="lb" bandwidth="100000000" latency="0.000000"/>
+   <route src="toto" dst="toto"><link_ctn id="lb"/></route>    
+  </AS>  
+   
+   <!-- Deployment -->
+   <process host="toto" function="sendpid"/>
+   <process host="toto" function="sendpid"/>
+   <process host="toto" function="sendpid"/>
+   <process host="toto" function="killall"/>
+
+ </platform>