1 /* 2 * Copyright (c) 2014, 2020, 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.DigestOptionsBase; 27 import compiler.testlibrary.sha.predicate.IntrinsicPredicates; 28 import jdk.test.lib.Asserts; 29 import jdk.test.lib.process.ExitCode; 30 import jdk.test.lib.Platform; 31 import jdk.test.lib.cli.CommandLineOptionTest; 32 import jdk.test.lib.cli.predicate.AndPredicate; 33 import jdk.test.lib.cli.predicate.NotPredicate; 34 import jdk.test.lib.cli.predicate.OrPredicate; 35 36 /** 37 * UseSHA specific test case targeted to CPUs which don't support all 38 * sha* instructions. 39 */ 40 public class UseSHASpecificTestCaseForUnsupportedCPU 41 extends DigestOptionsBase.TestCase { 42 public UseSHASpecificTestCaseForUnsupportedCPU(String optionName) { 43 super(DigestOptionsBase.USE_SHA_OPTION, new NotPredicate( 44 IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE)); 45 46 Asserts.assertEQ(optionName, DigestOptionsBase.USE_SHA_OPTION, 47 "Test case should be used for " + DigestOptionsBase.USE_SHA_OPTION 48 + " option only."); 49 } 50 51 @Override 52 protected void verifyWarnings() throws Throwable { 53 // Verify that attempt to use UseSHA option will cause a warning. 54 String shouldPassMessage = String.format("JVM startup should pass with" 55 + " '%s' option on unsupported CPU, but there should be" 56 + "the message shown.", optionName); 57 CommandLineOptionTest.verifySameJVMStartup(new String[] { 58 DigestOptionsBase.getWarningForUnsupportedCPU(optionName) 59 }, null, shouldPassMessage, shouldPassMessage, ExitCode.OK, 60 CommandLineOptionTest.prepareBooleanFlag(optionName, true)); 61 } 62 63 @Override 64 protected void verifyOptionValues() throws Throwable { 65 // Verify that UseSHA option remains disabled even if all 66 // UseSHA*Intrinsics were enabled. 67 CommandLineOptionTest.verifyOptionValueForSameVM( 68 DigestOptionsBase.USE_SHA_OPTION, "false", String.format( 69 "%s option should be disabled on unsupported CPU" 70 + " even if all UseSHA*Intrinsics options were enabled.", 71 DigestOptionsBase.USE_SHA_OPTION), 72 DigestOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS, 73 CommandLineOptionTest.prepareBooleanFlag( 74 DigestOptionsBase.USE_SHA1_INTRINSICS_OPTION, true), 75 CommandLineOptionTest.prepareBooleanFlag( 76 DigestOptionsBase.USE_SHA256_INTRINSICS_OPTION, true), 77 CommandLineOptionTest.prepareBooleanFlag( 78 DigestOptionsBase.USE_SHA512_INTRINSICS_OPTION, true)); 79 80 // Verify that UseSHA option remains disabled even if all 81 // UseSHA*Intrinsics options were enabled and UseSHA was enabled as well. 82 CommandLineOptionTest.verifyOptionValueForSameVM( 83 DigestOptionsBase.USE_SHA_OPTION, "false", String.format( 84 "%s option should be disabled on unsupported CPU" 85 + " even if all UseSHA*Intrinsics options were enabled" 86 + " and %s was enabled as well", 87 DigestOptionsBase.USE_SHA_OPTION, 88 DigestOptionsBase.USE_SHA_OPTION), 89 DigestOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS, 90 CommandLineOptionTest.prepareBooleanFlag( 91 DigestOptionsBase.USE_SHA_OPTION, true), 92 CommandLineOptionTest.prepareBooleanFlag( 93 DigestOptionsBase.USE_SHA1_INTRINSICS_OPTION, true), 94 CommandLineOptionTest.prepareBooleanFlag( 95 DigestOptionsBase.USE_SHA256_INTRINSICS_OPTION, true), 96 CommandLineOptionTest.prepareBooleanFlag( 97 DigestOptionsBase.USE_SHA512_INTRINSICS_OPTION, true)); 98 } 99 }