# HG changeset patch # User yan # Date 1462871707 -10800 # Node ID bbecc75e452179ba7bb9a8e96ed9852c1ea6985c # Parent add132f897cf882ba3e5cd6a2104bb434206e3f5 8156128: Tests for [AWT/Swing] Conditional support for GTK 3 on Linux Reviewed-by: prr diff -r add132f897cf -r bbecc75e4521 jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK.java Tue May 10 12:15:07 2016 +0300 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @summary Tests that GTK LaF is supported on solaris + regardless of jdk.gtk.version flag values. + @bug 8156121 + @requires (os.name == "linux" | os.name == "solaris") + @run main/othervm -Djdk.gtk.version=2 DemandGTK + @run main/othervm -Djdk.gtk.version=3 DemandGTK +*/ + +import javax.swing.JFrame; +import javax.swing.UIManager; +import javax.swing.SwingUtilities; +import java.awt.Robot; + +public class DemandGTK { + + static JFrame frame; + public static void createAndShow() { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); + } catch(Exception cnf) { + cnf.printStackTrace(); + throw new RuntimeException("GTK LaF must be supported"); + } + frame = new JFrame("JFrame"); + frame.setSize(200, 200); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(DemandGTK::createAndShow); + Robot robot = new Robot(); + robot.waitForIdle(); + robot.delay(1000); + SwingUtilities.invokeAndWait( () -> { + frame.setVisible(false); + frame.dispose(); + }); + + } +} + diff -r add132f897cf -r bbecc75e4521 jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK2.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK2.sh Tue May 10 12:15:07 2016 +0300 @@ -0,0 +1,89 @@ +#!/bin/ksh -p + +# +# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# @test +# @summary Try to force GTK2. We must bail out to GTK3 (if any) if no 2 available. +# +# @compile ProvokeGTK.java +# @requires os.family == "linux" +# @run shell/timeout=400 DemandGTK2.sh + +# +# Note that we depend on +# strace in the PATH +# /sbin/ldconfig (which may be not in PATH) +# It is true for OEL 7 and Ubuntu 14, 16 +# but may fail in future. Save tomorrow for tomorrow. +# +# Read DemandGTK2.txt how to prepare GTK2-less machine. +# + +which strace +if [ $? -ne 0 ] +then + echo "Please provide strace: \"which strace\" failed." + exit 1 +fi + +HAVE_2=`/sbin/ldconfig -v 2>/dev/null | grep libgtk-x11-2 | wc -l` +HAVE_3=`/sbin/ldconfig -v 2>/dev/null | grep libgtk-3.so | wc -l` + + +if [ "${HAVE_2}" = "0" ] +then + + if [ "${HAVE_3}" = "0" ] + then + echo "Neither GTK2 nor GTK3 found: system misconfiguration. Exit." + exit 1 + fi + echo "No GTK 2 library found: we should bail out to 3" + strace -o strace.log -fe open ${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} -Djdk.gtk.version=2 ProvokeGTK + EXECRES=$? + grep 'libgtk-3.*=\ *[0-9]*$' strace.log > logg +else + echo "There is GTK 2 library: we should use it" + strace -o strace.log -fe open ${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} -Djdk.gtk.version=2 ProvokeGTK + EXECRES=$? + grep 'libgtk-x11.*=\ *[0-9]*$' strace.log > logg +fi + +if [ ${EXECRES} -ne 0 ] +then + echo "java execution failed for unknown reason, see logs" + exit 2 +fi + +cat logg +if [ -s logg ] +then + echo "Success." + exit 0 +else + echo "Failed. Examine logs." + exit 3 +fi + + diff -r add132f897cf -r bbecc75e4521 jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK2.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK2.txt Tue May 10 12:15:07 2016 +0300 @@ -0,0 +1,36 @@ +How to prepare an Ubuntu machine for GTK-2-less test run. + +The test DemandGTK2.sh should work well without GTK-2 switching to version 3 +if there's no GTK-2 library available. +At the moment, it's not easy to find a system with GTK-3 and without GTK-2: +many programs still depend on version 2. +We can, however, rename GTK-2 library for a single test run and then restore +it back. + +(1) Find GTK2 library: run + /sbin/ldconfig -v 2>/dev/null | grep libgtk-x11-2 + +It will output one or two lines like +libgtk-x11-2.0.so.0 -> libgtk-x11-2.0.so.0.2400.23 +Search for the target of that symlink for instance with locate: +locate libgtk-x11-2.0.so.0.2400.23 +Finally, you'll find the libraries. On my current machine they are +/usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0.2400.23 +/usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23 + +I'm running 64-bit JDK and need to tamper with x86_64 copy only. + +(2) Find running programs depending on this library. They probably would crash +if you rename it. Stop them for this test run. +That said, I'm afraid it would be impossible to do on a system older than Ubuntu 16.04. +On my Ubuntu 16.04 I have only hud-service using this library, and that's OK, it will restart +after a crash, if any. +To find these programs, run +lsof /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23 + +(3) Now, +sudo mv /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23 /usr/lib/x86_64-linux-gnu/bak.libgtk-x11-2.0.so.0.2400.23 +jtreg DemandGTK2.sh +sudo mv /usr/lib/x86_64-linux-gnu/bak.libgtk-x11-2.0.so.0.2400.23 /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.23 + +Needless to say, you should substitute your own library path and however you run jtreg. diff -r add132f897cf -r bbecc75e4521 jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK3.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/LookAndFeel/8145547/DemandGTK3.sh Tue May 10 12:15:07 2016 +0300 @@ -0,0 +1,81 @@ +#!/bin/ksh -p + +# +# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + + +# @test +# @summary Try to force GTK3. We must bail out to GTK2 if no 3 available. +# +# @compile ProvokeGTK.java +# @requires os.family == "linux" +# @run shell/timeout=400 DemandGTK3.sh + +# +# Note that we depend on +# strace in the PATH +# /sbin/ldconfig (which may be is not in PATH) +# It is true for OEL 7 and Ubuntu 14, 16 +# but may fail in future. Save tomorrow for tomorrow. +# + +which strace +if [ $? -ne 0 ] +then + echo "Please provide strace: \"which strace\" failed." + exit 1 +fi + +HAVE_3=`/sbin/ldconfig -v 2>/dev/null | grep libgtk-3.so | wc -l` + + +if [ "${HAVE_3}" = "0" ] +then + + echo "No GTK 3 library found: we should bail out to 2" + strace -o strace.log -fe open ${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} -Djdk.gtk.version=3 ProvokeGTK + EXECRES=$? + grep 'libgtk-x11.*=\ *[0-9]*$' strace.log > logg +else + echo "There is GTK 3 library: we should use it" + strace -o strace.log -fe open ${TESTJAVA}/bin/java -cp ${TESTCLASSPATH} -Djdk.gtk.version=3 ProvokeGTK + EXECRES=$? + grep 'libgtk-3.*=\ *[0-9]*$' strace.log > logg +fi + +if [ ${EXECRES} -ne 0 ] +then + echo "java execution failed for unknown reason, see logs" + exit 2 +fi + +cat logg +if [ -s logg ] +then + echo "Success." + exit 0 +else + echo "Failed. Examine logs." + exit 3 +fi + diff -r add132f897cf -r bbecc75e4521 jdk/test/javax/swing/LookAndFeel/8145547/ProvokeGTK.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/javax/swing/LookAndFeel/8145547/ProvokeGTK.java Tue May 10 12:15:07 2016 +0300 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JFrame; +import javax.swing.UIManager; +import javax.swing.SwingUtilities; + +public class ProvokeGTK { + + static JFrame frame; + public static void createAndShow() { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); + } catch(Exception cnf) { + cnf.printStackTrace(); + } + frame = new JFrame("JFrame"); + frame.setSize(200, 200); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws Exception { + SwingUtilities.invokeAndWait(ProvokeGTK::createAndShow); + Thread.sleep(1000); + SwingUtilities.invokeAndWait( () -> { + frame.setVisible(false); + frame.dispose(); + }); + + } +} +