1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
/*
* Copyright (c) 2014, 2021, 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 CheckCompileCommandOption
* @summary Checks parsing of -XX:CompileCommand=option
* @bug 8055286 8056964 8059847 8069035
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.management
* @requires vm.flagless
* @requires vm.debug == true
* @run driver compiler.oracle.CheckCompileCommandOption
*/
package compiler.oracle;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import java.io.File;
public class CheckCompileCommandOption {
// Currently, two types of trailing options can be used with
// -XX:CompileCommand=option
//
// (1) CompileCommand=option,Klass::method,option
// (2) CompileCommand=option,Klass::method,type,option,value
//
// Type (1) is used to enable a boolean option for a method.
//
// Type (2) is used to support options with a value. Values can
// have the the following types: intx, uintx, bool, ccstr,
// ccstrlist, and double.
private static final String[][] FILE_ARGUMENTS = {
{
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command1.txt"),
"-version"
},
{
"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command2.txt"),
"-version"
}
};
private static final String[][] FILE_EXPECTED_OUTPUT = {
{
"com/oracle/Test.test1 bool TestOptionBool = true",
"com/oracle/Test.test2 bool TestOptionBool = true",
"com/oracle/Test.test3 bool TestOptionBool = true",
"com/oracle/Test.test4 bool TestOptionBool = true",
"com/oracle/Test.test4 bool TestOptionBool2 = true",
"com/oracle/Test.test5 bool TestOptionBool = true",
"com/oracle/Test.test5 bool TestOptionBool2 = true",
"com/oracle/Test.test6(I) bool TestOptionBool = true",
"com/oracle/Test.test7(I) bool TestOptionBool = true",
"com/oracle/Test.test8(I) bool TestOptionBool = true",
"com/oracle/Test.test9(I) bool TestOptionBool = true",
"com/oracle/Test.test9(I) bool TestOptionBool2 = true",
"com/oracle/Test.test10(I) bool TestOptionBool = true",
"com/oracle/Test.test10(I) bool TestOptionBool2 = true"
},
{
"Test.test const char* TestOptionList = '_foo _bar'",
"Test.test const char* TestOptionStr = '_foo'",
"Test.test bool TestOptionBool = false",
"Test.test intx TestOptionInt = -1",
"Test.test uintx TestOptionUint = 1",
"Test.test bool TestOptionBool2 = true",
"Test.test double TestOptionDouble = 1.123000"
}
};
private static final String[][] TYPE_1_ARGUMENTS = {
{
"-XX:CompileCommand=option,com/oracle/Test.test,TestOptionBool",
"-XX:CompileCommand=option,com/oracle/Test,test,TestOptionBool2",
"-XX:CompileCommand=option,com/oracle/Test.test2,TestOptionBool2,TestOptionBool",
"-version"
}
};
private static final String[][] TYPE_1_EXPECTED_OUTPUTS = {
{
"com/oracle/Test.test bool TestOptionBool = true",
"com/oracle/Test.test bool TestOptionBool2 = true",
"com/oracle/Test.test2 bool TestOptionBool = true",
"com/oracle/Test.test2 bool TestOptionBool2 = true",
}
};
private static final String[][] TYPE_2_ARGUMENTS = {
{
"-XX:CompileCommand=option,Test::test,ccstrlist,TestOptionList,_foo,_bar",
"-XX:CompileCommand=option,Test::test,ccstr,TestOptionStr,_foo",
"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false",
"-XX:CompileCommand=option,Test::test,intx,TestOptionInt,-1",
"-XX:CompileCommand=option,Test::test,uintx,TestOptionUint,1",
"-XX:CompileCommand=option,Test::test,TestOptionBool2",
"-XX:CompileCommand=option,Test::test,double,TestOptionDouble,1.123",
"-XX:CompileCommand=option,Test.test2,double,TestOptionDouble,1.123",
"-version"
}
};
private static final String[][] TYPE_2_EXPECTED_OUTPUTS = {
{
"Test.test const char* TestOptionList = '_foo _bar'",
"Test.test const char* TestOptionStr = '_foo'",
"Test.test bool TestOptionBool = false",
"Test.test intx TestOptionInt = -1",
"Test.test uintx TestOptionUint = 1",
"Test.test bool TestOptionBool2 = true",
"Test.test double TestOptionDouble = 1.123000",
"Test.test2 double TestOptionDouble = 1.123000"
}
};
private static final String[][] TYPE_3_ARGUMENTS = {
{
"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false,intx,TestOptionInt,-1,uintx,TestOptionUint,1,TestOptionBool2,double,TestOptionDouble,1.123",
"-version"
}
};
private static final String[][] TYPE_3_EXPECTED_OUTPUTS = {
{
"Test.test bool TestOptionBool = false",
"Test.test intx TestOptionInt = -1",
"Test.test uintx TestOptionUint = 1",
"Test.test bool TestOptionBool2 = true",
"Test.test double TestOptionDouble = 1.123000"
}
};
private static final String[][] TYPE_4_ARGUMENTS = {
{
"-XX:CompileCommand=TestOptionList,Test::test,_foo,_bar",
"-XX:CompileCommand=TestOptionStr,Test::test,_foo",
"-XX:CompileCommand=TestOptionBool,Test::test,false",
"-XX:CompileCommand=TestOptionInt,Test::test,-1",
"-XX:CompileCommand=TestOptionUint,Test::test,1",
"-XX:CompileCommand=TestOptionBool2,Test::test",
"-XX:CompileCommand=TestOptionDouble,Test::test,1.123",
"-XX:CompileCommand=TestOptionDouble,Test.test2,1.123",
"-version"
}
};
private static final String[][] TYPE_4_EXPECTED_OUTPUTS = {
{
"CompileCommand: TestOptionList Test.test const char* TestOptionList = '_foo _bar'",
"CompileCommand: TestOptionStr Test.test const char* TestOptionStr = '_foo'",
"CompileCommand: TestOptionBool Test.test bool TestOptionBool = false",
"CompileCommand: TestOptionInt Test.test intx TestOptionInt = -1",
"CompileCommand: TestOptionUint Test.test uintx TestOptionUint = 1",
"CompileCommand: TestOptionBool2 Test.test bool TestOptionBool2 = true",
"CompileCommand: TestOptionDouble Test.test double TestOptionDouble = 1.123000",
"CompileCommand: TestOptionDouble Test.test2 double TestOptionDouble = 1.123000"
}
};
private static final String[][] TYPE_4_INVALID_ARGUMENTS = {
{
"-XX:CompileCommand=InvalidOption,Test::test,_foo,_bar",
"-XX:CompileCommand=TestOptionInt,Test::test,_foo",
"-XX:CompileCommand=TestOptionBool,Test::test,1",
"-XX:CompileCommand=TestOptionDouble,Test::test,-1",
"-XX:CompileCommand=TestOptionUint,Test::test",
"-XX:CompileCommand=TestOptionBool2,Test::test,falsee",
"-XX:CompileCommand=TestOptionDouble,Test::test,true",
"-XX:CompileCommand=TestOptionDouble,Test.test2,1.f",
"-version"
}
};
private static final String[][] TYPE_4_INVALID_OUTPUTS = {
{
"Unrecognized option 'InvalidOption'",
"Value cannot be read for option 'TestOptionInt' of type 'intx'",
"Value cannot be read for option 'TestOptionBool' of type 'bool'",
"Value cannot be read for option 'TestOptionDouble' of type 'double'",
"Option 'TestOptionUint' is not followed by a value",
"Value cannot be read for option 'TestOptionBool2' of type 'bool'",
"Value cannot be read for option 'TestOptionDouble' of type 'double'",
"Value cannot be read for option 'TestOptionDouble' of type 'double'"
}
};
private static final String[][] TYPE_2_INVALID_ARGUMENTS = {
{
// bool flag name missing
"-XX:CompileCommand=option,Test::test,bool",
"-version"
},
{
// bool flag value missing
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption",
"-version"
},
{
// wrong value for bool flag
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,100",
"-version"
},
{
// intx flag name missing
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx",
"-version"
},
{
// intx flag value missing
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption",
"-version"
},
{
// wrong value for intx flag
"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption,true",
"-version"
},
{
// wrong value for flag double flag
"-XX:CompileCommand=option,Test::test,double,MyDoubleOption,1",
"-version"
}
};
private static void verifyValidOption(String[] arguments, String[] expected_outputs) throws Exception {
ProcessBuilder pb;
OutputAnalyzer out;
pb = ProcessTools.createJavaProcessBuilder(arguments);
out = new OutputAnalyzer(pb.start());
for (String expected_output : expected_outputs) {
out.shouldContain(expected_output);
}
out.shouldNotContain("CompileCommand: An error occurred during parsing");
out.shouldHaveExitValue(0);
}
private static void verifyInvalidOption(String[] arguments) throws Exception {
ProcessBuilder pb;
OutputAnalyzer out;
pb = ProcessTools.createJavaProcessBuilder(arguments);
out = new OutputAnalyzer(pb.start());
out.shouldContain("CompileCommand: An error occurred during parsing");
out.shouldHaveExitValue(0);
}
private static void verifyInvalidOption(String[] arguments, String[] expected_outputs) throws Exception {
ProcessBuilder pb;
OutputAnalyzer out;
pb = ProcessTools.createJavaProcessBuilder(arguments);
out = new OutputAnalyzer(pb.start());
for (String expected_output : expected_outputs) {
out.shouldContain(expected_output);
}
out.shouldContain("CompileCommand: An error occurred during parsing");
out.shouldHaveExitValue(0);
}
public static void main(String[] args) throws Exception {
if (TYPE_1_ARGUMENTS.length != TYPE_1_EXPECTED_OUTPUTS.length) {
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (1) options does not match.");
}
if (TYPE_2_ARGUMENTS.length != TYPE_2_EXPECTED_OUTPUTS.length) {
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (2) options does not match.");
}
if (TYPE_3_ARGUMENTS.length != TYPE_3_EXPECTED_OUTPUTS.length) {
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (3) options does not match.");
}
if (TYPE_4_ARGUMENTS.length != TYPE_4_EXPECTED_OUTPUTS.length) {
throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (4) options does not match.");
}
// Check if type (1) options are parsed correctly
for (int i = 0; i < TYPE_1_ARGUMENTS.length; i++) {
verifyValidOption(TYPE_1_ARGUMENTS[i], TYPE_1_EXPECTED_OUTPUTS[i]);
}
// Check if type (2) options are parsed correctly
for (int i = 0; i < TYPE_2_ARGUMENTS.length; i++) {
verifyValidOption(TYPE_2_ARGUMENTS[i], TYPE_2_EXPECTED_OUTPUTS[i]);
}
// Check if type (3) options are parsed correctly
for (int i = 0; i < TYPE_3_ARGUMENTS.length; i++) {
verifyValidOption(TYPE_3_ARGUMENTS[i], TYPE_3_EXPECTED_OUTPUTS[i]);
}
// Check if type (4) options are parsed correctly
for (int i = 0; i < TYPE_4_ARGUMENTS.length; i++) {
verifyValidOption(TYPE_4_ARGUMENTS[i], TYPE_4_EXPECTED_OUTPUTS[i]);
}
// Check if error is reported for invalid type (2) options
// (flags with type information specified)
for (String[] arguments: TYPE_2_INVALID_ARGUMENTS) {
verifyInvalidOption(arguments);
}
// Check if error is reported for invalid type (2) options
// (flags with type information specified)
for (int i = 0; i < TYPE_4_INVALID_ARGUMENTS.length; i++) {
verifyInvalidOption(TYPE_4_INVALID_ARGUMENTS[i], TYPE_4_INVALID_OUTPUTS[i]);
}
// Check if commands in command file are parsed correctly
for (int i = 0; i < FILE_ARGUMENTS.length; i++) {
verifyValidOption(FILE_ARGUMENTS[i], FILE_EXPECTED_OUTPUT[i]);
}
}
}
|