Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/BadNativeStackInErrorHandlingTest.java
40942 views
/*1* Copyright (c) 2018, 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*/2223import java.io.BufferedReader;24import java.io.File;25import java.io.FileInputStream;26import java.io.InputStreamReader;27import java.util.regex.Pattern;2829import jdk.test.lib.process.OutputAnalyzer;30import jdk.test.lib.process.ProcessTools;3132/*33* @test34* @bug 819465235* @summary Printing native stack shows an "error occurred during error reporting".36* @modules java.base/jdk.internal.misc37* @requires vm.debug38* @requires vm.flavor != "zero"39* @library /test/lib40* @run driver BadNativeStackInErrorHandlingTest41*/4243// This test was adapted from SafeFetchInErrorHandlingTest.java.44public class BadNativeStackInErrorHandlingTest {45public static void main(String[] args) throws Exception {46ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(47"-XX:+UnlockDiagnosticVMOptions",48"-Xmx100M",49"-XX:ErrorHandlerTest=14",50"-XX:-CreateCoredumpOnCrash",51"-version");5253OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());5455// we should have crashed with a SIGSEGV56output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");57output_detail.shouldMatch("# +(?:SIGSEGV|SIGBUS|EXCEPTION_ACCESS_VIOLATION).*");5859// extract hs-err file60String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);61if (hs_err_file == null) {62throw new RuntimeException("Did not find hs-err file in output.\n");63}6465File f = new File(hs_err_file);66if (!f.exists()) {67throw new RuntimeException("hs-err file missing at " +68f.getAbsolutePath() + ".\n");69}7071System.out.println("Found hs_err file. Scanning...");7273FileInputStream fis = new FileInputStream(f);74BufferedReader br = new BufferedReader(new InputStreamReader(fis));75String line = null;7677// The failing line looks like this:78// [error occurred during error reporting (printing native stack), id 0xb]79Pattern pattern =80Pattern.compile("\\[error occurred during error reporting \\(printing native stack\\), id .*\\]");8182String lastLine = null;83while ((line = br.readLine()) != null) {84if (pattern.matcher(line).matches()) {85System.out.println("Found: " + line + ".");86throw new RuntimeException("hs-err file should not contain: '" +87pattern + "'");88}89lastLine = line;90}91br.close();9293if (!lastLine.equals("END.")) {94throw new RuntimeException("hs-err file incomplete (missing END marker.)");95} else {96System.out.println("End marker found.");97}9899System.out.println("OK.");100}101}102103104