1 /* 2 * Copyright (c) 2014, 2015, 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 package compiler.arguments; 25 26 import jdk.test.lib.ExitCode; 27 import jdk.test.lib.Platform; 28 import jdk.test.lib.cli.CommandLineOptionTest; 29 30 /** 31 * Test on bit manipulation related command line options, 32 * that should be executed on CPU that does not support 33 * required features. 34 * 35 * Note that this test intended to verify that VM could be launched with 36 * specific options and that values of these options processed correctly. 37 * In order to do that test launch a new VM with tested options, the same 38 * flavor-specific flag as one that was used for parent VM (-client, -server, 39 * -minimal, -graal) and '-version'. 40 */ 41 public class BMIUnsupportedCPUTest extends BMICommandLineOptionTestBase { 42 43 /** 44 * Construct new test on {@code optionName} option. 45 * 46 * @param optionName Name of the option to be tested 47 * without -XX:[+-] prefix. 48 * @param warningMessage Message that can occur in VM output 49 * if CPU on test box does not support 50 * features required by the option. 51 * @param cpuFeatures CPU features requires by the option. 52 */ 53 public BMIUnsupportedCPUTest(String optionName, 54 String warningMessage, 55 String... cpuFeatures) { 56 super(optionName, warningMessage, null, cpuFeatures); 57 } 58 59 @Override 60 public void runTestCases() throws Throwable { 61 if (Platform.isX86() || Platform.isX64()) { 62 unsupportedX86CPUTestCases(); 63 } else { 64 unsupportedNonX86CPUTestCases(); 65 } 66 } 67 68 /** 69 * Run test cases common for all bit manipulation related VM options 70 * targeted to X86 CPU that does not support required features. 71 * 72 * @throws Throwable if test failed. 73 */ 74 public void unsupportedX86CPUTestCases() throws Throwable { 75 76 /* 77 Verify that VM will successfully start up, but output will contain a 78 warning. VM will be launched with following options: 79 -XX:+<tested option> -version 80 */ 81 String errorString = String.format("JVM should start with '-XX:+%s' " 82 + "flag, but output should contain warning.", optionName); 83 CommandLineOptionTest.verifySameJVMStartup( 84 new String[] { warningMessage }, new String[] { errorMessage }, 85 errorString, String.format("Option '%s' is unsupported.%n" 86 + "Warning expected to be shown.", optionName), ExitCode.OK, 87 CommandLineOptionTest.prepareBooleanFlag( 88 optionName, true)); 89 90 /* 91 Verify that VM will successfully startup without any warnings. 92 VM will be launched with following options: 93 -XX:-<tested option> -version 94 */ 95 errorString = String.format("JVM should start with '-XX:-%s' flag " 96 + "without any warnings", optionName); 97 CommandLineOptionTest.verifySameJVMStartup(null, 98 new String[] { warningMessage, errorMessage }, 99 errorString, errorString, ExitCode.OK, 100 CommandLineOptionTest.prepareBooleanFlag(optionName, false)); 101 102 /* 103 * Verify that on unsupported CPUs option is off by default. VM will be 104 * launched with following options: -version 105 */ 106 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false", 107 String.format("Option '%s' is expected to have default value " 108 + "'false' since feature required is not supported " 109 + "on CPU", optionName)); 110 111 /* 112 Verify that on unsupported CPUs option will be off even if 113 it was explicitly turned on by user. VM will be launched with 114 following options: -XX:+<tested option> -version 115 */ 116 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false", 117 String.format("Option '%s' is expected to have default value" 118 + " 'false' since feature required is not supported on" 119 + " CPU even if user set another value.", optionName), 120 CommandLineOptionTest.prepareBooleanFlag(optionName, true)); 121 122 } 123 124 /** 125 * Run test cases common for all bit manipulation related VM options 126 * targeted to non-X86 CPU that does not support required features. 127 * 128 * @throws Throwable if test failed. 129 */ 130 public void unsupportedNonX86CPUTestCases() throws Throwable { 131 132 /* 133 Verify that VM known nothing about tested option. VM will be launched 134 with following options: -XX:[+-]<tested option> -version 135 */ 136 CommandLineOptionTest.verifySameJVMStartup( 137 new String[] { errorMessage }, null, 138 String.format("JVM startup should fail with '-XX:+%s' flag." 139 + "%nOption should be unknown (non-X86CPU).", 140 optionName), "", ExitCode.FAIL, 141 CommandLineOptionTest.prepareBooleanFlag(optionName, true)); 142 143 CommandLineOptionTest.verifySameJVMStartup( 144 new String[] { errorMessage }, null, 145 String.format("JVM startup should fail with '-XX:-%s' flag." 146 + "%nOption should be unknown (non-X86CPU)", 147 optionName), "", ExitCode.FAIL, 148 CommandLineOptionTest.prepareBooleanFlag(optionName, false)); 149 } 150 } 151