test/jdk/java/awt/FullScreen/UninitializedDisplayModeChangeTest/UninitializedDisplayModeChangeTest.java
author pnarayanan
Fri, 02 Mar 2018 14:39:29 +0530
changeset 49217 3b820b878ebe
parent 49096 eaef201ec301
child 49685 26bd5cc412e1
permissions -rw-r--r--
8198613: Test cases result in failure or timeout when run with OpenGL backend Reviewed-by: serb, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49217
3b820b878ebe 8198613: Test cases result in failure or timeout when run with OpenGL backend
pnarayanan
parents: 49096
diff changeset
     2
 * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
49217
3b820b878ebe 8198613: Test cases result in failure or timeout when run with OpenGL backend
pnarayanan
parents: 49096
diff changeset
    26
 * @bug 6358034 6568560 8198613
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    27
 * @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Tests that no exception is thrown when display mode is changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          externally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @compile UninitializedDisplayModeChangeTest.java DisplayModeChanger.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run main/othervm UninitializedDisplayModeChangeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class UninitializedDisplayModeChangeTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static volatile boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            EventQueue.invokeAndWait(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                    Thread.currentThread().setDefaultUncaughtExceptionHandler(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                        new Thread.UncaughtExceptionHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                            public void uncaughtException(Thread t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                                          Throwable e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                System.err.println("Exception Detected:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        } catch (InterruptedException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        } catch (InvocationTargetException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        Process childProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        String classPath = System.getProperty("java.class.path" , ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        String cmd = new String(System.getProperty("java.home") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                "bin" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                File.separator +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                "java -cp " + classPath +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                " DisplayModeChanger");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        System.out.println("Launching the display mode changer process");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        System.out.println("cmd="+cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            childProc = Runtime.getRuntime().exec(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            StreamProcessor err =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                new StreamProcessor("stderr", childProc.getErrorStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            StreamProcessor out =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                new StreamProcessor("stdout", childProc.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            err.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            out.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            childProc.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new RuntimeException("Test Failed: exception detected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        System.out.println("Test Passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static class StreamProcessor extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        InputStream is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        String inputType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        StreamProcessor(String inputType, InputStream is) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            this.inputType = inputType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            this.is = is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                InputStreamReader isr = new InputStreamReader(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                BufferedReader br = new BufferedReader(isr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                String line = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                while ( (line = br.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    System.out.println("Display Changer "+inputType+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                       " output > " + line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                ioe.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}