summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-07-09 21:47:50 +0200
committerSven Gothel <[email protected]>2013-07-09 21:47:50 +0200
commit1bf8c73cb5c76c0ecd7bf7a97cdde990b3ad384e (patch)
treef4b618411201f35ad1788d892f91113fb11d9a75 /src/test/com/jogamp
parent18df35aa301c29bc6a85f8f8eabe0bd9407d8be6 (diff)
UITestCase.resetXRandRIfX11(): Iterate through all outputs and sets the preferred mode and normal rotation using RandR 1.3
.. using commandline processing w/ 'xrandr'
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java24
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java55
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/UITestCase.java110
3 files changed, 167 insertions, 22 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java
index c2cb88b1c..461b3e1fa 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java
@@ -185,16 +185,18 @@ public class TestScreenMode00cNEWT extends UITestCase {
Assert.assertEquals(true,window0.isNativeValid());
Assert.assertEquals(true,window0.isVisible());
+ // WARNING: See note in 'UITestCase.resetXRandRIfX11();'
UITestCase.resetXRandRIfX11();
System.err.println("XRandR Reset :"+monitor.queryCurrentMode());
- validateScreenModeReset(mmOrig, 0);
+ validateScreenModeReset0(mmOrig);
destroyWindow(window0);
Thread.sleep(waitTimeShort);
+ validateScreenModeReset(mmOrig);
}
- void validateScreenModeReset(final MonitorMode mmOrig, int mmIdx) {
+ void validateScreenModeReset0(final MonitorMode mmOrig) {
final Display display = NewtFactory.createDisplay(null); // local display
Assert.assertNotNull(display);
final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
@@ -208,6 +210,24 @@ public class TestScreenMode00cNEWT extends UITestCase {
screen.removeReference();
}
+ void validateScreenModeReset(final MonitorMode mmOrig) {
+ final Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ screen.addReference();
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ final MonitorDevice monitor = screen.getMonitorDevices().get(0);
+ Assert.assertEquals(mmOrig, monitor.getCurrentMode());
+
+ screen.removeReference();
+ Assert.assertEquals(false,display.isNativeValid());
+ Assert.assertEquals(false,screen.isNativeValid());
+ }
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
index 5717335b7..f83cb515e 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
@@ -33,9 +33,12 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.lang.reflect.*;
import java.nio.FloatBuffer;
+import com.jogamp.common.os.Platform;
+
public class MiscUtils {
public static boolean atob(String str, boolean def) {
try {
@@ -155,27 +158,55 @@ public class MiscUtils {
public static class StreamDump extends Thread {
final InputStream is;
- final String prefix;
+ final StringBuilder outString;
+ final OutputStream outStream;
+ final String prefix;
+ final Object sync;
+ volatile boolean eos = false;
- public StreamDump(InputStream is, String prefix) {
+ public StreamDump(OutputStream out, String prefix, InputStream is, Object sync) {
this.is = is;
+ this.outString = null;
+ this.outStream = out;
this.prefix = prefix;
+ this.sync = sync;
+ }
+ public StreamDump(StringBuilder sb, InputStream is, Object sync) {
+ this.is = is;
+ this.outString = sb;
+ this.outStream = null;
+ this.prefix = null;
+ this.sync = sync;
}
+
+ public final boolean eos() { return eos; }
@Override
public void run() {
- try {
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- String line = null;
- while ((line = br.readLine()) != null) {
- System.out.println(prefix + "> " + line);
+ synchronized ( sync ) {
+ try {
+ final BufferedReader in = new BufferedReader( new InputStreamReader(is) );
+ String line = null;
+ while ((line = in.readLine()) != null) {
+ if( null != outString ) {
+ outString.append(line).append(Platform.getNewline());
+ } else if( null != outStream ) {
+ if( null != prefix ) {
+ outStream.write(prefix.getBytes());
+ }
+ outStream.write(line.getBytes());
+ outStream.write(Platform.getNewline().getBytes());
+ outStream.flush();
+ }
+ }
+ } catch (IOException ioe) {
+ System.err.println("Catched "+ioe.getClass().getName()+": "+ioe.getMessage());
+ ioe.printStackTrace();
+ } finally {
+ eos = true;
+ sync.notifyAll();
}
}
- catch (IOException ioe) {
- System.err.println("Catched "+ioe.getClass().getName()+": "+ioe.getMessage());
- ioe.printStackTrace();
- }
}
}
}
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 d2ed7cd1e..839a0c7b8 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
@@ -32,8 +32,13 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.StringTokenizer;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.opengl.GL;
@@ -96,23 +101,112 @@ public abstract class UITestCase {
resetXRandRIfX11AfterClass = true;
}
+ /**
+ * Iterates through all outputs and sets the preferred mode and normal rotation using RandR 1.3.
+ * <p>
+ * With NV drivers, one need to add the Modes in proper order to the Screen's Subsection "Display",
+ * otherwise they are either in unsorted resolution order or even n/a!
+ * </p>
+ */
+ @SuppressWarnings("unused")
public static void resetXRandRIfX11() {
if( NativeWindowFactory.isInitialized() && NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(true) ) {
try {
- final ProcessBuilder pb = new ProcessBuilder("xrandr", "-s", "0", "-o", "normal");
- pb.redirectErrorStream(true);
- System.err.println("XRandR Reset cmd: "+pb.command());
- final Process p = pb.start();
- new MiscUtils.StreamDump( p.getInputStream(), "xrandr-reset" ).start();
- p.waitFor();
- System.err.println("XRandR Reset result "+p.exitValue());
+ final List<String> outputDevices = new ArrayList<String>();
+ // final List<String> outputSizes = new ArrayList<String>();
+ final Object ioSync = new Object();
+ synchronized ( ioSync ) {
+ final StringBuilder out = new StringBuilder();
+ final ProcessBuilder pb = new ProcessBuilder("xrandr", "-q");
+ pb.redirectErrorStream(true);
+ System.err.println("XRandR Query: "+pb.command());
+ final Process p = pb.start();
+ final MiscUtils.StreamDump dump = new MiscUtils.StreamDump( out, p.getInputStream(), ioSync );
+ dump.start();
+ while( !dump.eos() ) {
+ ioSync.wait();
+ }
+ p.waitFor(); // should be fine by now ..
+ final int errorCode = p.exitValue();
+ if( 0 == errorCode ) {
+ // Parse connected output devices !
+ final BufferedReader in = new BufferedReader( new StringReader( out.toString() ) );
+ String line = null;
+ while ( ( line = in.readLine() ) != null) {
+ final String lline = line.toLowerCase();
+ if( lline.contains("connected") && !lline.contains("disconnected") ) {
+ final String od = getFirst(line);
+ if( null != od ) {
+ outputDevices.add( od );
+ /**
+ if ( ( line = in.readLine() ) != null ) {
+ outputSizes.add( getFirst(line) );
+ } else {
+ outputSizes.add( null );
+ } */
+ }
+ }
+ }
+ } else {
+ System.err.println("XRandR Query Error Code "+errorCode);
+ System.err.println(out.toString());
+ }
+ }
+ for(int i=0; i<outputDevices.size(); i++) {
+ final String outputDevice = outputDevices.get(i);
+ final String outputSize = null; // outputSizes.get(i);
+ final String[] cmdline;
+ if( null != outputSize ) {
+ cmdline = new String[] { "xrandr", "--output", outputDevice, "--mode", outputSize, "--rotate", "normal" };
+ } else {
+ cmdline = new String[] { "xrandr", "--output", outputDevice, "--preferred", "--rotate", "normal" };
+ }
+ System.err.println("XRandR Reset: "+Arrays.asList(cmdline));
+ final int errorCode = processCommand(cmdline, System.err, "xrandr-reset> ");
+ if( 0 != errorCode ) {
+ System.err.println("XRandR Reset Error Code "+errorCode);
+ }
+ }
} catch (Exception e) {
System.err.println("Catched "+e.getClass().getName()+": "+e.getMessage());
e.printStackTrace();
}
- System.err.println("XRandR Reset done");
}
}
+ private static String getFirst(String line) {
+ final StringTokenizer tok = new StringTokenizer(line);
+ if( tok.hasMoreTokens() ) {
+ final String s = tok.nextToken().trim();
+ if( s.length() > 0 ) {
+ return s;
+ }
+ }
+ return null;
+ }
+
+ public static int processCommand(String[] cmdline, OutputStream outstream, String outPrefix) {
+ int errorCode = 0;
+ final Object ioSync = new Object();
+ try {
+ synchronized ( ioSync ) {
+ final ProcessBuilder pb = new ProcessBuilder(cmdline);
+ pb.redirectErrorStream(true);
+ final Process p = pb.start();
+ final MiscUtils.StreamDump dump = new MiscUtils.StreamDump( outstream, outPrefix, p.getInputStream(), ioSync);
+ dump.start();
+ while( !dump.eos() ) {
+ ioSync.wait();
+ }
+ p.waitFor(); // should be fine by now ..
+ errorCode = p.exitValue();
+ }
+ } catch (Exception e) {
+ System.err.println("Catched "+e.getClass().getName()+": "+e.getMessage());
+ e.printStackTrace();
+ errorCode = Integer.MIN_VALUE;
+ }
+ return errorCode;
+ }
public int getMaxTestNameLen() {
if(0 == maxMethodNameLen) {