Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
/ jdk22u Public archive

Commit

Permalink
8326496: [test] checkHsErrFileContent support printing hserr in error…
Browse files Browse the repository at this point in the history
… case

Backport-of: a065eba56de01f4492123c6663ec0c3108d907a1
  • Loading branch information
MBaesken committed Mar 13, 2024
1 parent 6aa344a commit 82c3743
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
65 changes: 60 additions & 5 deletions test/hotspot/jtreg/runtime/ErrorHandling/HsErrFileUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 SAP SE. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -68,7 +68,7 @@ public static File openHsErrFileFromOutput(OutputAnalyzer output) {
* @throws RuntimeException, {@link IOException}
*/
public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean verbose) throws IOException {
checkHsErrFileContent(f, patterns, null, true, verbose);
checkHsErrFileContent(f, patterns, null, true, verbose, false);
}

/**
Expand All @@ -80,11 +80,43 @@ public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean ver
* Order is irrelevant.
* @param checkEndMarker If true, we check for the final "END" in an hs-err file; if it is missing it indicates
* that hs-err file printing did not complete successfully.
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only important
* information are printed.
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
* are printed.
* @throws RuntimeException, {@link IOException}
*/
public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pattern[] negativePatterns, boolean checkEndMarker, boolean verbose) throws IOException {
checkHsErrFileContent(f, positivePatterns, negativePatterns, checkEndMarker, verbose, false);
}

/**
* Given an open hs-err file, read it line by line and check for existence of a set of patterns. Will fail
* if patterns are missing, or if the END marker is missing.
* @param f Input file
* @param patterns An array of patterns that need to match, in that order
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
* are printed.
* @param printHserrOnError If true, the content of the hs-err file is printed in case of a failing check
* @throws RuntimeException, {@link IOException}
*/
public static void checkHsErrFileContent(File f, Pattern[] patterns, boolean verbose, boolean printHserrOnError) throws IOException {
checkHsErrFileContent(f, patterns, null, true, verbose, printHserrOnError);
}

/**
* Given an open hs-err file, read it line by line and check for various conditions.
* @param f input file
* @param positivePatterns Optional array of patterns that need to appear, in given order, in the file. Missing
* patterns cause the test to fail.
* @param negativePatterns Optional array of patterns that must not appear in the file; test fails if they do.
* Order is irrelevant.
* @param checkEndMarker If true, we check for the final "END" in an hs-err file; if it is missing it indicates
* that hs-err file printing did not complete successfully.
* @param verbose If true, the content of the hs-err file is printed while matching. If false, only the matched patterns
* are printed.
* @param printHserrOnError If true, the content of the hs-err file is printed in case of a failing check
* @throws RuntimeException, {@link IOException}
*/
public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pattern[] negativePatterns, boolean checkEndMarker, boolean verbose, boolean printHserrOnError) throws IOException {
try (
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
Expand Down Expand Up @@ -123,6 +155,9 @@ public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pat
System.out.println(line);
}
System.out.println("^^^ Forbidden pattern found at line " + lineNo + ": " + negativePattern + "^^^");
if (printHserrOnError) {
printHsErrFile(f);
}
throw new RuntimeException("Forbidden pattern found at line " + lineNo + ": " + negativePattern);
}
}
Expand All @@ -132,13 +167,33 @@ public static void checkHsErrFileContent(File f, Pattern[] positivePatterns, Pat
}
// If the current pattern is not null then it didn't match
if (currentPositivePattern != null) {
if (printHserrOnError) {
printHsErrFile(f);
}
throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPositivePattern.pattern() + ")");
}
if (checkEndMarker && !lastLine.equals("END.")) {
if (printHserrOnError) {
printHsErrFile(f);
}
throw new RuntimeException("hs-err file incomplete (missing END marker.)");
}
System.out.println("hs-err file " + f.getAbsolutePath() + " scanned successfully.");
}
}

private static void printHsErrFile(File f) throws IOException {
try (
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
) {
String line;
System.out.println("------------------------ hs-err file ------------------------");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("-------------------------------------------------------------");
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2014, 2022 SAP SE. All rights reserved.
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024 SAP SE. All rights reserved.
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -122,7 +122,7 @@ public static void main(String[] args) throws Exception {
}
Pattern[] pattern = patternlist.toArray(new Pattern[] {});

HsErrFileUtils.checkHsErrFileContent(hs_err_file, pattern, false);
HsErrFileUtils.checkHsErrFileContent(hs_err_file, pattern, false, true);

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

Expand Down

1 comment on commit 82c3743

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.