< prev index next >

test/hotspot/jtreg/applications/jcstress/TestGenerator.java

Print this page

 24 package applications.jcstress;
 25 
 26 import jdk.test.lib.Utils;
 27 import jdk.test.lib.process.OutputAnalyzer;
 28 import jdk.test.lib.process.ProcessTools;
 29 
 30 import java.io.BufferedReader;
 31 import java.io.File;
 32 import java.io.FileNotFoundException;
 33 import java.io.IOException;
 34 import java.io.PrintStream;
 35 import java.nio.file.Files;
 36 import java.nio.file.Path;
 37 import java.nio.file.Paths;
 38 import java.util.Calendar;
 39 import java.util.EnumSet;
 40 import java.util.function.Predicate;
 41 
 42 
 43 /**
 44  * @notest THIS IS NOT A TEST.
 45  * This is a test generator, should be run only when jcstress is changed
 46  *
 47  * @library /test/lib /
 48  * @run main applications.jcstress.TestGenerator
 49  */
 50 
 51 /**
 52  * Use jcstress test suite to generate jtreg tests in 'test.src' or current
 53  * directory. Used version is defined in JcstressRunner class.
 54  *
 55  * This generator depends on testlibrary, therefore it should be compiled and
 56  * added to classpath. One can replace @notest by @test in jtreg test
 57  * description above to run this class with jtreg.
 58  *
 59  * @see <a href=https://wiki.openjdk.java.net/display/CodeTools/jcstress>jcstress</a>
 60  */
 61 public class TestGenerator {
 62     private static final String COPYRIGHT;
 63     static {
 64         String years;

 81                 " * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n" +
 82                 " * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n" +
 83                 " * version 2 for more details (a copy is included in the LICENSE file that\n" +
 84                 " * accompanied this code).\n" +
 85                 " *\n" +
 86                 " * You should have received a copy of the GNU General Public License version\n" +
 87                 " * 2 along with this work; if not, write to the Free Software Foundation,\n" +
 88                 " * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n" +
 89                 " *\n" +
 90                 " * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\n" +
 91                 " * or visit www.oracle.com if you need additional information or have any\n" +
 92                 " * questions.\n" +
 93                 " */\n\n", years);
 94     }
 95 
 96     public static String DESC_FORMAT = "\n"
 97             + "/**\n"
 98             + " * @test %1$s\n"
 99             + " * @library /test/lib /\n"
