From 78d9e7c84f03ac7b83ad2933cac884ce9ecac161 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 13 May 2012 22:01:00 +0200 Subject: GLContext/Surface Deadlock: Add unit test, provoking deadlock w/ 2 threads, one holding the surfaceLock acquiring ctxLock where ctx acquires the surfaceLock --- .../jogl/acore/TestGLContextSurfaceLockNEWT.java | 218 +++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java (limited to 'src/test/com') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java new file mode 100644 index 000000000..4b019d9be --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java @@ -0,0 +1,218 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; + +import javax.media.nativewindow.NativeSurface; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestGLContextSurfaceLockNEWT extends UITestCase { + static final int demoSize = 64; + + public abstract class MyRunnable implements Runnable { + final Object postSync; + final int id; + boolean done = false; + + public MyRunnable(Object postSync, int id) { + this.postSync = postSync; + this.id = id; + } + + public boolean done() { return done; } + } + + public class RudeAnimator extends MyRunnable { + private final GLAutoDrawable glad; + private final int frameCount; + + public RudeAnimator(GLAutoDrawable glad, int frameCount, Object postSync, int id) { + super(postSync, id); + this.glad = glad; + this.frameCount = frameCount; + } + + public void run() { + System.err.println("Animatr "+id+": PRE: "+Thread.currentThread().getName()); + + for(int c=0; c NativeSurface.LOCK_SURFACE_NOT_READY) { + try { + win.display(); + } finally { + win.unlockSurface(); + } + } + }}); + } + + System.err.println("Resizer "+id+": DONE/SYNC: "+Thread.currentThread().getName()); + synchronized (postSync) { + done = true; + System.err.println("Resizer "+id+": END: "+Thread.currentThread().getName()); + postSync.notifyAll(); + } + } + } + + protected static boolean done(MyRunnable[] tasks) { + for(int i=tasks.length-1; i>=0; i--) { + if(!tasks[i].done()) { + return false; + } + } + return true; + } + + protected static boolean isDead(Thread[] threads) { + for(int i=threads.length-1; i>=0; i--) { + if(threads[i].isAlive()) { + return false; + } + } + return true; + } + + protected void runJOGLTasks(int animThreadCount, int frameCount, int reszThreadCount, int resizeCount) throws InterruptedException { + GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glWindow); + + glWindow.addGLEventListener(new GearsES2(0)); + glWindow.setSize(demoSize, demoSize); + glWindow.setVisible(true); + + final String currentThreadName = Thread.currentThread().getName(); + final Object sync = new Object(); + final MyRunnable[] tasks = new MyRunnable[animThreadCount+reszThreadCount]; + final Thread[] threads = new Thread[animThreadCount+reszThreadCount]; + int i=0; + + System.err.println("animThreadCount "+animThreadCount+", frameCount "+frameCount); + System.err.println("reszThreadCount "+reszThreadCount+", resizeCount "+resizeCount); + System.err.println("tasks "+tasks.length+", threads "+threads.length); + + for(; i