From 47fb968673db55fee5ab9b7d5dcf395fd47118f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Fri, 7 Mar 2014 10:30:17 +0100 Subject: [PATCH] Add msg process test and fix ppid of created processes --- buildtools/Cmake/AddTests.cmake | 10 +++- src/simix/smx_process.c | 30 ++++++++-- src/simix/smx_process_private.h | 10 ++++ teshsuite/msg/CMakeLists.txt | 5 ++ teshsuite/msg/host_on_off.tesh | 1 + teshsuite/msg/process.c | 103 ++++++++++++++++++++++++++++++++ teshsuite/msg/process.tesh | 17 ++++++ teshsuite/msg/process.xml | 16 +++++ 8 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 teshsuite/msg/process.c create mode 100644 teshsuite/msg/process.tesh create mode 100644 teshsuite/msg/process.xml diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 8e85c1623a..1d6641a11a 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -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) diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index b71da54ff0..1444dc0119 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -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) diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index ac0126e158..0d2494369e 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -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); diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 1656f25981..983748ba10 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -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 diff --git a/teshsuite/msg/host_on_off.tesh b/teshsuite/msg/host_on_off.tesh index 7b613bcdcc..2e3e45664d 100644 --- a/teshsuite/msg/host_on_off.tesh +++ b/teshsuite/msg/host_on_off.tesh @@ -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 index 0000000000..e01112b5f7 --- /dev/null +++ b/teshsuite/msg/process.c @@ -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 +#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 index 0000000000..90a2575166 --- /dev/null +++ b/teshsuite/msg/process.tesh @@ -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 index 0000000000..f0c3dae669 --- /dev/null +++ b/teshsuite/msg/process.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.20.1