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