Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/SecondaryErrorTest.java
40942 views
/*1* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/*25* @test26* @bug 806589627* @summary Synchronous signals during error reporting may terminate or hang VM process28* @library /test/lib29* @requires vm.debug30* @requires os.family != "windows"31* @author Thomas Stuefe (SAP)32* @modules java.base/jdk.internal.misc33* java.management34* @run driver SecondaryErrorTest35*/3637import java.io.BufferedReader;38import java.io.File;39import java.io.FileInputStream;40import java.io.InputStreamReader;41import java.util.regex.Pattern;4243import jdk.test.lib.process.OutputAnalyzer;44import jdk.test.lib.process.ProcessTools;4546public class SecondaryErrorTest {474849public static void main(String[] args) throws Exception {50ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(51"-XX:+UnlockDiagnosticVMOptions",52"-Xmx100M",53"-XX:-CreateCoredumpOnCrash",54"-XX:ErrorHandlerTest=15",55"-XX:TestCrashInErrorHandler=14",56"-version");5758OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());5960// we should have crashed with a SIGFPE61output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");62output_detail.shouldMatch("#.+SIGFPE.*");6364// extract hs-err file65String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);66if (hs_err_file == null) {67throw new RuntimeException("Did not find hs-err file in output.\n");68}6970// scan hs-err file: File should contain the "[error occurred during error reporting..]"71// markers which show that the secondary error handling kicked in and handled the72// error successfully. As an added test, we check that the last line contains "END.",73// which is an end marker written in the last step and proves that hs-err file was74// completely written.75File f = new File(hs_err_file);76if (!f.exists()) {77throw new RuntimeException("hs-err file missing at "78+ f.getAbsolutePath() + ".\n");79}8081System.out.println("Found hs_err file. Scanning...");8283FileInputStream fis = new FileInputStream(f);84BufferedReader br = new BufferedReader(new InputStreamReader(fis));85String line = null;8687Pattern [] pattern = new Pattern[] {88Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),89Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 1\\).*\\]"),90Pattern.compile("Will crash now \\(TestCrashInErrorHandler=14\\)..."),91Pattern.compile("\\[error occurred during error reporting \\(test secondary crash 2\\).*\\]"),92};93int currentPattern = 0;9495String lastLine = null;96while ((line = br.readLine()) != null) {97if (currentPattern < pattern.length) {98if (pattern[currentPattern].matcher(line).matches()) {99System.out.println("Found: " + line + ".");100currentPattern ++;101}102}103lastLine = line;104}105br.close();106107if (currentPattern < pattern.length) {108throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPattern + ")");109}110111if (!lastLine.equals("END.")) {112throw new RuntimeException("hs-err file incomplete (missing END marker.)");113} else {114System.out.println("End marker found.");115}116117System.out.println("OK.");118119}120121}122123124125126