summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java (renamed from src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java)84
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent01NEWT.java78
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent02NEWT.java78
3 files changed, 190 insertions, 50 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/InitConcurrentBaseNEWT.java
index 7127b0a5f..11d1331ed 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/InitConcurrentBaseNEWT.java
@@ -28,8 +28,6 @@
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;
@@ -37,17 +35,24 @@ import javax.media.opengl.GLProfile;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Test;
-import com.jogamp.common.os.Platform;
+import com.jogamp.newt.Display;
import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
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;
import com.jogamp.opengl.util.Animator;
-public class TestInitConcurrentNEWT extends UITestCase {
+/**
+ * Concurrent and lock-free initialization and rendering using exclusive NEWT Display EDT instances, or
+ * concurrent locked initialization and lock-free rendering using a shared NEWT Display EDT instances.
+ * <p>
+ * Rendering is always lock-free and independent of the EDT.
+ * </p>
+ */
+public class InitConcurrentBaseNEWT extends UITestCase {
static final int demoSize = 128;
@@ -73,20 +78,24 @@ public class TestInitConcurrentNEWT extends UITestCase {
}
public class JOGLTask implements Runnable {
- private int id;
- private Object postSync;
+ private final int id;
+ private final Object postSync;
+ private final boolean reuse;
private boolean done = false;
- public JOGLTask(Object postSync, int id) {
+ public JOGLTask(Object postSync, int id, boolean reuse) {
this.postSync = postSync;
this.id = id;
+ this.reuse = reuse;
}
public void run() {
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()));
+ System.err.println("JOGLTask "+id+": START: "+x+"/"+y+", reuse "+reuse+" - "+Thread.currentThread().getName());
+ final Display display = NewtFactory.createDisplay(null, reuse);
+ final Screen screen = NewtFactory.createScreen(display, 0);
+ final GLWindow glWindow = GLWindow.create(screen, new GLCapabilities(GLProfile.getDefault()));
Assert.assertNotNull(glWindow);
glWindow.setTitle("Task "+id);
glWindow.setPosition(x + insets.getLeftWidth(), y + insets.getTopHeight() );
@@ -98,6 +107,9 @@ public class TestInitConcurrentNEWT extends UITestCase {
glWindow.setSize(demoSize, demoSize);
glWindow.setVisible(true);
animator.setUpdateFPSFrames(60, null);
+
+ System.err.println("JOGLTask "+id+": INITIALIZED: "+", "+display+" - "+Thread.currentThread().getName());
+
animator.start();
Assert.assertEquals(true, animator.isAnimating());
Assert.assertEquals(true, glWindow.isVisible());
@@ -169,67 +181,39 @@ public class TestInitConcurrentNEWT extends UITestCase {
return sb.toString();
}
- protected void runJOGLTasks(int num) throws InterruptedException {
+ protected void runJOGLTasks(int num, boolean reuse) throws InterruptedException {
final String currentThreadName = Thread.currentThread().getName();
- final Object sync = new Object();
+ final Object syncDone = new Object();
final JOGLTask[] tasks = new JOGLTask[num];
final Thread[] threads = new Thread[num];
int i;
for(i=0; i<num; i++) {
- tasks[i] = new JOGLTask(sync, i);
+ tasks[i] = new JOGLTask(syncDone, i, reuse);
threads[i] = new Thread(tasks[i], currentThreadName+"-jt"+i);
}
+ final long t0 = System.currentTimeMillis();
+
for(i=0; i<num; i++) {
threads[i].start();
}
- synchronized (sync) {
+ synchronized (syncDone) {
while(!done(tasks)) {
try {
- sync.wait();
+ syncDone.wait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
+ final long t1 = System.currentTimeMillis();
+ System.err.println("total: "+(t1-t0)/1000.0+"s");
+
Assert.assertTrue("Tasks are incomplete. Complete: "+doneDump(tasks), done(tasks));
i=0;
while(i<30 && !isDead(threads)) {
Thread.sleep(100);
i++;
}
- Assert.assertTrue("Threads are still alive after 3s. Alive: "+isAliveDump(threads), isDead(threads));
- }
-
- @Test
- public void test01OneThread() throws InterruptedException {
- runJOGLTasks(1);
- }
-
- @Test
- public void test02TwoThreads() throws InterruptedException {
- runJOGLTasks(2);
- }
-
- @Test
- public void test16SixteenThreads() throws InterruptedException {
- if( Platform.getCPUFamily() == Platform.CPUFamily.ARM ) {
- runJOGLTasks(8);
- } else {
- 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);
- }
-
+ Assert.assertTrue("Threads are still alive after 3s. Alive: "+isAliveDump(threads), isDead(threads));
+ }
}
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
new file mode 100644
index 000000000..e5ed8a79f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent01NEWT.java
@@ -0,0 +1,78 @@
+/**
+ * Copyright 2010 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 org.junit.Test;
+
+import com.jogamp.common.os.Platform;
+
+/**
+ * Concurrent initialization and lock-free rendering using shared NEWT Display EDT instances.
+ * <p>
+ * Rendering is always lock-free and independent of the EDT, however shared NEWT Display instances
+ * perform lifecycle actions (window creation etc) with locking.
+ * </p>
+ */
+public class TestInitConcurrent01NEWT extends InitConcurrentBaseNEWT {
+
+ @Test
+ public void test02TwoThreads() throws InterruptedException {
+ runJOGLTasks(2, true);
+ }
+
+ @Test
+ public void test02FourThreads() throws InterruptedException {
+ runJOGLTasks(4, true);
+ }
+
+ @Test
+ public void test16SixteenThreads() throws InterruptedException {
+ if( Platform.getCPUFamily() != Platform.CPUFamily.ARM ) {
+ runJOGLTasks(16, true);
+ } else {
+ runJOGLTasks( 8, true);
+ }
+ }
+
+ 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 = TestInitConcurrent01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
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
new file mode 100644
index 000000000..51e9af00e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrent02NEWT.java
@@ -0,0 +1,78 @@
+/**
+ * Copyright 2010 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 org.junit.Test;
+
+import com.jogamp.common.os.Platform;
+
+/**
+ * Concurrent and lock-free initialization and rendering using exclusive NEWT Display EDT instances.
+ * <p>
+ * Rendering is always lock-free and independent of the EDT, however exclusive NEWT Display instances
+ * perform lifecycle actions (window creation etc) w/o locking.
+ * </p>
+ */
+public class TestInitConcurrent02NEWT extends InitConcurrentBaseNEWT {
+
+ @Test
+ public void test02TwoThreads() throws InterruptedException {
+ runJOGLTasks(2, false);
+ }
+
+ @Test
+ public void test02FourThreads() throws InterruptedException {
+ runJOGLTasks(4, false);
+ }
+
+ @Test
+ public void test16SixteenThreads() throws InterruptedException {
+ if( Platform.getCPUFamily() != Platform.CPUFamily.ARM ) {
+ runJOGLTasks(16, false);
+ } else {
+ runJOGLTasks( 8, false);
+ }
+ }
+
+ 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 = TestInitConcurrent02NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}