Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/VeryEarlyAssertTest.java
40942 views
/*1* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2018, SAP. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/232425/*26* @test27* @bug 821497528* @summary No hs-err file if fatal error is raised during dynamic initialization.29* @library /test/lib30* @modules java.base/jdk.internal.misc31* @requires (vm.debug == true)32* @requires os.family == "linux"33* @run driver VeryEarlyAssertTest34*/3536import java.io.BufferedReader;37import java.io.File;38import java.io.FileInputStream;39import java.io.InputStreamReader;40import java.util.regex.Pattern;41import java.util.Map;4243import jdk.test.lib.process.OutputAnalyzer;44import jdk.test.lib.process.ProcessTools;4546public class VeryEarlyAssertTest {4748public static void main(String[] args) throws Exception {495051ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(52"-version");53Map<String, String> env = pb.environment();54env.put("HOTSPOT_FATAL_ERROR_DURING_DYNAMIC_INITIALIZATION", "1");5556OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());5758// we should have crashed with an assert with a specific message:59output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");60output_detail.shouldMatch("#.*HOTSPOT_FATAL_ERROR_DURING_DYNAMIC_INITIALIZATION.*");6162// extract hs-err file63String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);64if (hs_err_file == null) {65throw new RuntimeException("Did not find hs-err file in output.\n");66}6768// scan hs-err file: File should contain the same assertion message. Other than that,69// do not expect too much: file will be littered with secondary errors. The test70// should test that we get a hs-err file at all.71File f = new File(hs_err_file);72if (!f.exists()) {73throw new RuntimeException("hs-err file missing at "74+ f.getAbsolutePath() + ".\n");75}7677System.out.println("Found hs_err file. Scanning...");7879FileInputStream fis = new FileInputStream(f);80BufferedReader br = new BufferedReader(new InputStreamReader(fis));81String line = null;8283Pattern[] pattern = new Pattern[]{84Pattern.compile(".*HOTSPOT_FATAL_ERROR_DURING_DYNAMIC_INITIALIZATION.*")85};86int currentPattern = 0;8788boolean endMarkerFound = false;89while ((line = br.readLine()) != null) {90if (currentPattern < pattern.length) {91if (pattern[currentPattern].matcher(line).matches()) {92System.out.println("Found: " + line + ".");93currentPattern++;94}95}96if (line.equals("END.")) {97endMarkerFound = true;98break;99}100}101br.close();102103if (currentPattern < pattern.length) {104throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPattern + ")");105}106107if (!endMarkerFound) {108throw new RuntimeException("hs-err file incomplete (missing END marker.)");109} else {110System.out.println("End marker found.");111}112113System.out.println("OK.");114115}116117}118119120