From: Martin Quinson Date: Wed, 3 Feb 2016 07:35:47 +0000 (+0100) Subject: Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid X-Git-Tag: v3_13~993 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/83eac0d2fba299311b07779b4de686124ce0905b?hp=44192e0a7b9e976594fffe3b0af441a8054e69c5 Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid --- diff --git a/examples/msg/actions/actions.c b/examples/msg/actions/actions.c index bd5a62aa27..e43c1d45f5 100644 --- a/examples/msg/actions/actions.c +++ b/examples/msg/actions/actions.c @@ -230,8 +230,8 @@ static void action_barrier(const char *const *action) processes_arrived_sofar--; if (!processes_arrived_sofar) { - simcall_cond_destroy(cond); - simcall_mutex_destroy(mutex); + SIMIX_cond_destroy(cond); + SIMIX_mutex_destroy(mutex); mutex = NULL; } } diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index d931d13084..bd12391e93 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -410,13 +410,13 @@ XBT_PUBLIC(void) simcall_set_category(smx_synchro_t synchro, const char *categor /************************** Synchro simcalls **********************************/ XBT_PUBLIC(smx_mutex_t) simcall_mutex_init(void); -XBT_PUBLIC(void) simcall_mutex_destroy(smx_mutex_t mutex); +XBT_PUBLIC(void) SIMIX_mutex_destroy(smx_mutex_t mutex); XBT_PUBLIC(void) simcall_mutex_lock(smx_mutex_t mutex); XBT_PUBLIC(int) simcall_mutex_trylock(smx_mutex_t mutex); XBT_PUBLIC(void) simcall_mutex_unlock(smx_mutex_t mutex); XBT_PUBLIC(smx_cond_t) simcall_cond_init(void); -XBT_PUBLIC(void) simcall_cond_destroy(smx_cond_t cond); +XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond); XBT_PUBLIC(void) simcall_cond_signal(smx_cond_t cond); XBT_PUBLIC(void) simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex); XBT_PUBLIC(void) simcall_cond_wait_timeout(smx_cond_t cond, @@ -425,7 +425,7 @@ XBT_PUBLIC(void) simcall_cond_wait_timeout(smx_cond_t cond, XBT_PUBLIC(void) simcall_cond_broadcast(smx_cond_t cond); XBT_PUBLIC(smx_sem_t) simcall_sem_init(int capacity); -XBT_PUBLIC(void) simcall_sem_destroy(smx_sem_t sem); +XBT_PUBLIC(void) SIMIX_sem_destroy(smx_sem_t sem); XBT_PUBLIC(void) simcall_sem_release(smx_sem_t sem); XBT_PUBLIC(int) simcall_sem_would_block(smx_sem_t sem); XBT_PUBLIC(void) simcall_sem_acquire(smx_sem_t sem); diff --git a/src/msg/msg_synchro.cpp b/src/msg/msg_synchro.cpp index 70f13837fc..6547de0507 100644 --- a/src/msg/msg_synchro.cpp +++ b/src/msg/msg_synchro.cpp @@ -54,7 +54,7 @@ void MSG_sem_get_capacity(msg_sem_t sem) { } void MSG_sem_destroy(msg_sem_t sem) { - simcall_sem_destroy(sem); + SIMIX_sem_destroy(sem); } /** @brief returns a boolean indicating if this semaphore would block at this very specific time * diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index baa00625bf..901f49fff8 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -1031,15 +1031,6 @@ smx_mutex_t simcall_mutex_init(void) return simcall_BODY_mutex_init(); } -/** - * \ingroup simix_synchro_management - * - */ -void simcall_mutex_destroy(smx_mutex_t mutex) -{ - simcall_BODY_mutex_destroy(mutex); -} - /** * \ingroup simix_synchro_management * @@ -1076,15 +1067,6 @@ smx_cond_t simcall_cond_init(void) return simcall_BODY_cond_init(); } -/** - * \ingroup simix_synchro_management - * - */ -void simcall_cond_destroy(smx_cond_t cond) -{ - simcall_BODY_cond_destroy(cond); -} - /** * \ingroup simix_synchro_management * @@ -1133,15 +1115,6 @@ smx_sem_t simcall_sem_init(int capacity) return simcall_BODY_sem_init(capacity); } -/** - * \ingroup simix_synchro_management - * - */ -void simcall_sem_destroy(smx_sem_t sem) -{ - simcall_BODY_sem_destroy(sem); -} - /** * \ingroup simix_synchro_management * diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 981ded3bd8..cdd7775335 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -941,13 +941,6 @@ static inline void simcall_mutex_init__set__result(smx_simcall_t simcall, void* simcall->result.dp = result; } -static inline smx_mutex_t simcall_mutex_destroy__get__mutex(smx_simcall_t simcall) { - return (smx_mutex_t) simcall->args[0].dp; -} -static inline void simcall_mutex_destroy__set__mutex(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline smx_mutex_t simcall_mutex_lock__get__mutex(smx_simcall_t simcall) { return (smx_mutex_t) simcall->args[0].dp; } @@ -982,13 +975,6 @@ static inline void simcall_cond_init__set__result(smx_simcall_t simcall, void* r simcall->result.dp = result; } -static inline smx_cond_t simcall_cond_destroy__get__cond(smx_simcall_t simcall) { - return (smx_cond_t) simcall->args[0].dp; -} -static inline void simcall_cond_destroy__set__cond(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline smx_cond_t simcall_cond_signal__get__cond(smx_simcall_t simcall) { return (smx_cond_t) simcall->args[0].dp; } @@ -1048,13 +1034,6 @@ static inline void simcall_sem_init__set__result(smx_simcall_t simcall, void* re simcall->result.dp = result; } -static inline smx_sem_t simcall_sem_destroy__get__sem(smx_simcall_t simcall) { - return (smx_sem_t) simcall->args[0].dp; -} -static inline void simcall_sem_destroy__set__sem(smx_simcall_t simcall, void* arg) { - simcall->args[0].dp = arg; -} - static inline smx_sem_t simcall_sem_release__get__sem(smx_simcall_t simcall) { return (smx_sem_t) simcall->args[0].dp; } diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index b6c206aa53..8f7a88037f 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -1158,27 +1158,6 @@ inline static smx_mutex_t simcall_BODY_mutex_init() { return (smx_mutex_t) self->simcall.result.dp; } -inline static void simcall_BODY_mutex_destroy(smx_mutex_t mutex) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_mutex_destroy(mutex); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_MUTEX_DESTROY; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) mutex; - if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, - SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); - SIMIX_process_yield(self); - } else { - SIMIX_simcall_handle(&self->simcall, 0); - } - - } - inline static void simcall_BODY_mutex_lock(smx_mutex_t mutex) { smx_process_t self = SIMIX_process_self(); @@ -1263,27 +1242,6 @@ inline static smx_cond_t simcall_BODY_cond_init() { return (smx_cond_t) self->simcall.result.dp; } -inline static void simcall_BODY_cond_destroy(smx_cond_t cond) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_cond_destroy(cond); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_COND_DESTROY; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) cond; - if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, - SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); - SIMIX_process_yield(self); - } else { - SIMIX_simcall_handle(&self->simcall, 0); - } - - } - inline static void simcall_BODY_cond_signal(smx_cond_t cond) { smx_process_t self = SIMIX_process_self(); @@ -1392,27 +1350,6 @@ inline static smx_sem_t simcall_BODY_sem_init(unsigned int capacity) { return (smx_sem_t) self->simcall.result.dp; } -inline static void simcall_BODY_sem_destroy(smx_sem_t sem) { - smx_process_t self = SIMIX_process_self(); - - /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_sem_destroy(sem); - /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ - - self->simcall.call = SIMCALL_SEM_DESTROY; - memset(&self->simcall.result, 0, sizeof(self->simcall.result)); - memset(self->simcall.args, 0, sizeof(self->simcall.args)); - self->simcall.args[0].dp = (void*) sem; - if (self != simix_global->maestro_process) { - XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, - SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); - SIMIX_process_yield(self); - } else { - SIMIX_simcall_handle(&self->simcall, 0); - } - - } - inline static void simcall_BODY_sem_release(smx_sem_t sem) { smx_process_t self = SIMIX_process_self(); diff --git a/src/simix/popping_enum.h b/src/simix/popping_enum.h index 9c0b346bcc..a523f45b11 100644 --- a/src/simix/popping_enum.h +++ b/src/simix/popping_enum.h @@ -69,18 +69,15 @@ typedef enum { SIMCALL_COMM_GET_SRC_PROC, SIMCALL_COMM_GET_DST_PROC, SIMCALL_MUTEX_INIT, - SIMCALL_MUTEX_DESTROY, SIMCALL_MUTEX_LOCK, SIMCALL_MUTEX_TRYLOCK, SIMCALL_MUTEX_UNLOCK, SIMCALL_COND_INIT, - SIMCALL_COND_DESTROY, SIMCALL_COND_SIGNAL, SIMCALL_COND_WAIT, SIMCALL_COND_WAIT_TIMEOUT, SIMCALL_COND_BROADCAST, SIMCALL_SEM_INIT, - SIMCALL_SEM_DESTROY, SIMCALL_SEM_RELEASE, SIMCALL_SEM_WOULD_BLOCK, SIMCALL_SEM_ACQUIRE, diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 9b9b802fd5..418256ce99 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -74,18 +74,15 @@ const char* simcall_names[] = { "SIMCALL_COMM_GET_SRC_PROC", "SIMCALL_COMM_GET_DST_PROC", "SIMCALL_MUTEX_INIT", - "SIMCALL_MUTEX_DESTROY", "SIMCALL_MUTEX_LOCK", "SIMCALL_MUTEX_TRYLOCK", "SIMCALL_MUTEX_UNLOCK", "SIMCALL_COND_INIT", - "SIMCALL_COND_DESTROY", "SIMCALL_COND_SIGNAL", "SIMCALL_COND_WAIT", "SIMCALL_COND_WAIT_TIMEOUT", "SIMCALL_COND_BROADCAST", "SIMCALL_SEM_INIT", - "SIMCALL_SEM_DESTROY", "SIMCALL_SEM_RELEASE", "SIMCALL_SEM_WOULD_BLOCK", "SIMCALL_SEM_ACQUIRE", @@ -375,11 +372,6 @@ case SIMCALL_MUTEX_INIT: SIMIX_simcall_answer(simcall); break; -case SIMCALL_MUTEX_DESTROY: - SIMIX_mutex_destroy((smx_mutex_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_MUTEX_LOCK: simcall_HANDLER_mutex_lock(simcall , (smx_mutex_t) simcall->args[0].dp); break; @@ -399,11 +391,6 @@ case SIMCALL_COND_INIT: SIMIX_simcall_answer(simcall); break; -case SIMCALL_COND_DESTROY: - SIMIX_cond_destroy((smx_cond_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_COND_SIGNAL: SIMIX_cond_signal((smx_cond_t) simcall->args[0].dp); SIMIX_simcall_answer(simcall); @@ -427,11 +414,6 @@ case SIMCALL_SEM_INIT: SIMIX_simcall_answer(simcall); break; -case SIMCALL_SEM_DESTROY: - SIMIX_sem_destroy((smx_sem_t) simcall->args[0].dp); - SIMIX_simcall_answer(simcall); - break; - case SIMCALL_SEM_RELEASE: simcall_HANDLER_sem_release(simcall , (smx_sem_t) simcall->args[0].dp); SIMIX_simcall_answer(simcall); diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 60b8c72de7..43299df5f8 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -103,20 +103,17 @@ Func - comm_get_src_proc (void*, smx_process_t) (comm, void*, smx_synchro_t) Func - comm_get_dst_proc (void*, smx_process_t) (comm, void*, smx_synchro_t) Func H mutex_init (void*, smx_mutex_t) -Proc - mutex_destroy (void) (mutex, void*, smx_mutex_t) Blck H mutex_lock (void) (mutex, void*, smx_mutex_t) Func H mutex_trylock (int) (mutex, void*, smx_mutex_t) Proc H mutex_unlock (void) (mutex, void*, smx_mutex_t) Func - cond_init (void*, smx_cond_t) -Proc - cond_destroy (void) (cond, void*, smx_cond_t) Proc - cond_signal (void) (cond, void*, smx_cond_t) Blck H cond_wait (void) (cond, void*, smx_cond_t) (mutex, void*, smx_mutex_t) Blck H cond_wait_timeout (void) (cond, void*, smx_cond_t) (mutex, void*, smx_mutex_t) (timeout, double) Proc - cond_broadcast (void) (cond, void*, smx_cond_t) Func - sem_init (void*, smx_sem_t) (capacity, unsigned int) -Proc - sem_destroy (void) (sem, void*, smx_sem_t) Proc H sem_release (void) (sem, void*, smx_sem_t) Func H sem_would_block (int) (sem, void*, smx_sem_t) Blck H sem_acquire (void) (sem, void*, smx_sem_t) diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index 6078923989..9ced079ade 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -155,7 +155,6 @@ void SIMIX_create_maestro_process() maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro); maestro->simcall.issuer = maestro; simix_global->maestro_process = maestro; - return; } /** * \brief Stops a process. diff --git a/src/simix/smx_synchro_private.h b/src/simix/smx_synchro_private.h index d6da8045f7..9cf259203a 100644 --- a/src/simix/smx_synchro_private.h +++ b/src/simix/smx_synchro_private.h @@ -32,16 +32,13 @@ XBT_PRIVATE void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t XBT_PRIVATE void SIMIX_synchro_destroy(smx_synchro_t synchro); XBT_PRIVATE smx_mutex_t SIMIX_mutex_init(void); -XBT_PRIVATE void SIMIX_mutex_destroy(smx_mutex_t mutex); XBT_PRIVATE int SIMIX_mutex_trylock(smx_mutex_t mutex, smx_process_t issuer); XBT_PRIVATE void SIMIX_mutex_unlock(smx_mutex_t mutex, smx_process_t issuer); XBT_PRIVATE smx_cond_t SIMIX_cond_init(void); -XBT_PRIVATE void SIMIX_cond_destroy(smx_cond_t cond); XBT_PRIVATE void SIMIX_cond_broadcast(smx_cond_t cond); XBT_PRIVATE void SIMIX_cond_signal(smx_cond_t cond); -XBT_PRIVATE void SIMIX_sem_destroy(smx_sem_t sem); XBT_PRIVATE XBT_PRIVATE smx_sem_t SIMIX_sem_init(unsigned int value); XBT_PRIVATE void SIMIX_sem_release(smx_sem_t sem); XBT_PRIVATE int SIMIX_sem_would_block(smx_sem_t sem); diff --git a/src/xbt/xbt_os_synchro.c b/src/xbt/xbt_os_synchro.c index db8e2acbde..fd52a4deae 100644 --- a/src/xbt/xbt_os_synchro.c +++ b/src/xbt/xbt_os_synchro.c @@ -45,7 +45,7 @@ void xbt_mutex_release(xbt_mutex_t mutex) void xbt_mutex_destroy(xbt_mutex_t mutex) { - simcall_mutex_destroy((smx_mutex_t) mutex); + SIMIX_mutex_destroy((smx_mutex_t) mutex); } /***** condition related functions *****/ @@ -80,7 +80,7 @@ void xbt_cond_broadcast(xbt_cond_t cond) void xbt_cond_destroy(xbt_cond_t cond) { - simcall_cond_destroy((smx_cond_t) cond); + SIMIX_cond_destroy((smx_cond_t) cond); } /***** barrier related functions *****/ diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index f7ed95eced..3ef350b355 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -291,14 +291,10 @@ void xbt_os_thread_exit(int *retval) xbt_os_thread_t xbt_os_thread_self(void) { - xbt_os_thread_t res; - if (!thread_mod_inited) return NULL; - res = pthread_getspecific(xbt_self_thread_key); - - return res; + return pthread_getspecific(xbt_self_thread_key); } void xbt_os_thread_key_create(xbt_os_thread_key_t* key) { @@ -1303,8 +1299,7 @@ void xbt_os_thread_set_extra_data(void *data) void *xbt_os_thread_get_extra_data(void) { - xbt_os_thread_t self = xbt_os_thread_self(); - return self? self->extra_data : NULL; + return xbt_os_thread_self()->extra_data; } xbt_os_rmutex_t xbt_os_rmutex_init(void) diff --git a/teshsuite/java/semaphore/CMakeLists.txt b/teshsuite/java/semaphore/CMakeLists.txt new file mode 100644 index 0000000000..e86706b7f8 --- /dev/null +++ b/teshsuite/java/semaphore/CMakeLists.txt @@ -0,0 +1,40 @@ +set(example java_semaphore_gc) +set(sources + ${CMAKE_CURRENT_SOURCE_DIR}/SemaphoreGC.java + ) + +if(enable_java) + add_custom_command( + COMMENT "Building ${example}..." + OUTPUT ${example}_compiled + DEPENDS ${sources} simgrid-java_jar ${SIMGRID_JAR} + COMMAND ${JAVA_COMPILE} -classpath ${SIMGRID_JAR} + -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources} + COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled + COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled + ) + add_custom_target(${example} ALL DEPENDS ${example}_compiled) +endif() + +set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/semaphore_gc.tesh + PARENT_SCOPE + ) +set(xml_files + ${xml_files} + PARENT_SCOPE + ) +set(examples_src + ${examples_src} + ${sources} + PARENT_SCOPE + ) +set(bin_files + ${bin_files} + PARENT_SCOPE + ) +set(txt_files + ${txt_files} + PARENT_SCOPE + ) diff --git a/teshsuite/java/semaphore/SemaphoreGC.java b/teshsuite/java/semaphore/SemaphoreGC.java new file mode 100644 index 0000000000..224108a3db --- /dev/null +++ b/teshsuite/java/semaphore/SemaphoreGC.java @@ -0,0 +1,56 @@ +/* Copyright (c) 2016. 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. */ + +/* This test ensures that the used semaphores are not garbage-collected while we still use it. + * This was reported as bug #... on gforge. + */ + +package semaphore; + +import org.simgrid.msg.*; +import org.simgrid.msg.Process; +import org.simgrid.trace.Trace; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +class SemCreator extends Process { + Semaphore sem; + + SemCreator(Host h, String n){ + super(h, n); + } + + public void main(String[] args) throws MsgException{ + int j; + Msg.info("Creating 150 new Semaphores, yielding and triggering a GC after each"); + for(j = 1; j <= 150; j++) { + sem = new Semaphore(0); + waitFor(10); + System.gc(); + } + Msg.info("It worked, we survived. The test is passed."); + } +} + + +public class SemaphoreGC { + public static void main(String[] args) throws Exception { + + Msg.init(args); + if (args.length < 1) { + Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC "); + System.exit(1); + } + Msg.createEnvironment(args[0]); + + Host[] hosts = Host.all(); + new SemCreator(hosts[0], "SemCreator").start(); + + Msg.run(); + } + +} diff --git a/teshsuite/java/semaphore/semaphore_gc.tesh b/teshsuite/java/semaphore/semaphore_gc.tesh new file mode 100644 index 0000000000..f2f6df2473 --- /dev/null +++ b/teshsuite/java/semaphore/semaphore_gc.tesh @@ -0,0 +1,5 @@ +$ java -classpath ${classpath:=.} semaphore.SemaphoreGC ${srcdir:=.}/../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.4r]%e(%i:%P@%h)%e%m%n" +> [ 0.0000] (0:maestro@) Using regular java threads. +> [ 0.0000] (1:SemCreator@Fafard) Creating 150 new Semaphores, yielding and triggering a GC after each +> [ 1500.0000] (1:SemCreator@Fafard) It worked, we survived. The test is passed. +> [ 1500.0000] (0:maestro@) MSG_main finished; Cleaning up the simulation... diff --git a/teshsuite/java/sleep_host_off/CMakeLists.txt b/teshsuite/java/sleep_host_off/CMakeLists.txt index 18c2174534..90ba170b7e 100644 --- a/teshsuite/java/sleep_host_off/CMakeLists.txt +++ b/teshsuite/java/sleep_host_off/CMakeLists.txt @@ -1,6 +1,5 @@ set(example java_sleep_host_off) set(sources - ${CMAKE_CURRENT_SOURCE_DIR}/Main.java ${CMAKE_CURRENT_SOURCE_DIR}/SleepHostOff.java ) diff --git a/teshsuite/java/sleep_host_off/Main.java b/teshsuite/java/sleep_host_off/Main.java deleted file mode 100644 index 3cc4cea056..0000000000 --- a/teshsuite/java/sleep_host_off/Main.java +++ /dev/null @@ -1,30 +0,0 @@ -package sleep_host_off; - -import org.simgrid.msg.Host; -import org.simgrid.msg.HostNotFoundException; -import org.simgrid.msg.Msg; -import org.simgrid.msg.NativeException; - -public class Main { - - public static void main(String[] args) throws NativeException { - /* Init. internal values */ - Msg.init(args); - - if (args.length < 2) { - Msg.info("Usage : Main platform_file.xml dployment_file.xml"); - System.exit(1); - } - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - - try { - Msg.run(); - } catch (Exception e){ - System.out.println("Bye bye the program crashes !"); - } - - } -} diff --git a/teshsuite/java/sleep_host_off/SleepHostOff.java b/teshsuite/java/sleep_host_off/SleepHostOff.java index 1d60cad739..cebf7afe77 100644 --- a/teshsuite/java/sleep_host_off/SleepHostOff.java +++ b/teshsuite/java/sleep_host_off/SleepHostOff.java @@ -14,42 +14,63 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -public class SleepHostOff extends Process{ - public static Host jupiter = null; - - public SleepHostOff(Host host, String name, String[]args) { - super(host,name,args); - } - - public void main(String[] strings) throws MsgException { - - try { - jupiter = Host.getByName("Jupiter"); - } catch (HostNotFoundException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - - Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****"); - Msg.info("Test sleep: Create a process on Jupiter, the process simply make periodic sleep, turn off Jupiter"); - new Process(jupiter, "sleep", null) { - public void main(String[] args) { - while (true) { - Msg.info("I'm not dead"); - try { - Process.sleep(10); - } catch (HostFailureException e) { - Msg.info("catch HostException: "+e.getLocalizedMessage()); - break; //Break is needed to finalize the endless loop - } - } - } - }.start(); - - Process.sleep(20); - Msg.info("Stop Jupiter"); - jupiter.off(); - Msg.info("Jupiter has been stopped"); - Process.sleep(300); - Msg.info("Test sleep seems ok, cool !(number of Process : " + Process.getCount() + ", it should be 1 (i.e. the Test one))\n"); - } +class Sleeper extends Process { + public Sleeper(Host host, String name, String[] args) { + super(host,name,args); + } + public void main(String[] args) { + while (true) { + Msg.info("I'm not dead"); + try { + Process.sleep(10); + } catch (HostFailureException e) { + Msg.info("catch HostException: "+e.getLocalizedMessage()); + break; //Break is needed to finalize the endless loop + } + } + } +} + +class TestRunner extends Process { + + public TestRunner(Host host, String name, String[] args) { + super(host,name,args); + } + + public void main(String[] strings) throws MsgException { + Host host = Host.all()[1]; + + + Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****"); + Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "+host.getName()); + new Sleeper(host, "Sleeper", null).start(); + + waitFor(0.02); + Msg.info("Stop "+host.getName()); + host.off(); + Msg.info(host.getName()+" has been stopped"); + waitFor(0.3); + Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount() + ", it should be 1 (i.e. the Test one))"); + } +} + +public class SleepHostOff { + + public static void main(String[] args) throws Exception { + /* Init. internal values */ + Msg.init(args); + + if (args.length < 1) { + Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff "); + System.exit(1); + } + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + + Host[] hosts = Host.all(); + new TestRunner(hosts[0], "TestRunner", null).start(); + + Msg.run(); + } } diff --git a/teshsuite/java/sleep_host_off/sleep_host_off.tesh b/teshsuite/java/sleep_host_off/sleep_host_off.tesh index 5e77e1749f..c371d7fb40 100644 --- a/teshsuite/java/sleep_host_off/sleep_host_off.tesh +++ b/teshsuite/java/sleep_host_off/sleep_host_off.tesh @@ -1,13 +1,12 @@ -$ java -classpath ${classpath:=.} sleep_host_off.Main ${srcdir:=.}/../../examples/platforms/small_platform.xml ${srcdir:=.}/sleep_host_off/sleep_host_off_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ java -classpath ${classpath:=.} sleep_host_off.SleepHostOff ${srcdir:=.}/../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) Using regular java threads. -> [ 0.000000] (1:sleep_host_off.SleepHostOff@Tremblay) **** **** **** ***** ***** Test Sleep ***** ***** **** **** **** -> [ 0.000000] (1:sleep_host_off.SleepHostOff@Tremblay) Test sleep: Create a process on Jupiter, the process simply make periodic sleep, turn off Jupiter -> [ 0.000000] (2:sleep@Jupiter) I'm not dead -> [ 0.010000] (2:sleep@Jupiter) I'm not dead -> [ 0.020000] (1:sleep_host_off.SleepHostOff@Tremblay) Stop Jupiter -> [ 0.020000] (2:sleep@Jupiter) I'm not dead -> [ 0.020000] (2:sleep@Jupiter) catch HostException: Host Failure (null) -> [ 0.020000] (1:sleep_host_off.SleepHostOff@Tremblay) Jupiter has been stopped -> [ 0.320000] (1:sleep_host_off.SleepHostOff@Tremblay) Test sleep seems ok, cool !(number of Process : 1, it should be 1 (i.e. the Test one)) -> +> [ 0.000000] (1:TestRunner@Fafard) **** **** **** ***** ***** Test Sleep ***** ***** **** **** **** +> [ 0.000000] (1:TestRunner@Fafard) Test sleep: Create a process on Tremblay that simply make periodic sleep, turn off Tremblay +> [ 0.000000] (2:Sleeper@Tremblay) I'm not dead +> [ 0.010000] (2:Sleeper@Tremblay) I'm not dead +> [ 0.020000] (1:TestRunner@Fafard) Stop Tremblay +> [ 0.020000] (2:Sleeper@Tremblay) I'm not dead +> [ 0.020000] (2:Sleeper@Tremblay) catch HostException: Host Failure (null) +> [ 0.020000] (1:TestRunner@Fafard) Tremblay has been stopped +> [ 0.320000] (1:TestRunner@Fafard) Test sleep seems ok, cool! (number of Process : 1, it should be 1 (i.e. the Test one)) > [ 0.320000] (0:maestro@) MSG_main finished; Cleaning up the simulation... diff --git a/tools/cmake/MakeExe.cmake b/tools/cmake/MakeExe.cmake index cd1f8fb9e5..2752d29e8a 100644 --- a/tools/cmake/MakeExe.cmake +++ b/tools/cmake/MakeExe.cmake @@ -82,6 +82,7 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/smpi/energy/f90) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/xbt) add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java/semaphore) add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleep_host_off) add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/mc) diff --git a/tools/cmake/Tests.cmake b/tools/cmake/Tests.cmake index 832cad7f13..e84166a363 100644 --- a/tools/cmake/Tests.cmake +++ b/tools/cmake/Tests.cmake @@ -512,6 +512,7 @@ IF(NOT enable_memcheck) # teshsuite ones ADD_TESH(tesh-java-sleep-host-off --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java ${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleep_host_off/sleep_host_off.tesh) + ADD_TESH(tesh-java-semaphore-gc --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java ${CMAKE_HOME_DIRECTORY}/teshsuite/java/semaphore/semaphore_gc.tesh) ENDIF()