diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java index b6c6e0a91..fc025d023 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java @@ -30,12 +30,17 @@ package com.jogamp.opengl.test.junit.jogl.acore; import java.io.IOException; +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.util.InsetsImmutable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Window; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -43,33 +48,61 @@ import com.jogamp.opengl.util.Animator; public class TestInitConcurrentNEWT extends UITestCase { + static final int demoSize = 128; + static long duration = 300; // ms + static InsetsImmutable insets = null; + static int scrnHeight, scrnWidth; + static int num_x, num_y; + + @BeforeClass + public static void initClass() { + Window dummyWindow = NewtFactory.createWindow(new Capabilities()); + dummyWindow.setSize(demoSize, demoSize); + dummyWindow.setVisible(true); + Assert.assertEquals(true, dummyWindow.isVisible()); + Assert.assertEquals(true, dummyWindow.isNativeValid()); + insets = dummyWindow.getInsets(); + scrnHeight = dummyWindow.getScreen().getHeight(); + scrnWidth = dummyWindow.getScreen().getWidth(); + num_x = scrnWidth / ( demoSize + insets.getTotalWidth() ) - 2; + num_y = scrnHeight / ( demoSize + insets.getTotalHeight() ) - 2; + dummyWindow.destroy(); + } + public class JOGLTask implements Runnable { + private int id; private Object postSync; private boolean done = false; - public JOGLTask(Object postSync) { + public JOGLTask(Object postSync, int id) { this.postSync = postSync; + this.id = id; } public void run() { - System.err.println(Thread.currentThread().getName()+" START"); + int x = ( id % num_x ) * ( demoSize + insets.getTotalHeight() ); + int y = ( (id / num_x) % num_y ) * ( demoSize + insets.getTotalHeight() ); + + System.err.println("JOGLTask "+id+": START: "+x+"/"+y+" - "+Thread.currentThread().getName()); GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); Assert.assertNotNull(glWindow); - glWindow.setTitle("Gears NEWT Test"); + glWindow.setTitle("Task "+id); + glWindow.setPosition(x + insets.getLeftWidth(), y + insets.getTopHeight() ); glWindow.addGLEventListener(new GearsES2(0)); Animator animator = new Animator(glWindow); - glWindow.setSize(128, 128); + glWindow.setSize(demoSize, demoSize); glWindow.setVisible(true); - animator.setUpdateFPSFrames(60, System.err); + animator.setUpdateFPSFrames(60, null); animator.start(); Assert.assertEquals(true, animator.isAnimating()); Assert.assertEquals(true, glWindow.isVisible()); Assert.assertEquals(true, glWindow.isNativeValid()); Assert.assertEquals(true, glWindow.isRealized()); + System.err.println("JOGLTask "+id+": RUNNING: "+Thread.currentThread().getName()); while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) { try { @@ -82,10 +115,10 @@ public class TestInitConcurrentNEWT extends UITestCase { animator.stop(); glWindow.destroy(); - System.err.println(Thread.currentThread().getName()+" sync"); + System.err.println("JOGLTask "+id+": DONE/SYNC: "+Thread.currentThread().getName()); synchronized (postSync) { done = true; - System.err.println(Thread.currentThread().getName()+" END"); + System.err.println("JOGLTask "+id+": END: "+Thread.currentThread().getName()); postSync.notifyAll(); } } @@ -142,13 +175,13 @@ public class TestInitConcurrentNEWT extends UITestCase { final Thread[] threads = new Thread[num]; int i; for(i=0; i<num; i++) { - tasks[i] = new JOGLTask(sync); + tasks[i] = new JOGLTask(sync, i); threads[i] = new Thread(tasks[i], currentThreadName+"-jt"+i); } + for(i=0; i<num; i++) { + threads[i].start(); + } synchronized (sync) { - for(i=0; i<num; i++) { - threads[i].start(); - } while(!done(tasks)) { try { sync.wait(); @@ -177,16 +210,19 @@ public class TestInitConcurrentNEWT extends UITestCase { } @Test - public void test04FourThreads() throws InterruptedException { - runJOGLTasks(4); - } - - @Test public void test16SixteenThreads() throws InterruptedException { runJOGLTasks(16); } public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } String tstname = TestInitConcurrentNEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); } |