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