From 06ee15f57336cd94ef7be68947df842dbce28675 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Wed, 30 Jan 2013 11:27:42 +0100 Subject: [PATCH] Add test for msg pid --- buildtools/Cmake/AddTests.cmake | 9 +++++ teshsuite/msg/CMakeLists.txt | 8 +++- teshsuite/msg/pid.c | 65 +++++++++++++++++++++++++++++++++ teshsuite/msg/pid.tesh | 28 ++++++++++++++ teshsuite/msg/pid.xml | 17 +++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 teshsuite/msg/pid.c create mode 100644 teshsuite/msg/pid.tesh create mode 100644 teshsuite/msg/pid.xml diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 7e59b1bb55..25c58ca4ec 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -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() diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 4f22b3c611..eeb9d84b80 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -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 index 0000000000..1f04fb2a54 --- /dev/null +++ b/teshsuite/msg/pid.c @@ -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 index 0000000000..c91fedf15d --- /dev/null +++ b/teshsuite/msg/pid.tesh @@ -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 index 0000000000..8b7d1d83e4 --- /dev/null +++ b/teshsuite/msg/pid.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + -- 2.20.1