1 /*
   2  * Copyright (c) 2014, 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 com.oracle.java.testlibrary.Asserts;
  25 import com.oracle.java.testlibrary.ExitCode;
  26 import com.oracle.java.testlibrary.Platform;
  27 import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
  28 import com.oracle.java.testlibrary.cli.predicate.AndPredicate;
  29 import com.oracle.java.testlibrary.cli.predicate.NotPredicate;
  30 import sha.predicate.IntrinsicPredicates;
  31 
  32 /**
  33  * UseSHA specific test case targeted to SPARC CPUs which don't support all sha*
  34  * instructions.
  35  */
  36 public class UseSHASpecificTestCaseForUnsupportedSparcCPU
  37         extends SHAOptionsBase.TestCase {
  38     public UseSHASpecificTestCaseForUnsupportedSparcCPU(String optionName) {
  39         super(SHAOptionsBase.USE_SHA_OPTION, new AndPredicate(Platform::isSparc,
  40                 new NotPredicate(
  41                         IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE)));
  42 
  43         Asserts.assertEQ(optionName, SHAOptionsBase.USE_SHA_OPTION,
  44                 "Test case should be used for " + SHAOptionsBase.USE_SHA_OPTION
  45                         + " option only.");
  46     }
  47 
  48     @Override
  49     protected void verifyWarnings() throws Throwable {
  50         // Verify that attempt to use UseSHA option will cause a warning.
  51         CommandLineOptionTest.verifySameJVMStartup(new String[] {
  52                         SHAOptionsBase.getWarningForUnsupportedCPU(optionName)
  53                 }, null, ExitCode.OK,
  54                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
  55     }
  56 
  57     @Override
  58     protected void verifyOptionValues() throws Throwable {
  59         // Verify that UseSHA option remains disabled even if all
  60         // UseSHA*Intrincs options were enabled.
  61         CommandLineOptionTest.verifyOptionValueForSameVM(
  62                 SHAOptionsBase.USE_SHA_OPTION, "false",
  63                 CommandLineOptionTest.prepareBooleanFlag(
  64                         SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION, true),
  65                 CommandLineOptionTest.prepareBooleanFlag(
  66                         SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION, true),
  67                 CommandLineOptionTest.prepareBooleanFlag(
  68                         SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION, true));
  69 
  70         // Verify that UseSHA option remains disabled even if all
  71         // UseSHA*Intrincs options were enabled and UseSHA was enabled as well.
  72         CommandLineOptionTest.verifyOptionValueForSameVM(
  73                 SHAOptionsBase.USE_SHA_OPTION, "false",
  74                 CommandLineOptionTest.prepareBooleanFlag(
  75                         SHAOptionsBase.USE_SHA_OPTION, true),
  76                 CommandLineOptionTest.prepareBooleanFlag(
  77                         SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION, true),
  78                 CommandLineOptionTest.prepareBooleanFlag(
  79                         SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION, true),
  80                 CommandLineOptionTest.prepareBooleanFlag(
  81                         SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION, true));
  82     }
  83 }