From 5f5553f1c0b6731970db6df24d79654661238247 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 3 Sep 2015 17:43:33 +0200 Subject: Bug 1211: Adding unit test to identify Thread.interrupt() caller for DefaultEDTUtil.invokeImpl(..) wait interruption --- make/scripts/tests.sh | 3 +- .../test/junit/newt/TestBug1211IRQ00NEWT.java | 230 +++++++++++++++++++++ 2 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index b5579c01c..db5b42b03 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -428,7 +428,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2SimpleNEWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* -testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestRulerNEWT01 $* #testnoawt com.jogamp.opengl.test.junit.graph.demos.GPUUISceneNewtDemo $* @@ -630,6 +630,7 @@ testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasA #testnoawt com.jogamp.opengl.test.junit.newt.TestGLWindowInvisiblePointer01NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle01NEWT #testnoawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle02NEWT +testnoawt com.jogamp.opengl.test.junit.newt.TestBug1211IRQ00NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00aNEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00bNEWT $* diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java new file mode 100644 index 000000000..2c1adcd22 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestBug1211IRQ00NEWT.java @@ -0,0 +1,230 @@ +/** + * Copyright 2015 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.newt; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import com.jogamp.opengl.*; + +import com.jogamp.newt.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.util.EDTUtil; + +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.common.ExceptionUtils; + +/** + * Unit test to identify Thread.interrupt() caller for DefaultEDTUtil.invokeImpl(..) wait interruption. + * + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestBug1211IRQ00NEWT extends UITestCase { + static GLProfile glp; + static long durationTest00 = 1000; // ms + static long durationTest01 = 1000; // ms + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(final Screen screen, final GLCapabilitiesImmutable caps) { + Assert.assertNotNull(caps); + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + glWindow = GLWindow.create(screen, caps); + Assert.assertNotNull(glWindow); + } else { + glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + } + glWindow.setUpdateFPSFrames(1, null); + + final GearsES2 demo = new GearsES2(); + demo.setVerbose(false); + glWindow.addGLEventListener(demo); + + glWindow.setSize(512, 512); + return glWindow; + } + + static void destroyWindow(final GLWindow glWindow) { + if(null!=glWindow) { + glWindow.destroy(); + Assert.assertEquals(false,glWindow.isNativeValid()); + } + } + + static class MyThread extends Thread { + volatile boolean interruptCalled; + public MyThread(final Runnable target, final String name) { + super(target, name); + interruptCalled = false; + } + public boolean interruptCalled() { return interruptCalled; } + @Override + public void interrupt() { + System.err.println("MyThread.interrupt() ******************************************************"); + ExceptionUtils.dumpStack(System.err); + super.interrupt(); + } + } + + /** + * Test whether resize triggers DefaultEDTUtil.invokeImpl(..) wait interruption. + */ + @Test + public void test00() { + final MyThread t = new MyThread(new Runnable() { + public void run() { + final GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + final GLWindow window1 = createWindow(null, caps); // local + final EDTUtil edt = window1.getScreen().getDisplay().getEDTUtil(); + final Animator anim = new Animator(window1); + try { + window1.setVisible(true); + Assert.assertEquals(true,window1.isVisible()); + Assert.assertEquals(true,window1.isNativeValid()); + anim.start(); + boolean ok = true; + for(int i=0; ok && i*100 "+nw+"x"+nh); + window1.setSize(nw, nh); + final MyThread _t = (MyThread)Thread.currentThread(); + ok = !_t.interruptCalled() && edt.isRunning() && anim.isAnimating(); + } + } catch (final InterruptedException e) { + ExceptionUtils.dumpThrowable("MyThread.InterruptedException", e); + } + anim.stop(); + destroyWindow(window1); + } + }, "Thread_Test01"); + t.start(); + try { + t.join(); + } catch (final InterruptedException e) { + ExceptionUtils.dumpThrowable("Thread.InterruptedException", e); + } + } + + /** + * Test whether create/destroy triggers DefaultEDTUtil.invokeImpl(..) wait interruption. + */ + @Test + public void test01() { + final MyThread t = new MyThread(new Runnable() { + public void run() { + GLWindow lastWindow = null; + try { + final boolean ok = true; + for(int i=0; ok && i*100