hotspot/test/runtime/ErrorHandling/ErrorHandler.java
changeset 33135 aa536100693c
child 38152 80e5da81fb2c
equal deleted inserted replaced
33130:a776072941e8 33135:aa536100693c
       
     1 /*
       
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 6888954
       
    27  * @bug 8015884
       
    28  * @summary Exercise HotSpot error handling code by invoking java with
       
    29  *          -XX:ErrorHandlerTest option to cause an error report. Check the results.
       
    30  * @library /testlibrary
       
    31  * @run driver ErrorHandler
       
    32  */
       
    33 
       
    34 import jdk.test.lib.*;
       
    35 
       
    36 public class ErrorHandler {
       
    37 
       
    38     public static OutputAnalyzer runTest(int testcase) throws Exception {
       
    39         return new OutputAnalyzer(
       
    40             ProcessTools.createJavaProcessBuilder(
       
    41             "-XX:-TransmitErrorReport", "-XX:-CreateCoredumpOnCrash", "-XX:ErrorHandlerTest=" + testcase)
       
    42             .start());
       
    43     }
       
    44 
       
    45     public static void main(String[] args) throws Exception {
       
    46         // Test is only applicable for debug builds
       
    47         if (!Platform.isDebugBuild()) {
       
    48             return;
       
    49         }
       
    50         // Keep this in sync with hotspot/src/share/vm/utilities/debug.cpp
       
    51         int i = 1;
       
    52         String[] strings = {
       
    53             "assert(str == NULL) failed: expected null",
       
    54             "assert(num == 1023 && *str == 'X') failed: num=",
       
    55             "guarantee(str == NULL) failed: expected null",
       
    56             "guarantee(num == 1023 && *str == 'X') failed: num=",
       
    57             "fatal error: expected null",
       
    58             "fatal error: num=",
       
    59             "fatal error: this message should be truncated during formatting",
       
    60             "ChunkPool::allocate",
       
    61             "Error: ShouldNotCall()",
       
    62             "Error: ShouldNotReachHere()",
       
    63             "Error: Unimplemented()"
       
    64         };
       
    65 
       
    66         String[] patterns = {
       
    67             "(SIGILL|SIGSEGV|EXCEPTION_ACCESS_VIOLATION).* at pc=",
       
    68             "(SIGBUS|SIGSEGV|SIGILL|EXCEPTION_ACCESS_VIOLATION).* at pc="
       
    69         };
       
    70 
       
    71         for (String s : strings) {
       
    72             runTest(i++).shouldContain(s);
       
    73         }
       
    74 
       
    75         for (String p : patterns) {
       
    76             runTest(i++).shouldMatch(p);
       
    77         }
       
    78     }
       
    79 }