From: Gabriel Corona Date: Mon, 6 Jul 2015 14:21:17 +0000 (+0200) Subject: host-on-off: add basic tests X-Git-Tag: v3_12~536 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5ded2071c37dc28669c79ff593159aea355b2538 host-on-off: add basic tests --- diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 651c73feb9..25c59bb54b 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -197,6 +197,8 @@ IF(NOT enable_memcheck) # BEGIN TESH TESTS ADD_TESH_FACTORIES(tesh-msg-get-sender "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/get_sender --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/get_sender ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/get_sender/get_sender.tesh) ADD_TESH_FACTORIES(tesh-msg-host-on-off "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off/host_on_off.tesh) + ADD_TESH_FACTORIES(tesh-msg-host-on-off-wait "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off/host_on_off_wait.tesh) + ADD_TESH_FACTORIES(tesh-msg-host-on-off-recv "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off/host_on_off_recv.tesh) ADD_TESH_FACTORIES(tesh-msg-host-on-off-processes "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off_processes --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/host_on_off_processes ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off_processes/host_on_off_processes.tesh) ADD_TESH_FACTORIES(tesh-msg-pid "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/pid ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid/pid.tesh) ADD_TESH_FACTORIES(tesh-msg-process "thread;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/process ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process/process.tesh) diff --git a/src/msg/msg_gos.c b/src/msg/msg_gos.c index 4aa46346da..11218c98b1 100644 --- a/src/msg/msg_gos.c +++ b/src/msg/msg_gos.c @@ -338,9 +338,6 @@ MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout, } CATCH(e) { switch (e.category) { - case host_error: - ret = MSG_HOST_FAILURE; - break; case cancel_error: /* may be thrown by MSG_mailbox_get_by_alias */ ret = MSG_HOST_FAILURE; break; diff --git a/teshsuite/msg/host_on_off/CMakeLists.txt b/teshsuite/msg/host_on_off/CMakeLists.txt index 7f9719cdb7..ca555f81a8 100644 --- a/teshsuite/msg/host_on_off/CMakeLists.txt +++ b/teshsuite/msg/host_on_off/CMakeLists.txt @@ -2,16 +2,16 @@ cmake_minimum_required(VERSION 2.6) set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") -add_executable(host_on_off host_on_off.c) +foreach(x host_on_off host_on_off_wait host_on_off_recv) + add_executable(${x} ${x}.c) + target_link_libraries(${x} simgrid) + set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/${x}.tesh + PARENT_SCOPE + ) +endforeach() -### Add definitions for compile -target_link_libraries(host_on_off simgrid) - -set(tesh_files - ${tesh_files} - ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh - PARENT_SCOPE - ) set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off_d.xml @@ -20,6 +20,7 @@ set(xml_files set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c + ${CMAKE_CURRENT_SOURCE_DIR}/host_on_off_simple.c PARENT_SCOPE ) set(bin_files diff --git a/teshsuite/msg/host_on_off/host_on_off_recv.c b/teshsuite/msg/host_on_off/host_on_off_recv.c new file mode 100644 index 0000000000..4d89997dd7 --- /dev/null +++ b/teshsuite/msg/host_on_off/host_on_off_recv.c @@ -0,0 +1,115 @@ +/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ +#include "xbt/ex.h" + +/* 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[]); + +static const char* mailbox = "comm"; + +/** Emitter function */ +int master(int argc, char *argv[]) +{ + xbt_ex_t e; + TRY { + msg_host_t jupiter = MSG_get_host_by_name("Jupiter"); + + XBT_INFO("Master starting"); + MSG_process_sleep(0.5); + + msg_comm_t comm = NULL; + if (1) { + msg_task_t task = MSG_task_create("COMM", 0, 100000000, NULL); + comm = MSG_task_isend(task, mailbox); + } + + if(MSG_process_sleep(0.5)) { + XBT_ERROR("Unexpected error while sleeping"); + return 1; + } + XBT_INFO("Turning off the slave host"); + MSG_host_off(jupiter); + + if (comm) { + MSG_comm_wait(comm, -1); + } + XBT_INFO("Master has finished"); + } + CATCH(e) { + xbt_die("Exception caught in the master"); + return 1; + } + return 0; +} + +/** Receiver function */ +int slave(int argc, char *argv[]) +{ + xbt_ex_t e; + TRY { + XBT_INFO("Slave receiving"); + msg_task_t task = NULL; + msg_error_t error = MSG_task_receive(&(task), mailbox); + if (error) { + XBT_ERROR("Error while receiving message"); + return 1; + } + + XBT_ERROR("Slave should be off already."); + return 1; + } + CATCH(e) { + XBT_ERROR("Exception caught in the slave"); + return 1; + } + return 0; +} + +/** 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 != 3) { + 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[2]; + + /* 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/host_on_off_recv.tesh b/teshsuite/msg/host_on_off/host_on_off_recv.tesh new file mode 100644 index 0000000000..782ee41518 --- /dev/null +++ b/teshsuite/msg/host_on_off/host_on_off_recv.tesh @@ -0,0 +1,6 @@ +$ ./host_on_off_recv ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_d.xml +> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Master starting +> [Jupiter:slave:(2) 0.000000] [msg_test/INFO] Slave receiving +> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Turning off the slave host +> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Master has finished +> [1.000000] [msg_test/INFO] Simulation time 1 diff --git a/teshsuite/msg/host_on_off/host_on_off_wait.c b/teshsuite/msg/host_on_off/host_on_off_wait.c new file mode 100644 index 0000000000..2cb7cd7b83 --- /dev/null +++ b/teshsuite/msg/host_on_off/host_on_off_wait.c @@ -0,0 +1,96 @@ +/* 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 "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ +#include "xbt/sysdep.h" /* calloc, printf */ +#include "xbt/ex.h" + +/* 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_ex_t e; + TRY { + msg_host_t jupiter = MSG_get_host_by_name("Jupiter"); + XBT_INFO("Master waiting"); + if(MSG_process_sleep(1)) { + XBT_ERROR("Unexpected error while sleeping"); + return 1; + } + + XBT_INFO("Turning off the slave host"); + MSG_host_off(jupiter); + XBT_INFO("Master has finished"); + } + CATCH(e) { + xbt_die("Exception caught in the master"); + return 1; + } + return 0; +} + +/** Receiver function */ +int slave(int argc, char *argv[]) +{ + xbt_ex_t e; + TRY { + XBT_INFO("Slave waiting"); + // TODO, This should really be MSG_HOST_FAILURE + MSG_process_sleep(5); + XBT_ERROR("Slave should be off already."); + return 1; + } + CATCH(e) { + XBT_ERROR("Exception caught in the slave"); + return 1; + } + return 0; +} + +/** 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 != 3) { + 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[2]; + + /* 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/host_on_off_wait.tesh b/teshsuite/msg/host_on_off/host_on_off_wait.tesh new file mode 100644 index 0000000000..4071020e3e --- /dev/null +++ b/teshsuite/msg/host_on_off/host_on_off_wait.tesh @@ -0,0 +1,6 @@ +$ ./host_on_off_wait ${srcdir:=.}/../../../examples/platforms/small_platform.xml ${srcdir:=.}/host_on_off_d.xml +> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Master waiting +> [Jupiter:slave:(2) 0.000000] [msg_test/INFO] Slave waiting +> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Turning off the slave host +> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Master has finished +> [1.000000] [msg_test/INFO] Simulation time 1