aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-07-08 10:50:52 +0200
committerSven Gothel <[email protected]>2014-07-08 10:50:52 +0200
commit7d0c81f28d44179c7dafeeff1f3787f8aec622aa (patch)
tree3edffe7baa88738f1763d7cb446c72f0d755901e /src/test
parent73d2a436f92e360126167d9ce09b3d9637204921 (diff)
Findbugs.increment_volatile: Use AtomicInteger or add comment that operation is safe!
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/bugs/DemoBug910ExtendedAWTAppletLifecycleCheck.java39
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java13
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java41
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/UITestCase.java15
6 files changed, 73 insertions, 67 deletions
diff --git a/src/test/com/jogamp/opengl/test/bugs/DemoBug910ExtendedAWTAppletLifecycleCheck.java b/src/test/com/jogamp/opengl/test/bugs/DemoBug910ExtendedAWTAppletLifecycleCheck.java
index 20573aa4b..3d43c2f8f 100644
--- a/src/test/com/jogamp/opengl/test/bugs/DemoBug910ExtendedAWTAppletLifecycleCheck.java
+++ b/src/test/com/jogamp/opengl/test/bugs/DemoBug910ExtendedAWTAppletLifecycleCheck.java
@@ -35,6 +35,7 @@ import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.atomic.AtomicInteger;
@SuppressWarnings("serial")
public class DemoBug910ExtendedAWTAppletLifecycleCheck extends Applet {
@@ -83,27 +84,27 @@ public class DemoBug910ExtendedAWTAppletLifecycleCheck extends Applet {
", compCount "+compCount+", compClazz "+clazzName);
}
- volatile int initCount = 0;
- volatile int startCount = 0;
- volatile int stopCount = 0;
- volatile int destroyCount = 0;
+ AtomicInteger initCount = new AtomicInteger(0);
+ AtomicInteger startCount = new AtomicInteger(0);
+ AtomicInteger stopCount = new AtomicInteger(0);
+ AtomicInteger destroyCount = new AtomicInteger(0);
private final void checkAppletState(final String msg, final boolean expIsActive,
final int expInitCount, final int expStartCount, final int expStopCount, final boolean startStopCountEquals, final int expDestroyCount) {
final boolean isActive = this.isActive();
- final String okS = ( expInitCount == initCount &&
+ final String okS = ( expInitCount == initCount.get() &&
expIsActive == isActive &&
- expStartCount == startCount &&
- expStopCount == stopCount &&
- expDestroyCount == destroyCount &&
+ expStartCount == startCount.get() &&
+ expStopCount == stopCount.get() &&
+ expDestroyCount == destroyCount.get() &&
( !startStopCountEquals || startCount == stopCount ) ) ? "OK" : "ERROR";
println("Applet-State @ "+msg+": "+okS+
", active[exp "+expIsActive+", has "+isActive+"]"+(expIsActive!=isActive?"*":"")+
- ", init[exp "+expInitCount+", has "+initCount+"]"+(expInitCount!=initCount?"*":"")+
- ", start[exp "+expStartCount+", has "+startCount+"]"+(expStartCount!=startCount?"*":"")+
- ", stop[exp "+expStopCount+", has "+stopCount+"]"+(expStopCount!=stopCount?"*":"")+
+ ", init[exp "+expInitCount+", has "+initCount+"]"+(expInitCount!=initCount.get()?"*":"")+
+ ", start[exp "+expStartCount+", has "+startCount+"]"+(expStartCount!=startCount.get()?"*":"")+
+ ", stop[exp "+expStopCount+", has "+stopCount+"]"+(expStopCount!=stopCount.get()?"*":"")+
", start==stop[exp "+startStopCountEquals+", start "+startCount+", stop "+stopCount+"]"+(( startStopCountEquals && startCount != stopCount )?"*":"")+
- ", destroy[exp "+expDestroyCount+", has "+destroyCount+"]"+(expDestroyCount!=destroyCount?"*":""));
+ ", destroy[exp "+expDestroyCount+", has "+destroyCount+"]"+(expDestroyCount!=destroyCount.get()?"*":""));
}
private class MyCanvas extends Canvas {
@@ -160,7 +161,7 @@ public class DemoBug910ExtendedAWTAppletLifecycleCheck extends Applet {
public void init() {
final java.awt.Dimension aSize = getSize();
println("Applet.init() START - applet.size "+aSize+" - "+currentThreadName());
- initCount++;
+ initCount.incrementAndGet();
checkAppletState("init", false /* expIsActive */, 1 /* expInitCount */,
0 /* expStartCount */, 0 /* expStopCount */, true /* startStopCountEquals */,
0 /* expDestroyCount */);
@@ -182,9 +183,9 @@ public class DemoBug910ExtendedAWTAppletLifecycleCheck extends Applet {
@Override
public void start() {
println("Applet.start() START (isVisible "+isVisible()+", isDisplayable "+isDisplayable()+") - "+currentThreadName());
- startCount++;
+ startCount.incrementAndGet();
checkAppletState("start", true /* expIsActive */, 1 /* expInitCount */,
- startCount /* expStartCount */, startCount-1 /* expStopCount */, false /* startStopCountEquals */,
+ startCount.get() /* expStartCount */, startCount.get()-1 /* expStopCount */, false /* startStopCountEquals */,
0 /* expDestroyCount */);
invoke(true, new Runnable() {
public void run() {
@@ -204,9 +205,9 @@ public class DemoBug910ExtendedAWTAppletLifecycleCheck extends Applet {
@Override
public void stop() {
println("Applet.stop() START - "+currentThreadName());
- stopCount++;
+ stopCount.incrementAndGet();
checkAppletState("stop", false /* expIsActive */, 1 /* expInitCount */,
- stopCount /* expStartCount */, stopCount /* expStopCount */, true /* startStopCountEquals */,
+ stopCount.get() /* expStartCount */, stopCount.get() /* expStopCount */, true /* startStopCountEquals */,
0 /* expDestroyCount */);
invoke(true, new Runnable() {
public void run() {
@@ -218,9 +219,9 @@ public class DemoBug910ExtendedAWTAppletLifecycleCheck extends Applet {
@Override
public void destroy() {
println("Applet.destroy() START - "+currentThreadName());
- destroyCount++;
+ destroyCount.incrementAndGet();
checkAppletState("destroy", false /* expIsActive */, 1 /* expInitCount */,
- startCount /* expStartCount */, stopCount /* expStopCount */, true /* startStopCountEquals */,
+ startCount.get() /* expStartCount */, stopCount.get() /* expStopCount */, true /* startStopCountEquals */,
1 /* expDestroyCount */);
invoke(true, new Runnable() {
public void run() {
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
index 3900817c5..1fc8372c8 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextSurfaceLockNEWT.java
@@ -29,6 +29,7 @@
package com.jogamp.opengl.test.junit.jogl.acore;
import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GLAutoDrawable;
@@ -152,8 +153,8 @@ public class TestGLContextSurfaceLockNEWT extends UITestCase {
}
protected class MyEventCounter implements GLEventListener {
- volatile int reshapeCount = 0;
- volatile int displayCount = 0;
+ AtomicInteger reshapeCount = new AtomicInteger(0);
+ AtomicInteger displayCount = new AtomicInteger(0);
@Override
public void init(final GLAutoDrawable drawable) {
@@ -166,17 +167,17 @@ public class TestGLContextSurfaceLockNEWT extends UITestCase {
@Override
public void display(final GLAutoDrawable drawable) {
- displayCount++;
+ displayCount.incrementAndGet();
}
@Override
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
- reshapeCount++;
+ reshapeCount.incrementAndGet();
}
public void reset() {
- reshapeCount = 0;
- displayCount = 0;
+ reshapeCount.set(0);
+ displayCount.set(0);
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java
index 33c918b66..92785ef6e 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/perf/TestPerf001GLJPanelInit01AWT.java
@@ -31,6 +31,7 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
@@ -87,7 +88,7 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase {
UITestCase.waitForKey("Pre-Init");
}
System.err.println("INIT START");
- initCount = 0;
+ initCount.set(0);
try {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
@@ -97,7 +98,7 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase {
glad.addGLEventListener(new GLEventListener() {
@Override
public void init(final GLAutoDrawable drawable) {
- initCount++;
+ initCount.getAndIncrement();
}
@Override
public void dispose(final GLAutoDrawable drawable) {}
@@ -122,24 +123,24 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase {
}
final long t0 = System.currentTimeMillis();
long t1 = t0;
- while( panelCount > initCount && INIT_TIMEOUT > t1 - t0 ) {
+ while( panelCount > initCount.get() && INIT_TIMEOUT > t1 - t0 ) {
try {
Thread.sleep(100);
- System.err.println("Sleep initialized: "+initCount+"/"+panelCount);
+ System.err.println("Sleep initialized: "+initCount.get()+"/"+panelCount);
} catch (final InterruptedException e1) {
e1.printStackTrace();
}
t1 = System.currentTimeMillis();
}
t[3] = Platform.currentTimeMillis();
- final double panelCountF = initCount;
+ final double panelCountF = initCount.get();
System.err.printf("P: %d %s:%n\tctor\t%6d/t %6.2f/1%n\tvisible\t%6d/t %6.2f/1%n\tsum-i\t%6d/t %6.2f/1%n",
- initCount,
+ initCount.get(),
useGLJPanel?"GLJPanel":"GLCanvas",
t[1]-t[0], (t[1]-t[0])/panelCountF,
t[3]-t[1], (t[3]-t[1])/panelCountF,
t[3]-t[0], (t[3]-t[0])/panelCountF);
- System.err.println("INIT END: "+initCount+"/"+panelCount);
+ System.err.println("INIT END: "+initCount.get()+"/"+panelCount);
if( wait ) {
UITestCase.waitForKey("Post-Init");
}
@@ -211,7 +212,7 @@ public class TestPerf001GLJPanelInit01AWT extends UITestCase {
static boolean wait = false;
static int width = 800, height = 600, rows = 5, cols = 5;
- volatile int initCount = 0;
+ AtomicInteger initCount = new AtomicInteger(0);
public static void main(final String[] args) {
boolean useGLJPanel = true, useGears = false, manual=false;
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java
index 6fa070b07..27d095a11 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/event/BaseNewtEventModifiers.java
@@ -30,6 +30,7 @@ package com.jogamp.opengl.test.junit.newt.event ;
import java.io.PrintStream ;
import java.util.ArrayList ;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.media.opengl.GLProfile ;
@@ -86,7 +87,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
private boolean _modifierCheckEnabled ;
private int _expectedModifiers;
- private volatile int _eventCount ;
+ private final AtomicInteger _eventCount = new AtomicInteger(0);
private ArrayList<String> _failures = new ArrayList<String>() ;
public synchronized void setModifierCheckEnabled( final boolean value ) {
@@ -112,7 +113,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
public synchronized ArrayList<String> clear() {
final ArrayList<String> old = _failures;
- _eventCount = 0;
+ _eventCount.set(0);
// Assume we will have a failure due to no event delivery.
// If an event is delivered and it's good this assumed
@@ -124,10 +125,10 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
public ArrayList<String> getFailures(final int waitEventCount) {
int j;
- for(j=0; j < 20 && _eventCount < waitEventCount; j++) { // wait until events are collected
+ for(j=0; j < 20 && _eventCount.get() < waitEventCount; j++) { // wait until events are collected
_robot.delay(MS_ROBOT_AUTO_DELAY);
}
- if(0 == _eventCount) {
+ if(0 == _eventCount.get()) {
_debugPrintStream.println("**** No Event. Waited "+j+" * "+MS_ROBOT_AUTO_DELAY+"ms, eventCount "+_eventCount);
}
return clear();
@@ -177,7 +178,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
}
public synchronized void mousePressed( final com.jogamp.newt.event.MouseEvent event ) {
- _eventCount++;
+ _eventCount.incrementAndGet();
if( _debug ) {
_debugPrintStream.println( "MousePressed "+_eventCount+": "+event);
}
@@ -185,7 +186,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
}
public synchronized void mouseReleased( final com.jogamp.newt.event.MouseEvent event ) {
- _eventCount++;
+ _eventCount.incrementAndGet();
if( _debug ) {
_debugPrintStream.println( "MouseReleased "+_eventCount+": "+event);
}
@@ -193,7 +194,7 @@ public abstract class BaseNewtEventModifiers extends UITestCase {
}
public synchronized void mouseDragged( final com.jogamp.newt.event.MouseEvent event ) {
- _eventCount++;
+ _eventCount.incrementAndGet();
if( _debug ) {
_debugPrintStream.println( "MouseDragged "+_eventCount+": "+event);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
index 318ba17f1..31d6b887d 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -33,6 +33,7 @@ import jogamp.newt.awt.event.AWTNewtEventFactory;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.atomic.AtomicInteger;
import java.awt.AWTException;
import java.awt.EventQueue;
import java.awt.Robot;
@@ -864,31 +865,31 @@ public class AWTRobotUtil {
static class AWTWindowClosingAdapter
extends java.awt.event.WindowAdapter implements WindowClosingListener
{
- volatile int closing = 0;
- volatile int closed = 0;
+ AtomicInteger closing = new AtomicInteger(0);
+ AtomicInteger closed = new AtomicInteger(0);
public void reset() {
- closing = 0;
- closed = 0;
+ closing.set(0);
+ closed.set(0);
}
public int getWindowClosingCount() {
- return closing;
+ return closing.get();
}
public int getWindowClosedCount() {
- return closed;
+ return closed.get();
}
public boolean isWindowClosing() {
- return 0 < closing;
+ return 0 < closing.get();
}
public boolean isWindowClosed() {
- return 0 < closed;
+ return 0 < closed.get();
}
public void windowClosing(final java.awt.event.WindowEvent e) {
- closing++;
+ closing.incrementAndGet();
System.err.println("AWTWindowClosingAdapter.windowClosing: "+this);
}
public void windowClosed(final java.awt.event.WindowEvent e) {
- closed++;
+ closed.incrementAndGet();
System.err.println("AWTWindowClosingAdapter.windowClosed: "+this);
}
public String toString() {
@@ -898,31 +899,31 @@ public class AWTRobotUtil {
static class NEWTWindowClosingAdapter
extends com.jogamp.newt.event.WindowAdapter implements WindowClosingListener
{
- volatile int closing = 0;
- volatile int closed = 0;
+ AtomicInteger closing = new AtomicInteger(0);
+ AtomicInteger closed = new AtomicInteger(0);
public void reset() {
- closing = 0;
- closed = 0;
+ closing.set(0);
+ closed.set(0);
}
public int getWindowClosingCount() {
- return closing;
+ return closing.get();
}
public int getWindowClosedCount() {
- return closed;
+ return closed.get();
}
public boolean isWindowClosing() {
- return 0 < closing;
+ return 0 < closing.get();
}
public boolean isWindowClosed() {
- return 0 < closed;
+ return 0 < closed.get();
}
public void windowDestroyNotify(final WindowEvent e) {
- closing++;
+ closing.incrementAndGet();
System.err.println("NEWTWindowClosingAdapter.windowDestroyNotify: "+this);
}
public void windowDestroyed(final WindowEvent e) {
- closed++;
+ closed.incrementAndGet();
System.err.println("NEWTWindowClosingAdapter.windowDestroyed: "+this);
}
public String toString() {
diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
index 0044a5708..a1e2b19d3 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
@@ -39,6 +39,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.opengl.GL;
@@ -361,8 +362,8 @@ public abstract class UITestCase {
private volatile boolean makeShot = false;
private volatile boolean makeShotAlways = false;
private volatile boolean verbose = false;
- private volatile int displayCount=0;
- private volatile int reshapeCount=0;
+ private final AtomicInteger displayCount = new AtomicInteger(0);
+ private final AtomicInteger reshapeCount = new AtomicInteger(0);
private volatile String postSNDetail = null;
public SnapshotGLEventListener(final GLReadBufferUtil screenshot) {
this.screenshot = screenshot;
@@ -370,8 +371,8 @@ public abstract class UITestCase {
public SnapshotGLEventListener() {
this.screenshot = new GLReadBufferUtil(false, false);
}
- public int getDisplayCount() { return displayCount; }
- public int getReshapeCount() { return reshapeCount; }
+ public int getDisplayCount() { return displayCount.get(); }
+ public int getReshapeCount() { return reshapeCount.get(); }
public GLReadBufferUtil getGLReadBufferUtil() { return screenshot; }
public void init(final GLAutoDrawable drawable) {}
public void dispose(final GLAutoDrawable drawable) {}
@@ -383,15 +384,15 @@ public abstract class UITestCase {
}
if(_makeShot) {
makeShot=false;
- snapshot(displayCount, postSNDetail, gl, screenshot, TextureIO.PNG, null);
+ snapshot(displayCount.get(), postSNDetail, gl, screenshot, TextureIO.PNG, null);
}
- displayCount++;
+ displayCount.incrementAndGet();
}
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
if(verbose) {
System.err.println(Thread.currentThread().getName()+": ** reshape: "+reshapeCount+": "+width+"x"+height+" - "+drawable.getSurfaceWidth()+"x"+drawable.getSurfaceHeight());
}
- reshapeCount++;
+ reshapeCount.incrementAndGet();
}
public void setMakeSnapshot() {
makeShot=true;