Skip to content

Commit

Permalink
8294880: Review running time of jdk/internal/shellsupport/doc/Javadoc…
Browse files Browse the repository at this point in the history
…HelperTest.java

Reviewed-by: jjg
  • Loading branch information
hns committed May 15, 2024
1 parent a5005c8 commit fa043ae
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 9 deletions.
11 changes: 8 additions & 3 deletions test/langtools/TEST.groups
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -63,6 +63,9 @@ langtools_jdeps = \
tools/all \
tools/jdeps

langtools_slow = \
jdk/internal/shellsupport/doc/FullJavadocHelperTest.java

# All tests

all = \
Expand 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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -46,6 +47,8 @@
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;
Expand Down Expand Up @@ -383,7 +386,35 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept

}

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) {
Expand All @@ -408,7 +439,7 @@ public void testAllDocs() throws IOException {
}
}
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");
Expand All @@ -420,8 +451,10 @@ public void testAllDocs() throws IOException {
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);
}
}
}
}
Expand Down

1 comment on commit fa043ae

@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.