From: Martin Quinson Date: Wed, 3 Feb 2016 07:35:31 +0000 (+0100) Subject: add a test case for the JVM slaying our semaphores X-Git-Tag: v3_13~994 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cdd4b1f204288924e187d305a8c2d1739040c513 add a test case for the JVM slaying our semaphores --- 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/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()