100             + " * @run driver/timeout=21600 " + JcstressRunner.class.getName()
101                     // verbose output
102                     + " -v"
103                     // test name
104                     + " -t org.openjdk.jcstress.tests.%1$s\\.\n"
105             + " */\n";
106 
107     public static void main(String[] args) throws IOException {
108         Path path = JcstressRunner.pathToArtifact();
109         Path output;
110         try {
111             output = Files.createTempFile("jcstress", ".out");
112             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
113                     "-jar",
114                     path.toAbsolutePath().toString(),
115                     "-l");
116             pb.redirectOutput(output.toFile());
117             new OutputAnalyzer(pb.start()).shouldHaveExitValue(0);
118         } catch (Exception e) {
119             throw new Error("Can not get list of tests", e);
120         }
121 
122         BufferedReader reader = Files.newBufferedReader(output);
123 
124         reader.lines()
125                 .skip(4) // skip first 4 lines: name, -{80}, revision and empty line
126                 .map(s -> s.split("\\.")[4]) // group by the package name following "org.openjdk.jcstress.tests."
127                 .distinct()
128                 .filter(s -> !s.startsWith("sample")) // skip sample test
129                 .forEach(TestGenerator::generate);
130 
131         output.toFile().delete();
132     }
133 
134     private static void generate(String group) {
135         Path testFile = Paths.get(Utils.TEST_SRC).resolve(group + ".java");
136 
137         System.out.println("Generating " + testFile);
138         try (PrintStream ps = new PrintStream(testFile.toFile())) {
139             ps.print(COPYRIGHT);
140             ps.printf("/* DO NOT MODIFY THIS FILE. GENERATED BY %s */\n",
141                     TestGenerator.class.getName());
142 
143             ps.printf(DESC_FORMAT, group);
144             ps.print('\n');
145         } catch (FileNotFoundException e) {

 24 package applications.jcstress;
 25 
 26 import jdk.test.lib.Utils;
 27 import jdk.test.lib.process.OutputAnalyzer;
 28 import jdk.test.lib.process.ProcessTools;
 29 
 30 import java.io.BufferedReader;
 31 import java.io.File;
 32 import java.io.FileNotFoundException;
 33 import java.io.IOException;
 34 import java.io.PrintStream;
 35 import java.nio.file.Files;
 36 import java.nio.file.Path;
 37 import java.nio.file.Paths;
 38 import java.util.Calendar;
 39 import java.util.EnumSet;
 40 import java.util.function.Predicate;
 41 
 42 
 43 /**
 44  * @test THIS IS NOT A TEST.
 45  * This is a test generator, should be run only when jcstress is changed
 46  *
 47  * @library /test/lib /
 48  * @run main applications.jcstress.TestGenerator
 49  */
 50 
 51 /**
 52  * Use jcstress test suite to generate jtreg tests in 'test.src' or current
 53  * directory. Used version is defined in JcstressRunner class.
 54  *
 55  * This generator depends on testlibrary, therefore it should be compiled and
 56  * added to classpath. One can replace @notest by @test in jtreg test
 57  * description above to run this class with jtreg.
 58  *
 59  * @see <a href=https://wiki.openjdk.java.net/display/CodeTools/jcstress>jcstress</a>
 60  */
 61 public class TestGenerator {
 62     private static final String COPYRIGHT;
 63     static {
 64         String years;

 81                 " * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n" +
 82                 " * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\n" +
 83                 " * version 2 for more details (a copy is included in the LICENSE file that\n" +
 84                 " * accompanied this code).\n" +
 85                 " *\n" +
 86                 " * You should have received a copy of the GNU General Public License version\n" +
 87                 " * 2 along with this work; if not, write to the Free Software Foundation,\n" +
 88                 " * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n" +
 89                 " *\n" +
 90                 " * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\n" +
 91                 " * or visit www.oracle.com if you need additional information or have any\n" +
 92                 " * questions.\n" +
 93                 " */\n\n", years);
 94     }
 95 
 96     public static String DESC_FORMAT = "\n"
 97             + "/**\n"
 98             + " * @test %1$s\n"
 99             + " * @library /test/lib /\n"
100             + " * @run driver/timeout=21600 " + JcstressRunner.class.getName()
101                     // verbose output, testing in virtual threads
102                     + " -v -vt -spinStyle LOCKSUPPORT_PARK_NANOS -f 0"
103                     // test name
104                     + " -t org.openjdk.jcstress.tests.%1$s\\.\n"
105             + " */\n";
106 
107     public static void main(String[] args) throws IOException {
108         Path path = JcstressRunner.pathToArtifact();
109         Path output;
110         try {
111             output = Files.createTempFile("jcstress", ".out");
112             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
113                     "-jar",
114                     path.toAbsolutePath().toString(),
115                     "-l");
116             pb.redirectOutput(output.toFile());
117             new OutputAnalyzer(pb.start()).shouldHaveExitValue(0);
118         } catch (Exception e) {
119             throw new Error("Can not get list of tests", e);
120         }
121 
122         BufferedReader reader = Files.newBufferedReader(output);
123 
124         reader.lines()
125                 .skip(6) // skip first 6 lines: name, -{80}, revision CPU info and empty line
126                 .map(s -> s.split("\\.")[4]) // group by the package name following "org.openjdk.jcstress.tests."
127                 .distinct()
128                 .filter(s -> !s.startsWith("sample")) // skip sample test
129                 .forEach(TestGenerator::generate);
130 
131         output.toFile().delete();
132     }
133 
134     private static void generate(String group) {
135         Path testFile = Paths.get(Utils.TEST_SRC).resolve(group + ".java");
136 
137         System.out.println("Generating " + testFile);
138         try (PrintStream ps = new PrintStream(testFile.toFile())) {
139             ps.print(COPYRIGHT);
140             ps.printf("/* DO NOT MODIFY THIS FILE. GENERATED BY %s */\n",
141                     TestGenerator.class.getName());
142 
143             ps.printf(DESC_FORMAT, group);
144             ps.print('\n');
145         } catch (FileNotFoundException e) {
< prev index next >