8294880: Review running time of jdk/internal/shellsupport/doc/JavadocHelperTest.java

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2024-05-15 11:47:49 +00:00
parent a5005c87c4
commit fa043aec42
3 changed files with 96 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 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
@ -63,6 +63,9 @@ langtools_jdeps = \
tools/all \
tools/jdeps
langtools_slow = \
jdk/internal/shellsupport/doc/FullJavadocHelperTest.java
# All tests
all = \
@ -78,11 +81,13 @@ tier1 = \
:langtools_all \
lib \
tools \
-:langtools_jshell_unstable
-:langtools_jshell_unstable \
-:langtools_slow
# (Almost) no langtools tests are tier 2.
tier2 = \
:langtools_jshell_unstable
:langtools_jshell_unstable \
:langtools_slow
# No langtools tests are tier 3 either.
tier3 =

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, 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
* 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.
*/
/*
* @test
* @bug 8189778
* @summary Test JavadocHelper
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/jdk.internal.shellsupport.doc
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
* @run testng/timeout=900/othervm -Xmx1024m FullJavadocHelperTest
*/
import java.io.IOException;
import org.testng.annotations.Test;
@Test
public class FullJavadocHelperTest {
/*
* Long-running test to retrieve doc comments for enclosed elements of all JDK classes.
*/
public void testAllDocs() throws IOException {
new JavadocHelperTest().retrieveDocComments(Boolean.TRUE::booleanValue);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -30,7 +30,8 @@
* jdk.compiler/com.sun.tools.javac.main
* jdk.compiler/jdk.internal.shellsupport.doc
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
* @run testng/timeout=900/othervm -Xmx1024m JavadocHelperTest
* @run testng JavadocHelperTest
* @key randomness
*/
import java.io.IOException;
@ -46,6 +47,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@ -383,7 +386,35 @@ public class JavadocHelperTest {
}
public void testAllDocs() throws IOException {
private static long getSeed() {
long seed;
try {
// Throws NumberFormatException if the property is undefined
seed = Long.parseLong(System.getProperty("seed"));
} catch (NumberFormatException e) {
seed = new Random().nextLong();
}
System.out.println("Random Seed: " + seed);
return seed;
}
/*
* Retrieves doc comments for a random subset of JDK classes.
* Set the system property `seed` to a random seed to reproduce
* a specific run of this test.
*/
public void testRandomDocs() throws IOException {
Random random = new Random(getSeed());
// Run test on 2% of classes, which corresponds to ~ 140 classes
retrieveDocComments(() -> random.nextInt(100) < 2);
}
/**
* Retrieve documentation of enclosed elements for some or all JDK classes.
*
* @param shouldTest oracle function to decide whether a class should be tested
*/
protected void retrieveDocComments(BooleanSupplier shouldTest) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticListener<? super JavaFileObject> noErrors = d -> {
if (d.getKind() == Kind.ERROR) {
@ -408,7 +439,7 @@ public class JavadocHelperTest {
}
}
try (StandardJavaFileManager fm =
compiler.getStandardFileManager(null, null, null)) {
compiler.getStandardFileManager(null, null, null)) {
JavacTask task =
(JavacTask) compiler.getTask(null, fm, noErrors, null, null, null);
task.getElements().getTypeElement("java.lang.Object");
@ -420,8 +451,10 @@ public class JavadocHelperTest {
List<? extends Element> content =
ed.getPackage().getEnclosedElements();
for (TypeElement clazz : ElementFilter.typesIn(content)) {
for (Element el : clazz.getEnclosedElements()) {
helper.getResolvedDocComment(el);
if (shouldTest.getAsBoolean()) {
for (Element el : clazz.getEnclosedElements()) {
helper.getResolvedDocComment(el);
}
}
}
}