Skip to content

Commit 10f0884

Browse files
committed
8207855: Make applications/jcstress invoke tests in batches
Backport-of: 4805473
1 parent a855cab commit 10f0884

35 files changed

+810
-69612
lines changed

test/hotspot/jtreg/TEST.groups

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,21 @@ hotspot_rest_runtime = \
424424
-:hotspot_nmt \
425425
-:hotspot_tier2_runtime_platform_agnostic
426426

427+
jcstress_part1 = \
428+
applications/jcstress/seqcst.java
429+
430+
jcstress_part2 = \
431+
applications/jcstress/accessAtomic.java \
432+
applications/jcstress/acqrel.java \
433+
applications/jcstress/atomics.java \
434+
applications/jcstress/coherence.java \
435+
applications/jcstress/locks.java
436+
437+
jcstress_part3 = \
438+
applications/jcstress \
439+
-:jcstress_part1 \
440+
-:jcstress_part2
441+
427442
# Stress tests against information provided by VM via JMX
428443
vmTestbase_nsk_monitoring = \
429444
vmTestbase/nsk/monitoring

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

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.io.BufferedReader;
3131
import java.io.File;
32+
import java.io.FileNotFoundException;
3233
import java.io.IOException;
3334
import java.io.PrintStream;
3435
import java.nio.file.Files;
@@ -51,11 +52,6 @@
5152
* Use jcstress test suite to generate jtreg tests in 'test.src' or current
5253
* directory. Used version is defined in JcstressRunner class.
5354
*
54-
* Each generated jtreg test file will contain several tests. Subdirectories are
55-
* used to allow running all tests from a file using command line. 'copy',
56-
* 'acqrel', 'fences', 'atomicity', 'seqcst.sync', 'seqcst.volatiles' and
57-
* 'other' tests will be generated.
58-
*
5955
* This generator depends on testlibrary, therefore it should be compiled and
6056
* added to classpath. One can replace @notest by @test in jtreg test
6157
* description above to run this class with jtreg.
@@ -97,58 +93,18 @@ public class TestGenerator {
9793
" */\n\n", years);
9894
}
9995

100-
private static enum JcstressGroup {
101-
MEMEFFECTS("memeffects"),
102-
COPY("copy"),
103-
ACQREL("acqrel"),
104-
FENCES("fences"),
105-
ATOMICITY("atomicity"),
106-
SEQCST_SYNC("seqcst.sync"),
107-
SEQCST_VOLATILES("seqcst.volatiles"),
108-
OTHER("other", JcstressGroup.otherFilter());
109-
110-
private final String groupName;
111-
private final Predicate<String> filter;
112-
113-
private JcstressGroup(String groupName, Predicate<String> filter) {
114-
this.groupName = groupName;
115-
this.filter = filter;
116-
}
117-
118-
private JcstressGroup(String groupName) {
119-
this(groupName, JcstressGroup.nameFilter(groupName));
120-
}
121-
122-
private static Predicate<String> nameFilter(String group) {
123-
return s -> s.startsWith("org.openjdk.jcstress.tests." + group + ".");
124-
}
125-
126-
private static Predicate<String> otherFilter() {
127-
return (s) -> {
128-
for (JcstressGroup g : EnumSet.complementOf(EnumSet.of(OTHER))) {
129-
if (g.filter.test(s)) {
130-
return false;
131-
}
132-
}
133-
return true;
134-
};
135-
}
136-
}
137-
13896
public static String DESC_FORMAT = "\n"
13997
+ "/**\n"
14098
+ " * @test %1$s\n"
14199
+ " * @library /test/lib /\n"
142-
+ " * @run driver/timeout=2400 " + JcstressRunner.class.getName()
100+
+ " * @run driver/timeout=21600 " + JcstressRunner.class.getName()
143101
// verbose output
144102
+ " -v"
145-
// test mode preset
146-
+ " -m default"
147103
// test name
148-
+ " -t %1$s\n"
104+
+ " -t org.openjdk.jcstress.tests.%1$s\\.\n"
149105
+ " */\n";
150106

151-
public static void main(String[] args) {
107+
public static void main(String[] args) throws IOException {
152108
Path path = JcstressRunner.pathToArtifact();
153109
Path output;
154110
try {
@@ -162,56 +118,32 @@ public static void main(String[] args) {
162118
} catch (Exception e) {
163119
throw new Error("Can not get list of tests", e);
164120
}
165-
for (JcstressGroup group : JcstressGroup.values()) {
166-
try {
167-
try (BufferedReader reader = Files.newBufferedReader(output)) {
168-
// skip first 4 lines: name, -{80}, revision and empty line
169-
for (int i = 0; i < 4; ++i) {
170-
reader.readLine();
171-
}
172-
new TestGenerator(group).generate(reader);
173-
}
174-
} catch (IOException e) {
175-
throw new Error("Generating tests for " + group.name()
176-
+ " has failed", e);
177-
}
178-
}
179-
output.toFile().delete();
180-
}
181121

182-
private final JcstressGroup group;
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);
183130

184-
private TestGenerator(JcstressGroup group) {
185-
this.group = group;
131+
output.toFile().delete();
186132
}
187133

188-
private void generate(BufferedReader reader) throws IOException {
189-
// array is needed to change value inside a lambda
190-
long[] count = {0L};
191-
String root = Utils.TEST_SRC;
192-
Path testFile = Paths.get(root)
193-
.resolve(group.groupName)
194-
.resolve("Test.java");
195-
File testDir = testFile.getParent().toFile();
196-
if (!testDir.mkdirs() && !testDir.exists()) {
197-
throw new Error("Can not create directories for "
198-
+ testFile.toString());
199-
}
134+
private static void generate(String group) {
135+
Path testFile = Paths.get(Utils.TEST_SRC).resolve(group + ".java");
200136

137+
System.out.println("Generating " + testFile);
201138
try (PrintStream ps = new PrintStream(testFile.toFile())) {
202139
ps.print(COPYRIGHT);
203140
ps.printf("/* DO NOT MODIFY THIS FILE. GENERATED BY %s */\n",
204-
getClass().getName());
141+
TestGenerator.class.getName());
205142

206-
reader.lines()
207-
.filter(group.filter)
208-
.forEach(s -> {
209-
count[0]++;
210-
ps.printf(DESC_FORMAT, s);
211-
});
143+
ps.printf(DESC_FORMAT, group);
212144
ps.print('\n');
145+
} catch (FileNotFoundException e) {
146+
System.out.println("Failed to generate tests for " + group);
213147
}
214-
System.out.printf("%d tests generated in %s%n",
215-
count[0], group.groupName);
216148
}
217149
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/* DO NOT MODIFY THIS FILE. GENERATED BY applications.jcstress.TestGenerator */
25+
26+
/**
27+
* @test accessAtomic
28+
* @library /test/lib /
29+
* @run driver/timeout=21600 applications.jcstress.JcstressRunner -v -t org.openjdk.jcstress.tests.accessAtomic\.
30+
*/
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/* DO NOT MODIFY THIS FILE. GENERATED BY applications.jcstress.TestGenerator */
25+
26+
/**
27+
* @test acqrel
28+
* @library /test/lib /
29+
* @run driver/timeout=21600 applications.jcstress.JcstressRunner -v -t org.openjdk.jcstress.tests.acqrel\.
30+
*/
31+

0 commit comments

Comments
 (0)