36
package compiler.oracle;
38
import jdk.test.lib.process.OutputAnalyzer;
39
import jdk.test.lib.process.ProcessTools;
43
public class CheckCompileCommandOption {
57
private static final String[][] FILE_ARGUMENTS = {
59
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command1.txt"),
63
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command2.txt"),
68
private static final String[][] FILE_EXPECTED_OUTPUT = {
70
"com/oracle/Test.test1 bool TestOptionBool = true",
71
"com/oracle/Test.test2 bool TestOptionBool = true",
72
"com/oracle/Test.test3 bool TestOptionBool = true",
73
"com/oracle/Test.test4 bool TestOptionBool = true",
74
"com/oracle/Test.test4 bool TestOptionBool2 = true",
75
"com/oracle/Test.test5 bool TestOptionBool = true",
76
"com/oracle/Test.test5 bool TestOptionBool2 = true",
77
"com/oracle/Test.test6(I) bool TestOptionBool = true",
78
"com/oracle/Test.test7(I) bool TestOptionBool = true",
79
"com/oracle/Test.test8(I) bool TestOptionBool = true",
80
"com/oracle/Test.test9(I) bool TestOptionBool = true",
81
"com/oracle/Test.test9(I) bool TestOptionBool2 = true",
82
"com/oracle/Test.test10(I) bool TestOptionBool = true",
83
"com/oracle/Test.test10(I) bool TestOptionBool2 = true"
86
"Test.test const char* TestOptionList = '_foo _bar'",
87
"Test.test const char* TestOptionStr = '_foo'",
88
"Test.test bool TestOptionBool = false",
89
"Test.test intx TestOptionInt = -1",
90
"Test.test uintx TestOptionUint = 1",
91
"Test.test bool TestOptionBool2 = true",
92
"Test.test double TestOptionDouble = 1.123000"
96
private static final String[][] TYPE_1_ARGUMENTS = {
98
"-XX:CompileCommand=option,com/oracle/Test.test,TestOptionBool",
99
"-XX:CompileCommand=option,com/oracle/Test,test,TestOptionBool2",
100
"-XX:CompileCommand=option,com/oracle/Test.test2,TestOptionBool2,TestOptionBool",
105
private static final String[][] TYPE_1_EXPECTED_OUTPUTS = {
107
"com/oracle/Test.test bool TestOptionBool = true",
108
"com/oracle/Test.test bool TestOptionBool2 = true",
109
"com/oracle/Test.test2 bool TestOptionBool = true",
110
"com/oracle/Test.test2 bool TestOptionBool2 = true",
114
private static final String[][] TYPE_2_ARGUMENTS = {
116
"-XX:CompileCommand=option,Test::test,ccstrlist,TestOptionList,_foo,_bar",
117
"-XX:CompileCommand=option,Test::test,ccstr,TestOptionStr,_foo",
118
"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false",
119
"-XX:CompileCommand=option,Test::test,intx,TestOptionInt,-1",
120
"-XX:CompileCommand=option,Test::test,uintx,TestOptionUint,1",
121
"-XX:CompileCommand=option,Test::test,TestOptionBool2",
122
"-XX:CompileCommand=option,Test::test,double,TestOptionDouble,1.123",
123
"-XX:CompileCommand=option,Test.test2,double,TestOptionDouble,1.123",
128
private static final String[][] TYPE_2_EXPECTED_OUTPUTS = {
130
"Test.test const char* TestOptionList = '_foo _bar'",
131
"Test.test const char* TestOptionStr = '_foo'",
132
"Test.test bool TestOptionBool = false",
133
"Test.test intx TestOptionInt = -1",
134
"Test.test uintx TestOptionUint = 1",
135
"Test.test bool TestOptionBool2 = true",
136
"Test.test double TestOptionDouble = 1.123000",
137
"Test.test2 double TestOptionDouble = 1.123000"
141
private static final String[][] TYPE_3_ARGUMENTS = {
143
"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false,intx,TestOptionInt,-1,uintx,TestOptionUint,1,TestOptionBool2,double,TestOptionDouble,1.123",
148
private static final String[][] TYPE_3_EXPECTED_OUTPUTS = {
150
"Test.test bool TestOptionBool = false",
151
"Test.test intx TestOptionInt = -1",
152
"Test.test uintx TestOptionUint = 1",
153
"Test.test bool TestOptionBool2 = true",
154
"Test.test double TestOptionDouble = 1.123000"
158
private static final String[][] TYPE_4_ARGUMENTS = {
160
"-XX:CompileCommand=TestOptionList,Test::test,_foo,_bar",
161
"-XX:CompileCommand=TestOptionStr,Test::test,_foo",
162
"-XX:CompileCommand=TestOptionBool,Test::test,false",
163
"-XX:CompileCommand=TestOptionInt,Test::test,-1",
164
"-XX:CompileCommand=TestOptionUint,Test::test,1",
165
"-XX:CompileCommand=TestOptionBool2,Test::test",
166
"-XX:CompileCommand=TestOptionDouble,Test::test,1.123",
167
"-XX:CompileCommand=TestOptionDouble,Test.test2,1.123",
172
private static final String[][] TYPE_4_EXPECTED_OUTPUTS = {
174
"CompileCommand: TestOptionList Test.test const char* TestOptionList = '_foo _bar'",
175
"CompileCommand: TestOptionStr Test.test const char* TestOptionStr = '_foo'",
176
"CompileCommand: TestOptionBool Test.test bool TestOptionBool = false",
177
"CompileCommand: TestOptionInt Test.test intx TestOptionInt = -1",
178
"CompileCommand: TestOptionUint Test.test uintx TestOptionUint = 1",
179
"CompileCommand: TestOptionBool2 Test.test bool TestOptionBool2 = true",
180
"CompileCommand: TestOptionDouble Test.test double TestOptionDouble = 1.123000",
181
"CompileCommand: TestOptionDouble Test.test2 double TestOptionDouble = 1.123000"
185
private static final String[][] TYPE_4_INVALID_ARGUMENTS = {
187
"-XX:CompileCommand=InvalidOption,Test::test,_foo,_bar",
188
"-XX:CompileCommand=TestOptionInt,Test::test,_foo",
189
"-XX:CompileCommand=TestOptionBool,Test::test,1",
190
"-XX:CompileCommand=TestOptionDouble,Test::test,-1",
191
"-XX:CompileCommand=TestOptionUint,Test::test",
192
"-XX:CompileCommand=TestOptionBool2,Test::test,falsee",
193
"-XX:CompileCommand=TestOptionDouble,Test::test,true",
194
"-XX:CompileCommand=TestOptionDouble,Test.test2,1.f",
199
private static final String[][] TYPE_4_INVALID_OUTPUTS = {
201
"Unrecognized option 'InvalidOption'",
202
"Value cannot be read for option 'TestOptionInt' of type 'intx'",
203
"Value cannot be read for option 'TestOptionBool' of type 'bool'",
204
"Value cannot be read for option 'TestOptionDouble' of type 'double'",
205
"Option 'TestOptionUint' is not followed by a value",
206
"Value cannot be read for option 'TestOptionBool2' of type 'bool'",
207
"Value cannot be read for option 'TestOptionDouble' of type 'double'",
208
"Value cannot be read for option 'TestOptionDouble' of type 'double'"
212
private static final String[][] TYPE_2_INVALID_ARGUMENTS = {
215
"-XX:CompileCommand=option,Test::test,bool",
220
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption",
225
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,100",
230
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx",
235
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption",
240
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption,true",
245
"-XX:CompileCommand=option,Test::test,double,MyDoubleOption,1",
250
private static void verifyValidOption(String[] arguments, String[] expected_outputs) throws Exception {
254
pb = ProcessTools.createLimitedTestJavaProcessBuilder(arguments);
255
out = new OutputAnalyzer(pb.start());
257
for (String expected_output : expected_outputs) {
258
out.shouldContain(expected_output);
261
out.shouldNotContain("CompileCommand: An error occurred during parsing");
262
out.shouldHaveExitValue(0);
265
private static void verifyInvalidOption(String[] arguments) throws Exception {
269
pb = ProcessTools.createLimitedTestJavaProcessBuilder(arguments);
270
out = new OutputAnalyzer(pb.start());
272
out.shouldContain("CompileCommand: An error occurred during parsing");
273
out.shouldHaveExitValue(1);
276
private static void verifyInvalidOption(String[] arguments, String[] expected_outputs) throws Exception {
280
pb = ProcessTools.createLimitedTestJavaProcessBuilder(arguments);
281
out = new OutputAnalyzer(pb.start());
283
for (String expected_output : expected_outputs) {
284
out.shouldContain(expected_output);
287
out.shouldContain("CompileCommand: An error occurred during parsing");
288
out.shouldHaveExitValue(1);
293
public static void main(String[] args) throws Exception {
295
if (TYPE_1_ARGUMENTS.length != TYPE_1_EXPECTED_OUTPUTS.length) {
296
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (1) options does not match.");
299
if (TYPE_2_ARGUMENTS.length != TYPE_2_EXPECTED_OUTPUTS.length) {
300
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (2) options does not match.");
303
if (TYPE_3_ARGUMENTS.length != TYPE_3_EXPECTED_OUTPUTS.length) {
304
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (3) options does not match.");
307
if (TYPE_4_ARGUMENTS.length != TYPE_4_EXPECTED_OUTPUTS.length) {
308
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (4) options does not match.");
312
for (int i = 0; i < TYPE_1_ARGUMENTS.length; i++) {
313
verifyValidOption(TYPE_1_ARGUMENTS[i], TYPE_1_EXPECTED_OUTPUTS[i]);
317
for (int i = 0; i < TYPE_2_ARGUMENTS.length; i++) {
318
verifyValidOption(TYPE_2_ARGUMENTS[i], TYPE_2_EXPECTED_OUTPUTS[i]);
322
for (int i = 0; i < TYPE_3_ARGUMENTS.length; i++) {
323
verifyValidOption(TYPE_3_ARGUMENTS[i], TYPE_3_EXPECTED_OUTPUTS[i]);
327
for (int i = 0; i < TYPE_4_ARGUMENTS.length; i++) {
328
verifyValidOption(TYPE_4_ARGUMENTS[i], TYPE_4_EXPECTED_OUTPUTS[i]);
333
for (String[] arguments: TYPE_2_INVALID_ARGUMENTS) {
334
verifyInvalidOption(arguments);
339
for (int i = 0; i < TYPE_4_INVALID_ARGUMENTS.length; i++) {
340
verifyInvalidOption(TYPE_4_INVALID_ARGUMENTS[i], TYPE_4_INVALID_OUTPUTS[i]);
344
for (int i = 0; i < FILE_ARGUMENTS.length; i++) {
345
verifyValidOption(FILE_ARGUMENTS[i], FILE_EXPECTED_OUTPUT[i]);