29
29
30
30
import java .io .BufferedReader ;
31
31
import java .io .File ;
32
+ import java .io .FileNotFoundException ;
32
33
import java .io .IOException ;
33
34
import java .io .PrintStream ;
34
35
import java .nio .file .Files ;
51
52
* Use jcstress test suite to generate jtreg tests in 'test.src' or current
52
53
* directory. Used version is defined in JcstressRunner class.
53
54
*
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
- *
59
55
* This generator depends on testlibrary, therefore it should be compiled and
60
56
* added to classpath. One can replace @notest by @test in jtreg test
61
57
* description above to run this class with jtreg.
@@ -97,58 +93,18 @@ public class TestGenerator {
97
93
" */\n \n " , years );
98
94
}
99
95
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
-
138
96
public static String DESC_FORMAT = "\n "
139
97
+ "/**\n "
140
98
+ " * @test %1$s\n "
141
99
+ " * @library /test/lib /\n "
142
- + " * @run driver/timeout=2400 " + JcstressRunner .class .getName ()
100
+ + " * @run driver/timeout=21600 " + JcstressRunner .class .getName ()
143
101
// verbose output
144
102
+ " -v"
145
- // test mode preset
146
- + " -m default"
147
103
// test name
148
- + " -t %1$s\n "
104
+ + " -t org.openjdk.jcstress.tests. %1$s\\ . \n "
149
105
+ " */\n " ;
150
106
151
- public static void main (String [] args ) {
107
+ public static void main (String [] args ) throws IOException {
152
108
Path path = JcstressRunner .pathToArtifact ();
153
109
Path output ;
154
110
try {
@@ -162,56 +118,32 @@ public static void main(String[] args) {
162
118
} catch (Exception e ) {
163
119
throw new Error ("Can not get list of tests" , e );
164
120
}
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
- }
181
121
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 );
183
130
184
- private TestGenerator (JcstressGroup group ) {
185
- this .group = group ;
131
+ output .toFile ().delete ();
186
132
}
187
133
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" );
200
136
137
+ System .out .println ("Generating " + testFile );
201
138
try (PrintStream ps = new PrintStream (testFile .toFile ())) {
202
139
ps .print (COPYRIGHT );
203
140
ps .printf ("/* DO NOT MODIFY THIS FILE. GENERATED BY %s */\n " ,
204
- getClass () .getName ());
141
+ TestGenerator . class .getName ());
205
142
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 );
212
144
ps .print ('\n' );
145
+ } catch (FileNotFoundException e ) {
146
+ System .out .println ("Failed to generate tests for " + group );
213
147
}
214
- System .out .printf ("%d tests generated in %s%n" ,
215
- count [0 ], group .groupName );
216
148
}
217
149
}
0 commit comments