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         // Verify that it is possible to enable the tested option and disable
  68         // all SHA intrinsics via -UseSHA without any warnings.
  69         CommandLineOptionTest.verifySameJVMStartup(null, new String[] {
  70                         SHAOptionsBase.getWarningForUnsupportedCPU(optionName)
  71                 }, shouldPassMessage, String.format("It should be able to "
  72                         + "enable option '%s' even if %s was passed to JVM",
  73                         optionName, CommandLineOptionTest.prepareBooleanFlag(
  74                             SHAOptionsBase.USE_SHA_OPTION, false)),
  75                 ExitCode.OK,
  76                 CommandLineOptionTest.prepareBooleanFlag(
  77                         SHAOptionsBase.USE_SHA_OPTION, false),
  78                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
  79     }
  80 
  81     @Override
  82     protected void verifyOptionValues() throws Throwable {
  83         // Verify that "It should be able to disable option "
  84 
  85         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "true",
  86                 String.format("Option '%s' should be enabled by default",
  87                         optionName));
  88 
  89         // Verify that it is possible to explicitly enable the option.
  90         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "true",
  91                 String.format("Option '%s' was set to have value 'true'",
  92                         optionName),
  93                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
  94 
  95         // Verify that it is possible to explicitly disable the option.
  96         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
  97                 String.format("Option '%s' was set to have value 'false'",
  98                         optionName),
  99                 CommandLineOptionTest.prepareBooleanFlag(optionName, false));
 100 
 101         // verify that option is disabled when -UseSHA was passed to JVM.
 102         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
 103                 String.format("Option '%s' should have value 'false' when %s"
 104                         + " flag set to JVM", optionName,
 105                         CommandLineOptionTest.prepareBooleanFlag(
 106                             SHAOptionsBase.USE_SHA_OPTION, false)),
 107                 CommandLineOptionTest.prepareBooleanFlag(optionName, true),
 108                 CommandLineOptionTest.prepareBooleanFlag(
 109                         SHAOptionsBase.USE_SHA_OPTION, false));
 110 
 111         // Verify that it is possible to explicitly disable the tested option
 112         // even if +UseSHA was passed to JVM.
 113         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
 114                 String.format("Option '%s' should have value 'false' if set so"
 115                         + " even if %s flag set to JVM", optionName,
 116                         CommandLineOptionTest.prepareBooleanFlag(
 117                             SHAOptionsBase.USE_SHA_OPTION, true)),
 118                 CommandLineOptionTest.prepareBooleanFlag(
 119                         SHAOptionsBase.USE_SHA_OPTION, true),
 120                 CommandLineOptionTest.prepareBooleanFlag(optionName, false));
 121     }
 122 }