Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a test case for the JVM slaying our semaphores
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 3 Feb 2016 07:35:31 +0000 (08:35 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 3 Feb 2016 07:35:31 +0000 (08:35 +0100)
teshsuite/java/semaphore/CMakeLists.txt [new file with mode: 0644]
teshsuite/java/semaphore/SemaphoreGC.java [new file with mode: 0644]
teshsuite/java/semaphore/semaphore_gc.tesh [new file with mode: 0644]
tools/cmake/MakeExe.cmake
tools/cmake/Tests.cmake

diff --git a/teshsuite/java/semaphore/CMakeLists.txt b/teshsuite/java/semaphore/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e86706b
--- /dev/null
@@ -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 (file)
index 0000000..224108a
--- /dev/null
@@ -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 <deployment.xml>");
+                       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 (file)
index 0000000..f2f6df2
--- /dev/null
@@ -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...
index cd1f8fb..2752d29 100644 (file)
@@ -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}/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)
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleep_host_off)
 
 add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/mc)
index 832cad7..e84166a 100644 (file)
@@ -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)
 
     # 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()
 
 
   ENDIF()