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()
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
${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
--- /dev/null
+/* 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;
+}
--- /dev/null
+! 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.
--- /dev/null
+<?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>