From: Paul Bédaride Date: Tue, 4 Mar 2014 16:17:21 +0000 (+0100) Subject: Add msg host on/off test X-Git-Tag: v3_11~242^2~21 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/39714a9316cb8b1b86982600d4b1c8e034c82e7f Add msg host on/off test --- diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index aa7a9b2e3a..cc1ceb5ba7 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -110,6 +110,15 @@ if(NOT enable_memcheck) ADD_TEST(tesh-msg-pid-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/pid.tesh) endif() + ADD_TEST(tesh-msg-host-on-off-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/host_on_off.tesh) + if(HAVE_RAWCTX) + ADD_TEST(tesh-msg-host-on-off-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/host_on_off.tesh) + endif() + if(CONTEXT_UCONTEXT) + 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() + + # 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_host.c b/src/simix/smx_host.c index 2f88f82313..80c5d6c269 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -103,8 +103,8 @@ void SIMIX_host_off(smx_host_t h, smx_process_t issuer) xbt_assert((host != NULL), "Invalid parameters"); - if (surf_resource_get_state(surf_workstation_resource_priv(h))==SURF_RESOURCE_OFF) { - surf_resource_set_state(surf_workstation_resource_priv(h), SURF_RESOURCE_ON); + if (surf_resource_get_state(surf_workstation_resource_priv(h))==SURF_RESOURCE_ON) { + surf_resource_set_state(surf_workstation_resource_priv(h), SURF_RESOURCE_OFF); /* Clean Simulator data */ if (xbt_swag_size(host->process_list) != 0) { diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 065b8f68f1..ec4f4f1b96 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -4,13 +4,15 @@ 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_executable(host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.c) + ### Add definitions for compile +target_link_libraries(get_sender simgrid) +target_link_libraries(host_on_off simgrid) if(NOT WIN32) - 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() @@ -18,6 +20,7 @@ set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.tesh ${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh + ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh PARENT_SCOPE ) set(xml_files @@ -26,12 +29,14 @@ set(xml_files ${CMAKE_CURRENT_SOURCE_DIR}/get_sender_p.xml ${CMAKE_CURRENT_SOURCE_DIR}/pid_d.xml ${CMAKE_CURRENT_SOURCE_DIR}/pid_p.xml + ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.xml PARENT_SCOPE ) set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/get_sender.c ${CMAKE_CURRENT_SOURCE_DIR}/pid.c + ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c PARENT_SCOPE ) set(bin_files diff --git a/teshsuite/msg/host_on_off.c b/teshsuite/msg/host_on_off.c new file mode 100644 index 0000000000..a26d7e07c9 --- /dev/null +++ b/teshsuite/msg/host_on_off.c @@ -0,0 +1,128 @@ +/* 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[]) +{ + double task_comp_size = 5E7; + double task_comm_size = 1E6; + + char mailbox[256]; + msg_task_t task = NULL; + + sprintf(mailbox, "jupi"); + + task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL); + XBT_INFO("Sending \"%s\"", task->name); + MSG_task_send_with_timeout(task, mailbox, 1); + + MSG_process_sleep(1); + MSG_host_off(MSG_get_host_by_name("Jupiter")); + + task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL); + XBT_INFO("Sending \"%s\"", task->name); + MSG_task_send_with_timeout(task, mailbox, 1); + + MSG_host_on(MSG_get_host_by_name("Jupiter")); + + task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL); + XBT_INFO("Sending \"%s\"", task->name); + MSG_task_send_with_timeout(task, mailbox, 1); + + char **argvF = xbt_new(char*, 2); + argvF[0] = xbt_strdup("slave"); + MSG_process_create_with_arguments("slave", slave, NULL, MSG_get_host_by_name("Jupiter"), 1, argvF); + + task = MSG_task_create("task on with proc", task_comp_size, task_comm_size, NULL); + XBT_INFO("Sending \"%s\"", task->name); + MSG_task_send_with_timeout(task, mailbox, 1); + + task = MSG_task_create("finalize", 0, 0, 0); + XBT_INFO("Sending \"%s\"", task->name); + MSG_task_send_with_timeout(task, mailbox, 1); + + XBT_INFO("Goodbye now!"); + return 0; +} /* end_of_master */ + +/** Receiver function */ +int slave(int argc, char *argv[]) +{ + msg_task_t task = NULL; + _XBT_GNUC_UNUSED int res; + int id = -1; + char mailbox[80]; + _XBT_GNUC_UNUSED int read; + + sprintf(mailbox, "jupi"); + + while (1) { + res = MSG_task_receive(&(task), mailbox); + xbt_assert(res == MSG_OK, "MSG_task_get failed"); + + if (!strcmp(MSG_task_get_name(task), "finalize")) { + MSG_task_destroy(task); + break; + } + MSG_task_execute(task); + XBT_INFO("Task \"%s\" done", MSG_task_get_name(task)); + + MSG_task_destroy(task); + task = NULL; + id--; + } + 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/host_on_off.tesh b/teshsuite/msg/host_on_off.tesh new file mode 100644 index 0000000000..403d26d7de --- /dev/null +++ b/teshsuite/msg/host_on_off.tesh @@ -0,0 +1,12 @@ + +$ msg/host_on_off ${srcdir:=.}/msg/host_on_off.xml +> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Sending "task on" +> [Jupiter:slave:(2) 0.682345] [msg_test/INFO] Task "task on" done +> [Tremblay:master:(1) 1.027003] [msg_test/INFO] Sending "task off" +> [Tremblay:master:(1) 2.027003] [msg_test/INFO] Sending "task on without proc" +> [Tremblay:master:(1) 3.027003] [msg_test/INFO] Sending "task on with proc" +> [Tremblay:master:(1) 3.054005] [msg_test/INFO] Sending "finalize" +> [Jupiter:slave:(3) 3.709348] [msg_test/INFO] Task "task on with proc" done +> [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/host_on_off.xml b/teshsuite/msg/host_on_off.xml new file mode 100644 index 0000000000..d57e0f384a --- /dev/null +++ b/teshsuite/msg/host_on_off.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file