New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8302267: [jittester] Improve separation of test generation and execution #12527
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/ErrorTolerance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) 2023, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package jdk.test.lib.jittester; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
import jdk.test.lib.Asserts; | ||
|
||
/** | ||
* Compares reference output to the one that's being verified. | ||
* | ||
* The class can tolerate some errors (like OutOfMemoryError), | ||
* as their nature is unpredictable and ignore missing intrinsics in | ||
* compiled code stack traces. | ||
*/ | ||
public class ErrorTolerance { | ||
|
||
// Put the most annoying intrinsics here | ||
private static final List<Predicate<String>> PATTERNS = List.of( | ||
Pattern.compile(".*at java.base.*misc.Unsafe.allocateUninitializedArray0.*").asPredicate() | ||
); | ||
|
||
private static final Predicate<String> OOME = Pattern.compile( | ||
"Exception in thread \".*\" java.lang.OutOfMemoryError.*").asPredicate(); | ||
private static final Predicate<String> SOE = Pattern.compile( | ||
".*StackOverFlowError.*").asPredicate(); | ||
|
||
private static boolean isIntrinsicCandidate(String line) { | ||
return PATTERNS.stream() | ||
.map(pattern -> pattern.test(line)) | ||
.reduce(false, (acc, match) -> acc | match); | ||
} | ||
|
||
public static void assertIsAcceptable(String message, Stream<String> gold, Stream<String> run) { | ||
Iterator<String> goldIt = gold.iterator(); | ||
Iterator<String> runIt = run.iterator(); | ||
|
||
while (goldIt.hasNext() && runIt.hasNext()) { | ||
String goldLine = goldIt.next(); | ||
String runLine = runIt.next(); | ||
|
||
// Skipping intrinsics in 'run' | ||
while (isIntrinsicCandidate(goldLine) && | ||
!runLine.equals(goldLine) && | ||
goldIt.hasNext()) { | ||
goldLine = goldIt.next(); | ||
} | ||
|
||
if (!goldLine.equals(runLine)) { | ||
String fullMessage = "While " + message + ":\n" + | ||
"Expected: " + goldLine + "\n" + | ||
"Actual : " + runLine + "\n"; | ||
Asserts.fail(fullMessage); | ||
} | ||
} | ||
Asserts.assertEquals(goldIt.hasNext(), runIt.hasNext(), message + ": files are different"); | ||
} | ||
|
||
public static void assertIsAcceptable(Path gold, Path run) { | ||
String comparisonNames = "'" + gold + "' and '" + run + "'"; | ||
try { | ||
assertIsAcceptable("comparing files " + comparisonNames, | ||
Files.lines(gold), Files.lines(run)); | ||
} catch (IOException e) { | ||
throw new Error("Could not compare files: '" + comparisonNames); | ||
} | ||
} | ||
|
||
public static boolean isReliable(Stream<String> gold) { | ||
return !gold.anyMatch(line -> OOME.test(line) || SOE.test(line)); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/HeaderFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,126 @@ | ||||||
/* | ||||||
* Copyright (c) 2023, 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 | ||||||
* under the terms of the GNU General Public License version 2 only, as | ||||||
* published by the Free Software Foundation. | ||||||
* | ||||||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||
* version 2 for more details (a copy is included in the LICENSE file that | ||||||
* accompanied this code). | ||||||
* | ||||||
* You should have received a copy of the GNU General Public License version | ||||||
* 2 along with this work; if not, write to the Free Software Foundation, | ||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
* | ||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||||
* or visit www.oracle.com if you need additional information or have any | ||||||
* questions. | ||||||
*/ | ||||||
|
||||||
package jdk.test.lib.jittester; | ||||||
|
||||||
import java.util.function.Function; | ||||||
import java.util.stream.Collectors; | ||||||
|
||||||
import jdk.test.lib.jittester.types.TypeKlass; | ||||||
import jdk.test.lib.jittester.utils.PseudoRandom; | ||||||
|
||||||
public final class HeaderFormatter { | ||||||
public static final String DISABLE_WARNINGS = "-XX:-PrintWarnings"; | ||||||
|
||||||
private final Builder builder; | ||||||
|
||||||
public static class Builder { | ||||||
private Function<String, String[]> preRunActions = s -> new String[0]; | ||||||
private String jtDriverOptions = "-Xcomp"; | ||||||
private String libraries = "/ ../"; | ||||||
private boolean printJitTesterHierarchy = true; | ||||||
private boolean buildPrinter = true; | ||||||
|
||||||
public Builder preRunActions(Function<String, String[]> from) { | ||||||
preRunActions = from; | ||||||
return this; | ||||||
} | ||||||
|
||||||
public Builder jtDriverOptions(String from) { | ||||||
jtDriverOptions = from; | ||||||
return this; | ||||||
} | ||||||
|
||||||
public Builder libraries(String from) { | ||||||
libraries = from; | ||||||
return this; | ||||||
} | ||||||
|
||||||
public Builder printJitTesterHierarchy(boolean from) { | ||||||
printJitTesterHierarchy = from; | ||||||
return this; | ||||||
} | ||||||
|
||||||
public Builder buildPrinter(boolean from) { | ||||||
buildPrinter = false; | ||||||
return this; | ||||||
} | ||||||
|
||||||
public HeaderFormatter build() { | ||||||
return new HeaderFormatter(this); | ||||||
} | ||||||
} | ||||||
|
||||||
private HeaderFormatter(Builder builder) { | ||||||
this.builder = builder; | ||||||
} | ||||||
|
||||||
public String getJtregHeader(String mainClassName) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
String synopsis = "seed = '" + ProductionParams.seed.value() + "'" | ||||||
+ ", specificSeed = '" + PseudoRandom.getCurrentSeed() + "'"; | ||||||
StringBuilder header = new StringBuilder(); | ||||||
header.append("/*\n * @test\n * @summary ") | ||||||
.append(synopsis) | ||||||
.append(" \n * @library " + builder.libraries + "\n"); | ||||||
header.append(" * @run build jdk.test.lib.jittester.jtreg.JitTesterDriver" | ||||||
+ (builder.buildPrinter ? " jdk.test.lib.jittester.jtreg.Printer\n" : "\n")); | ||||||
for (String action : builder.preRunActions.apply(mainClassName)) { | ||||||
header.append(" * ") | ||||||
.append(action) | ||||||
.append("\n"); | ||||||
} | ||||||
header.append(" * @run driver/timeout=180 jdk.test.lib.jittester.jtreg.JitTesterDriver ") | ||||||
.append(DISABLE_WARNINGS) | ||||||
.append(" ") | ||||||
.append(builder.jtDriverOptions) | ||||||
.append(" ") | ||||||
.append(mainClassName) | ||||||
.append("\n */\n\n"); | ||||||
if (ProductionParams.printHierarchy.value() && builder.printJitTesterHierarchy) { | ||||||
header.append("/*\n") | ||||||
.append(printHierarchy()) | ||||||
.append("*/\n"); | ||||||
} | ||||||
return header.toString(); | ||||||
} | ||||||
|
||||||
private static String printHierarchy() { | ||||||
return TypeList.getAll() | ||||||
.stream() | ||||||
.filter(t -> t instanceof TypeKlass) | ||||||
.map(t -> typeDescription((TypeKlass) t)) | ||||||
.collect(Collectors.joining("\n", "CLASS HIERARCHY:\n", "\n")); | ||||||
} | ||||||
|
||||||
private static String typeDescription(TypeKlass type) { | ||||||
StringBuilder result = new StringBuilder(); | ||||||
String parents = type.getParentsNames().stream().collect(Collectors.joining(",")); | ||||||
result.append(type.isAbstract() ? "abstract " : "") | ||||||
.append(type.isFinal() ? "final " : "") | ||||||
.append(type.isInterface() ? "interface " : "class ") | ||||||
.append(type.getName()) | ||||||
.append(parents.isEmpty() ? "" : ": " + parents); | ||||||
return result.toString(); | ||||||
} | ||||||
|
||||||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.