From 6ae0b46319f23797ae320fa36ca7b6f7cbb891ed Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 7 Aug 2014 11:10:35 +0200 Subject: [PATCH 1/1] add an example about the remote exception throwing (still not working entierely) --- buildtools/Cmake/DefinePackages.cmake | 1 + buildtools/Cmake/MakeExe.cmake | 1 + examples/msg/exception/CMakeLists.txt | 32 +++++ .../msg/exception/deployment_exception.xml | 5 + examples/msg/exception/exception.c | 125 ++++++++++++++++++ examples/msg/exception/exception.tesh | 6 + 6 files changed, 170 insertions(+) create mode 100644 examples/msg/exception/CMakeLists.txt create mode 100644 examples/msg/exception/deployment_exception.xml create mode 100644 examples/msg/exception/exception.c create mode 100644 examples/msg/exception/exception.tesh diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 0c18d61a27..fca1fb251f 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -994,6 +994,7 @@ set(EXAMPLES_CMAKEFILES_TXT examples/msg/energy/e1/CMakeLists.txt examples/msg/energy/e2/CMakeLists.txt examples/msg/energy/e3/CMakeLists.txt + examples/msg/exception/CMakeLists.txt examples/msg/gpu/CMakeLists.txt examples/msg/gtnets/CMakeLists.txt examples/msg/icomms/CMakeLists.txt diff --git a/buildtools/Cmake/MakeExe.cmake b/buildtools/Cmake/MakeExe.cmake index 60b58fb79a..27061c8ba9 100644 --- a/buildtools/Cmake/MakeExe.cmake +++ b/buildtools/Cmake/MakeExe.cmake @@ -36,6 +36,7 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/cloud) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e1) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e2) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/energy/e3) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/exception) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/gpu) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/gtnets) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/icomms) diff --git a/examples/msg/exception/CMakeLists.txt b/examples/msg/exception/CMakeLists.txt new file mode 100644 index 0000000000..53ba5786a5 --- /dev/null +++ b/examples/msg/exception/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 2.6) + +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(exception exception.c) + +### Add definitions for compile +target_link_libraries(exception simgrid) + +set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/exception.tesh + PARENT_SCOPE + ) +set(examples_src + ${examples_src} + ${CMAKE_CURRENT_SOURCE_DIR}/exception.c + PARENT_SCOPE + ) +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/deployment_exception.xml + PARENT_SCOPE + ) +set(bin_files + ${bin_files} + PARENT_SCOPE + ) +set(txt_files + ${txt_files} + PARENT_SCOPE + ) diff --git a/examples/msg/exception/deployment_exception.xml b/examples/msg/exception/deployment_exception.xml new file mode 100644 index 0000000000..26b035dfb9 --- /dev/null +++ b/examples/msg/exception/deployment_exception.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/examples/msg/exception/exception.c b/examples/msg/exception/exception.c new file mode 100644 index 0000000000..a4f6b6e21a --- /dev/null +++ b/examples/msg/exception/exception.c @@ -0,0 +1,125 @@ +/* Copyright (c) 2007, 2009-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 "msg/msg.h" +#include "xbt.h" + +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test_exception, + "Messages specific for this msg example"); + +/** @addtogroup MSG_examples + * + * - exception/exception.c: Demonstrates how to send an exception to a remote guy + */ + +/** Victim. This process gets a lot of remote exceptions */ +static int victim(int argc, char *argv[]) { + + xbt_ex_t e; + XBT_INFO("Let's get suspended."); + TRY { + MSG_process_suspend(MSG_process_self()); + } CATCH(e) { + XBT_INFO("The received exception resumed my execution. Good. Here is it: ----------------------->8----"); + xbt_ex_display(&e); + XBT_INFO("(end of the first exception) ----8<------------------------"); + xbt_ex_free(e); + } + + msg_error_t res; + int gotit = 0; + XBT_INFO("Let's sleep for 10 seconds."); + TRY { + res = MSG_process_sleep(10); + } CATCH(e) { + XBT_INFO("Got the second exception: ----------------------->8----"); + xbt_ex_display(&e); + XBT_INFO("(end of the second exception) ----8<------------------------"); + xbt_ex_free(e); + } + + if (res != MSG_TASK_CANCELED) + xbt_die("Sleep action not canceled through the exception. This is not a method. (retval: %d)",res); + if (!gotit) + xbt_die("I was expecting to get an exception during my nap."); + XBT_INFO("My little nap got canceled through a raw exception. Excellent."); + + XBT_INFO("That's enough now. I quit."); + return 0; +} + +/** Terrorist. This process sends a bunch of exceptions to the victim. */ +static int terrorist(int argc, char *argv[]) +{ + msg_process_t victim_process = NULL; + + XBT_INFO("Let's create a victim."); + victim_process = MSG_process_create("victim", victim, NULL, MSG_host_self()); + if (MSG_process_sleep(1) != MSG_OK) + xbt_die("What's going on??? I failed to sleep!"); + XBT_INFO("Send a first exception (host failure)"); + SIMIX_process_throw(victim_process, host_error, 0, "Let's pretend that the host failed"); + + if (MSG_process_sleep(3) != MSG_OK) + xbt_die("What's going on??? I failed to sleep!"); + XBT_INFO("Send a second exception (cancellation)"); + SIMIX_process_throw(victim_process, cancel_error, 0, "Let's pretend this time that someone canceled something"); + + XBT_INFO("OK, goodbye now."); + return 0; +} + +int main(int argc, char *argv[]) { + msg_error_t res = MSG_OK; + + MSG_init(&argc, argv); + if (argc < 3) { + XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]); + exit(1); + } + + MSG_function_register("terrorist", terrorist); + MSG_create_environment(argv[1]); + MSG_launch_application(argv[2]); + + /* + // Simplistic platform with only one host + sg_platf_begin(); + s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER; + sg_platf_new_AS_begin(&AS); + + s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER; + host.id = "host0"; + sg_platf_new_host(&host); + + sg_platf_new_AS_end(); + sg_platf_end(); + + // Add one process -- super heavy just to launch an application! + SIMIX_init_application(); + sg_platf_begin(); + + s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER; + process.argc=1; + process.argv = malloc(sizeof(char*)*2); + process.argv[0] = "terrorist"; + process.argv[1] = NULL; + process.host = "host0"; + process.function = "terrorist"; + process.start_time = 0; + sg_platf_new_process(&process); + sg_platf_end(); +*/ + + // Launch the simulation + res = MSG_main(); + + XBT_INFO("Simulation time %g", MSG_get_clock()); + if (res == MSG_OK) + return 0; + else + return 1; +} diff --git a/examples/msg/exception/exception.tesh b/examples/msg/exception/exception.tesh new file mode 100644 index 0000000000..cf8cdb2819 --- /dev/null +++ b/examples/msg/exception/exception.tesh @@ -0,0 +1,6 @@ +#! ./tesh + +p Testing the remote exception raising feature + +! output sort +$ $SG_TEST_EXENV exception/exception ${srcdir:=.}/../platforms/platform.xml ${srcdir:=.}/exception/deployment_exception.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -- 2.20.1