Skip to content

Commit 608c98d

Browse files
committed
8326496: [test] checkHsErrFileContent support printing hserr in error case
Backport-of: a065eba56de01f4492123c6663ec0c3108d907a1
1 parent d42da09 commit 608c98d

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

test/hotspot/jtreg/runtime/ErrorHandling/HsErrFileUtils.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2022 SAP SE. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2022, 2024 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -68,7 +68,7 @@ public static File openHsErrFileFromOutput(OutputAnalyzer output) {
6868
* @throws RuntimeException, {@link IOException}
6969
*/
7070
public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean verbose) throws IOException {
71-
checkHsErrFileContent(f, patterns, null, true, verbose);
71+
checkHsErrFileContent(f, patterns, null, true, verbose, false);
7272
}
7373

7474
/**
@@ -80,11 +80,43 @@ public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean ver
8080
* Order is irrelevant.
8181
* @param checkEndMarker If true, we check for the final "END" in an hs-err file; if it is missing it indicates
8282
* that hs-err file printing did not complete successfully.
83-
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only important
84-
* information are printed.
83+
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
84+
* are printed.
8585
* @throws RuntimeException, {@link IOException}
8686
*/
8787
public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pattern[] negativePatterns, boolean checkEndMarker, boolean verbose) throws IOException {
88+
checkHsErrFileContent(f, positivePatterns, negativePatterns, checkEndMarker, verbose, false);
89+
}
90+
91+
/**
92+
* Given an open hs-err file, read it line by line and check for existence of a set of patterns. Will fail
93+
* if patterns are missing, or if the END marker is missing.
94+
* @param f Input file
95+
* @param patterns An array of patterns that need to match, in that order
96+
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
97+
* are printed.
98+
* @param printHserrOnError If true, the content of the hs-err file is printed in case of a failing check
99+
* @throws RuntimeException, {@link IOException}
100+
*/
101+
public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean verbose, boolean printHserrOnError) throws IOException {
102+
checkHsErrFileContent(f, patterns, null, true, verbose, printHserrOnError);
103+
}
104+
105+
/**
106+
* Given an open hs-err file, read it line by line and check for various conditions.
107+
* @param f input file
108+
* @param positivePatterns Optional array of patterns that need to appear, in given order, in the file. Missing
109+
* patterns cause the test to fail.
110+
* @param negativePatterns Optional array of patterns that must not appear in the file; test fails if they do.
111+
* Order is irrelevant.
112+
* @param checkEndMarker If true, we check for the final "END" in an hs-err file; if it is missing it indicates
113+
* that hs-err file printing did not complete successfully.
114+
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
115+
* are printed.
116+
* @param printHserrOnError If true, the content of the hs-err file is printed in case of a failing check
117+
* @throws RuntimeException, {@link IOException}
118+
*/
119+
public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pattern[] negativePatterns, boolean checkEndMarker, boolean verbose, boolean printHserrOnError) throws IOException {
88120
try (
89121
FileInputStream fis = new FileInputStream(f);
90122
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
@@ -123,6 +155,9 @@ public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pat
123155
System.out.println(line);
124156
}
125157
System.out.println("^^^ Forbidden pattern found at line " + lineNo + ": " + negativePattern + "^^^");
158+
if (printHserrOnError) {
159+
printHsErrFile(f);
160+
}
126161
throw new RuntimeException("Forbidden pattern found at line " + lineNo + ": " + negativePattern);
127162
}
128163
}
@@ -132,13 +167,33 @@ public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pat
132167
}
133168
// If the current pattern is not null then it didn't match
134169
if (currentPositivePattern != null) {
170+
if (printHserrOnError) {
171+
printHsErrFile(f);
172+
}
135173
throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPositivePattern.pattern() + ")");
136174
}
137175
if (checkEndMarker && !lastLine.equals("END.")) {
176+
if (printHserrOnError) {
177+
printHsErrFile(f);
178+
}
138179
throw new RuntimeException("hs-err file incomplete (missing END marker.)");
139180
}
140181
System.out.println("hs-err file " + f.getAbsolutePath() + " scanned successfully.");
141182
}
142183
}
143184

185+
private static void printHsErrFile(File f) throws IOException {
186+
try (
187+
FileInputStream fis = new FileInputStream(f);
188+
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
189+
) {
190+
String line;
191+
System.out.println("------------------------ hs-err file ------------------------");
192+
while ((line = br.readLine()) != null) {
193+
System.out.println(line);
194+
}
195+
System.out.println("-------------------------------------------------------------");
196+
}
197+
}
198+
144199
}

test/hotspot/jtreg/runtime/ErrorHandling/SecondaryErrorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2014, 2022 SAP SE. All rights reserved.
3-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024 SAP SE. All rights reserved.
3+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -122,7 +122,7 @@ public static void main(String[] args) throws Exception {
122122
}
123123
Pattern[] pattern = patternlist.toArray(new Pattern[] {});
124124

125-
HsErrFileUtils.checkHsErrFileContent(hs_err_file, pattern, false);
125+
HsErrFileUtils.checkHsErrFileContent(hs_err_file, pattern, false, true);
126126

127127
System.out.println("OK.");
128128

0 commit comments

Comments
 (0)