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 import jdk.test.lib.ExitCode; 25 import jdk.test.lib.Platform; 26 import jdk.test.lib.cli.CommandLineOptionTest; 27 import jdk.test.lib.cli.predicate.AndPredicate; 28 import jdk.test.lib.cli.predicate.OrPredicate; 29 30 /** 31 * Generic test case for SHA-related options targeted to CPUs which 32 * support instructions required by the tested option. 33 */ 34 public class GenericTestCaseForSupportedCPU extends 35 SHAOptionsBase.TestCase { 36 public GenericTestCaseForSupportedCPU(String optionName) { 37 super(optionName, 38 new AndPredicate( 39 new OrPredicate(Platform::isSparc, Platform::isAArch64), 40 SHAOptionsBase.getPredicateForOption(optionName))); 41 } 42 43 @Override 44 protected void verifyWarnings() throws Throwable { 45 46 String shouldPassMessage = String.format("JVM should start with option" 47 + " '%s' without any warnings", optionName); 48 // Verify that there are no warning when option is explicitly enabled. 49 CommandLineOptionTest.verifySameJVMStartup(null, new String[] { 50 SHAOptionsBase.getWarningForUnsupportedCPU(optionName) 51 }, shouldPassMessage, shouldPassMessage, ExitCode.OK, 52 CommandLineOptionTest.prepareBooleanFlag(optionName, true)); 53 54 // Verify that option could be disabled even if +UseSHA was passed to 55 // JVM. 56 CommandLineOptionTest.verifySameJVMStartup(null, new String[] { 57 SHAOptionsBase.getWarningForUnsupportedCPU(optionName) 58 }, shouldPassMessage, String.format("It should be able to " 59 + "disable option '%s' even if %s was passed to JVM", 60 optionName, CommandLineOptionTest.prepareBooleanFlag( 61 SHAOptionsBase.USE_SHA_OPTION, true)), 62 ExitCode.OK, 63 CommandLineOptionTest.prepareBooleanFlag( 64 SHAOptionsBase.USE_SHA_OPTION, true), 65 CommandLineOptionTest.prepareBooleanFlag(optionName, false)); 66 67 if (!optionName.equals(SHAOptionsBase.USE_SHA_OPTION)) { 68 // Verify that if -XX:-UseSHA is passed to the JVM, it is not possible 69 // to enable the tested option and a warning is printed. 70 CommandLineOptionTest.verifySameJVMStartup( 71 new String[] { SHAOptionsBase.getWarningForUnsupportedCPU(optionName) }, 72 null, 73 shouldPassMessage, 74 String.format("Enabling option '%s' should not be possible and should result in a warning if %s was passed to JVM", 75 optionName, 76 CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false)), 77 ExitCode.OK, 78 CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false), 79 CommandLineOptionTest.prepareBooleanFlag(optionName, true)); 80 } 81 } 82 83 @Override 84 protected void verifyOptionValues() throws Throwable { 85 // Verify that "It should be able to disable option " 86 87 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "true", 88 String.format("Option '%s' should be enabled by default", 89 optionName)); 90 91 // Verify that it is possible to explicitly enable the option. 92 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "true", 93 String.format("Option '%s' was set to have value 'true'", 94 optionName), 95 CommandLineOptionTest.prepareBooleanFlag(optionName, true)); 96 97 // Verify that it is possible to explicitly disable the option. 98 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false", 99 String.format("Option '%s' was set to have value 'false'", 100 optionName), 101 CommandLineOptionTest.prepareBooleanFlag(optionName, false)); 102 103 // verify that option is disabled when -UseSHA was passed to JVM. 104 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false", 105 String.format("Option '%s' should have value 'false' when %s" 106 + " flag set to JVM", optionName, 107 CommandLineOptionTest.prepareBooleanFlag( 108 SHAOptionsBase.USE_SHA_OPTION, false)), 109 CommandLineOptionTest.prepareBooleanFlag(optionName, true), 110 CommandLineOptionTest.prepareBooleanFlag( 111 SHAOptionsBase.USE_SHA_OPTION, false)); 112 113 // Verify that it is possible to explicitly disable the tested option 114 // even if +UseSHA was passed to JVM. 115 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false", 116 String.format("Option '%s' should have value 'false' if set so" 117 + " even if %s flag set to JVM", optionName, 118 CommandLineOptionTest.prepareBooleanFlag( 119 SHAOptionsBase.USE_SHA_OPTION, true)), 120 CommandLineOptionTest.prepareBooleanFlag( 121 SHAOptionsBase.USE_SHA_OPTION, true), 122 CommandLineOptionTest.prepareBooleanFlag(optionName, false)); 123 } 124 }