diff options
author | Sven Gothel <[email protected]> | 2013-07-09 15:04:50 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-07-09 15:04:50 +0200 |
commit | 453ccee8e3ce90956756d1582852b13f45cd2f38 (patch) | |
tree | 953a75b75fec41f0e77312a342976cd334928eae /src/test | |
parent | 433e3914324b90c910b018bb7d9d80e814c67123 (diff) |
NEWT EDTUtil: Exposed weakness of EDTUtil usage due to usage of WeakReference, i.e. higher retention of Display instances.
- WeakReference Change 99479bf3197cde8e89c5b499d135417863d521c7
- Refines commits:
feb352145af1643a57eaae99c0342e6f5e0f2a2e
dec4b02fe4b93028c85de6a56b6af79601042d6e
433e3914324b90c910b018bb7d9d80e814c67123
Reviews EDTUtil API and usage:
- less confusing / more determined EDTUtil API
- EDTUtil's thread shall only be reset and started when required (-> lazy)
- EDTUtil's instance in Display shall be handled thread safe w/o extra blocking
- EDTUtil's implementations (Default, SWT and AWT) shall be aligned / similar as much as possible
Further note: SWT's EDTUtil (NewtCanvasSWT) shall not use a reused Display instance due to it's
custom SWTEDTUtil. We may need to disable the ref. cache if custom EDTUtil (setEDTUtil)
is intended (used).
Diffstat (limited to 'src/test')
11 files changed, 64 insertions, 29 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java index f8e6ee5d3..f1bc0ab7a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java @@ -184,6 +184,7 @@ public abstract class InitConcurrentBaseNEWT extends UITestCase { } protected void runJOGLTasks(int num, boolean reuse) throws InterruptedException { + System.err.println("InitConcurrentBaseNEWT "+num+" threads, reuse display: "+reuse); final String currentThreadName = Thread.currentThread().getName(); final Object syncDone = new Object(); final JOGLTask[] tasks = new JOGLTask[num]; @@ -198,13 +199,16 @@ public abstract class InitConcurrentBaseNEWT extends UITestCase { for(i=0; i<num; i++) { threads[i].start(); } + i=0; synchronized (syncDone) { while(!done(tasks)) { try { - syncDone.wait(); + syncDone.wait(500); } catch (InterruptedException e) { throw new RuntimeException(e); } + System.err.println(i+": "+doneDump(tasks)); + i++; } } final long t1 = System.currentTimeMillis(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent01NEWT.java index 20c098f2e..f8e0affa3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent01NEWT.java @@ -42,8 +42,7 @@ import com.jogamp.common.os.Platform; * </p> */ public class TestInitConcurrent01NEWT extends InitConcurrentBaseNEWT { - static boolean mainRun = false; - + @Test(timeout=180000) // TO 3 min public void test02TwoThreads() throws InterruptedException { runJOGLTasks(2, true); @@ -56,8 +55,7 @@ public class TestInitConcurrent01NEWT extends InitConcurrentBaseNEWT { @Test(timeout=300000) // TO 5 min public void test16SixteenThreads() throws InterruptedException { - if( !mainRun && - Platform.getCPUFamily() != Platform.CPUFamily.ARM && + if( Platform.getCPUFamily() != Platform.CPUFamily.ARM && Platform.getOSType() != Platform.OSType.WINDOWS ) { runJOGLTasks(16, true); } else { @@ -66,11 +64,8 @@ public class TestInitConcurrent01NEWT extends InitConcurrentBaseNEWT { } public static void main(String args[]) throws IOException { - mainRun = true; for(int i=0; i<args.length; i++) { - if(args[i].equals("-normalRun")) { - mainRun = false; - } else if(args[i].equals("-time")) { + if(args[i].equals("-time")) { i++; try { duration = Integer.parseInt(args[i]); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent02NEWT.java index 5b754ef7d..dfb7326df 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent02NEWT.java @@ -68,8 +68,7 @@ public class TestInitConcurrent02NEWT extends InitConcurrentBaseNEWT { System.err.println("Disabled for auto unit test until further analysis - Windows/ATI driver crash"); return; } - if( !mainRun && - Platform.getCPUFamily() != Platform.CPUFamily.ARM && + if( Platform.getCPUFamily() != Platform.CPUFamily.ARM && Platform.getOSType() != Platform.OSType.WINDOWS ) { runJOGLTasks(16, false); } else { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java index eed2e1267..7a93faa1f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NewtCanvasSWT.java @@ -103,6 +103,7 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase { Display display = null; Shell shell = null; Composite composite = null; + com.jogamp.newt.Display swtNewtDisplay = null; @Before public void init() { @@ -120,6 +121,7 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase { composite.setLayout( new FillLayout() ); Assert.assertNotNull( composite ); }}); + swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } @After @@ -142,6 +144,7 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } + swtNewtDisplay = null; display = null; shell = null; composite = null; @@ -149,8 +152,7 @@ public class TestGearsES2NewtCanvasSWT extends UITestCase { protected void runTestGL(GLCapabilitiesImmutable caps) throws InterruptedException, InvocationTargetException { System.err.println("requested: vsync "+swapInterval+", "+caps); - com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null); - com.jogamp.newt.Screen screen = NewtFactory.createScreen(dpy, screenIdx); + com.jogamp.newt.Screen screen = NewtFactory.createScreen(swtNewtDisplay, screenIdx); final GLWindow glWindow = GLWindow.create(screen, caps); Assert.assertNotNull(glWindow); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java index e7037aaef..f8fbe7276 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java @@ -52,6 +52,7 @@ import javax.media.opengl.GLProfile; import junit.framework.Assert; import com.jogamp.nativewindow.swt.SWTAccessor; +import com.jogamp.newt.NewtFactory; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow ; @@ -250,6 +251,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { volatile Display display; volatile Shell shell; volatile Composite composite; + volatile com.jogamp.newt.Display swtNewtDisplay = null; public void init() { SWTAccessor.invoke(true, new Runnable() { @@ -266,7 +268,8 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { composite = new Composite( shell, SWT.NO_BACKGROUND ); composite.setLayout( new FillLayout() ); Assert.assertNotNull( composite ); - }}); + }}); + swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } public void dispose() { @@ -288,6 +291,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } + swtNewtDisplay = null; display = null; shell = null; composite = null; @@ -305,7 +309,8 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { { final GLProfile gl2Profile = GLProfile.get( GLProfile.GL2 ) ; final GLCapabilities caps = new GLCapabilities( gl2Profile ) ; - glWindow = GLWindow.create( caps ) ; + com.jogamp.newt.Screen screen = NewtFactory.createScreen(dsc.swtNewtDisplay, 0); + glWindow = GLWindow.create( screen, caps ) ; glWindow.addGLEventListener( new BigFlashingX() ) ; glWindow.addKeyListener(new KeyAdapter() { @Override diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTGLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTGLn.java index 396d219b4..7acc6452e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTGLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTGLn.java @@ -48,6 +48,8 @@ import org.junit.After; import org.junit.Test; import com.jogamp.nativewindow.swt.SWTAccessor; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.swt.NewtCanvasSWT; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; @@ -81,7 +83,8 @@ public class TestNewtCanvasSWTGLn extends UITestCase { Display display = null; Shell shell = null; Composite composite = null; - + com.jogamp.newt.Display swtNewtDisplay = null; + @BeforeClass public static void startup() { System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); @@ -103,6 +106,7 @@ public class TestNewtCanvasSWTGLn extends UITestCase { composite.setLayout( new FillLayout() ); Assert.assertNotNull( composite ); }}); + swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } @After @@ -125,6 +129,7 @@ public class TestNewtCanvasSWTGLn extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } + swtNewtDisplay = null; display = null; shell = null; composite = null; @@ -134,7 +139,8 @@ public class TestNewtCanvasSWTGLn extends UITestCase { boolean postAttach, boolean useAnimator ) throws InterruptedException { final GLReadBufferUtil screenshot = new GLReadBufferUtil(false, false); - final GLWindow glWindow1 = GLWindow.create(caps); + final Screen screen = NewtFactory.createScreen(swtNewtDisplay, 0); + final GLWindow glWindow1 = GLWindow.create(screen, caps); Assert.assertNotNull(glWindow1); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeValid()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java index 66911ef06..4d279b349 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java @@ -49,6 +49,7 @@ import jogamp.newt.swt.event.SWTNewtEventFactory; import junit.framework.Assert; import com.jogamp.nativewindow.swt.SWTAccessor; +import com.jogamp.newt.NewtFactory; import com.jogamp.newt.opengl.GLWindow ; import com.jogamp.newt.swt.NewtCanvasSWT ; import com.jogamp.opengl.swt.GLCanvas; @@ -140,7 +141,9 @@ public class TestSWTBug643AsyncExec extends UITestCase { { try { - swtDisplay.asyncExec( swtAsyncAction ); + if( !swtDisplay.isDisposed() ) { + swtDisplay.asyncExec( swtAsyncAction ); + } if(null != newtDisplay && newtDisplay.isNativeValid() && newtDisplay.getEDTUtil().isRunning()) { // only perform async exec on valid and already running NEWT EDT! newtDisplay.runOnEDTIfAvail(false, newtAsyncAction); @@ -227,9 +230,10 @@ public class TestSWTBug643AsyncExec extends UITestCase { glad = glc; newtDisplay = null; } else if( useNewtCanvasSWT ) { - final GLWindow glWindow = GLWindow.create( caps ) ; + newtDisplay = NewtFactory.createDisplay(null, false); // no-reuse + com.jogamp.newt.Screen screen = NewtFactory.createScreen(newtDisplay, 0); + final GLWindow glWindow = GLWindow.create( screen, caps ) ; glWindow.addGLEventListener( new GearsES2() ) ; - newtDisplay = glWindow.getScreen().getDisplay(); if( glWindowPreVisible ) { newtDisplay.setEDTUtil(new SWTEDTUtil(newtDisplay, dsc.display)); // Especially Windows requires creation access via same thread! glWindow.setVisible(true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java index e4867e3fe..6a248bcf6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java @@ -37,6 +37,8 @@ import javax.media.opengl.*; import com.jogamp.newt.*; import com.jogamp.newt.event.*; import com.jogamp.newt.opengl.*; +import com.jogamp.newt.util.EDTUtil; + import java.io.IOException; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -89,7 +91,7 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { Assert.assertEquals(0,display.getReferenceCount()); Assert.assertEquals(false,display.isNativeValid()); Assert.assertNotNull(display.getEDTUtil()); - Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); Assert.assertEquals(0,screen.getReferenceCount()); Assert.assertEquals(false,screen.isNativeValid()); @@ -199,10 +201,17 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { Assert.assertEquals(0,Display.getActiveDisplayNumber()); Assert.assertEquals(0,display.getReferenceCount()); Assert.assertEquals(false,display.isNativeValid()); - Assert.assertNotNull(display.getEDTUtil()); - Assert.assertEquals(false,display.getEDTUtil().isRunning()); - display.getEDTUtil().invoke(true, null); - Assert.assertEquals(true,display.getEDTUtil().isRunning()); + { + final EDTUtil edtUtil = display.getEDTUtil(); + Assert.assertNotNull(edtUtil); + Assert.assertEquals(false,edtUtil.isRunning()); + edtUtil.restart(); + edtUtil.invoke(true, null); + Assert.assertEquals(true,edtUtil.isRunning()); + edtUtil.invokeStop(true, null); + edtUtil.waitUntilStopped(); + Assert.assertEquals(false,edtUtil.isRunning()); + } Assert.assertEquals(0,screen.getReferenceCount()); Assert.assertEquals(false,screen.isNativeValid()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java index e7fced5d9..d618d3b3c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java @@ -74,7 +74,7 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertEquals(0,display.getReferenceCount()); Assert.assertEquals(false,display.isNativeValid()); Assert.assertNotNull(display.getEDTUtil()); - Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); Assert.assertEquals(0,screen.getReferenceCount()); Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(0,Display.getActiveDisplayNumber()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aSWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aSWT.java index 11aef7c24..c95ac1985 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aSWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aSWT.java @@ -47,6 +47,7 @@ import org.junit.BeforeClass; import org.junit.Test; import com.jogamp.nativewindow.swt.SWTAccessor; +import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Window; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.swt.NewtCanvasSWT; @@ -65,6 +66,7 @@ public class TestParenting01aSWT extends UITestCase { Display display = null; Shell shell = null; Composite composite1 = null; + com.jogamp.newt.Display swtNewtDisplay = null; @BeforeClass public static void initClass() { @@ -86,6 +88,7 @@ public class TestParenting01aSWT extends UITestCase { composite1.setLayout( new FillLayout() ); Assert.assertNotNull( composite1 ); }}); + swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } @After @@ -105,6 +108,7 @@ public class TestParenting01aSWT extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } + swtNewtDisplay = null; display = null; shell = null; composite1 = null; @@ -113,7 +117,8 @@ public class TestParenting01aSWT extends UITestCase { @Test public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { - GLWindow glWindow1 = GLWindow.create(glCaps); + com.jogamp.newt.Screen screen = NewtFactory.createScreen(swtNewtDisplay, 0); + GLWindow glWindow1 = GLWindow.create(screen, glCaps); Assert.assertNotNull(glWindow1); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeValid()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java index 14a36c573..a4e4ace43 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting04SWT.java @@ -47,6 +47,7 @@ import org.junit.BeforeClass; import org.junit.Test; import com.jogamp.nativewindow.swt.SWTAccessor; +import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Window; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.swt.NewtCanvasSWT; @@ -69,6 +70,7 @@ public class TestParenting04SWT extends UITestCase { Shell shell2 = null; Composite composite1 = null; Composite composite2 = null; + com.jogamp.newt.Display swtNewtDisplay = null; @BeforeClass public static void initClass() { @@ -98,6 +100,7 @@ public class TestParenting04SWT extends UITestCase { composite2.setLayout( new FillLayout() ); Assert.assertNotNull( composite2 ); }}); + swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } @After @@ -121,6 +124,7 @@ public class TestParenting04SWT extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } + swtNewtDisplay = null; display = null; shell1 = null; shell2 = null; @@ -141,13 +145,15 @@ public class TestParenting04SWT extends UITestCase { } protected void winHopFrame2Frame(final boolean detachFirst) throws InterruptedException, InvocationTargetException { - final GLWindow glWindow1 = GLWindow.create(glCaps); + com.jogamp.newt.Screen screen = NewtFactory.createScreen(swtNewtDisplay, 0); + + final GLWindow glWindow1 = GLWindow.create(screen, glCaps); GLEventListener demo1 = new RedSquareES2(); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); Animator anim1 = new Animator(glWindow1); - final GLWindow glWindow2 = GLWindow.create(glCaps); + final GLWindow glWindow2 = GLWindow.create(screen, glCaps); GLEventListener demo2 = new GearsES2(); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); |