hotspot/test/runtime/ErrorHandling/SecondaryErrorTest.java
author stefank
Wed, 20 Apr 2016 09:58:15 +0200
changeset 38000 7519aefb5b86
parent 36851 03e2f4d0a421
child 40631 ed82623d7831
permissions -rw-r--r--
8079843: do_young_space_rescan - comment out of sync with code Reviewed-by: mgerdin, sjohanss, ehelin, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     1
/*
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     4
 *
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     7
 * published by the Free Software Foundation.
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     8
 *
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    13
 * accompanied this code).
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    14
 *
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    18
 *
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    21
 * questions.
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    22
 */
28944
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    23
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    24
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    25
/*
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    26
 * @test
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    27
 * @bug 8065896
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    28
 * @summary Synchronous signals during error reporting may terminate or hang VM process
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    29
 * @library /testlibrary
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    30
 * @author Thomas Stuefe (SAP)
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 34144
diff changeset
    31
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28944
diff changeset
    32
 *          java.management
28944
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    33
 */
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    34
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    35
import java.io.BufferedReader;
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    36
import java.io.File;
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    37
import java.io.FileInputStream;
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    38
import java.io.InputStreamReader;
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    39
import java.util.regex.Pattern;
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    40
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    41
import jdk.test.lib.OutputAnalyzer;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    42
import jdk.test.lib.Platform;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 30240
diff changeset
    43
import jdk.test.lib.ProcessTools;
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    44
28944
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    45
public class SecondaryErrorTest {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    46
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    47
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    48
  public static void main(String[] args) throws Exception {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    49
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    50
    // Do not execute for windows, nor for non-debug builds
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    51
    if (Platform.isWindows()) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    52
      return;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    53
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    54
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    55
    if (!Platform.isDebugBuild()) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    56
      return;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    57
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    58
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    59
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    60
        "-XX:+UnlockDiagnosticVMOptions",
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    61
        "-Xmx100M",
30240
a7ba42fa1df6 8074354: Make CreateMinidumpOnCrash a new name and available on all platforms
minqi
parents: 29678
diff changeset
    62
        "-XX:-CreateCoredumpOnCrash",
28944
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    63
        "-XX:ErrorHandlerTest=15",
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    64
        "-XX:TestCrashInErrorHandler=14",
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    65
        "-version");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    66
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    67
    OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    68
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    69
    // we should have crashed with a SIGFPE
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    70
    output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    71
    output_detail.shouldMatch("# +SIGFPE.*");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    72
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    73
    // extract hs-err file
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    74
    String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    75
    if (hs_err_file == null) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    76
      throw new RuntimeException("Did not find hs-err file in output.\n");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    77
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    78
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    79
    // scan hs-err file: File should contain the "[error occurred during error reporting..]"
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    80
    // markers which show that the secondary error handling kicked in and handled the
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    81
    // error successfully. As an added test, we check that the last line contains "END.",
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    82
    // which is an end marker written in the last step and proves that hs-err file was
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    83
    // completely written.
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    84
    File f = new File(hs_err_file);
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    85
    if (!f.exists()) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    86
      throw new RuntimeException("hs-err file missing at "
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    87
          + f.getAbsolutePath() + ".\n");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    88
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    89
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    90
    System.out.println("Found hs_err file. Scanning...");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    91
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    92
    FileInputStream fis = new FileInputStream(f);
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    93
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    94
    String line = null;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    95
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    96
    Pattern [] pattern = new Pattern[] {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    97
        Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    98
        Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 1\\).*\\]"),
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
    99
        Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   100
        Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 2\\).*\\]"),
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   101
    };
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   102
    int currentPattern = 0;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   103
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   104
    String lastLine = null;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   105
    while ((line = br.readLine()) != null) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   106
      if (currentPattern < pattern.length) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   107
        if (pattern[currentPattern].matcher(line).matches()) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   108
          System.out.println("Found: " + line + ".");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   109
          currentPattern ++;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   110
        }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   111
      }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   112
      lastLine = line;
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   113
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   114
    br.close();
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   115
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   116
    if (currentPattern < pattern.length) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   117
      throw new RuntimeException("hs-err file incomplete (first missing pattern: " +  currentPattern + ")");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   118
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   119
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   120
    if (!lastLine.equals("END.")) {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   121
      throw new RuntimeException("hs-err file incomplete (missing END marker.)");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   122
    } else {
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   123
      System.out.println("End marker found.");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   124
    }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   125
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   126
    System.out.println("OK.");
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   127
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   128
  }
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   129
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   130
}
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   131
0fce29a072f1 8072575: Add missing test for 8065895
dholmes
parents:
diff changeset
   132