< prev index next >

test/compiler/intrinsics/sha/cli/SHAOptionsBase.java

Print this page
rev 11557 : 8132919: use package in compiler tests
Reviewed-by: duke


   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.Platform;
  25 import jdk.test.lib.cli.CommandLineOptionTest;
  26 import compiler.testlibrary.sha.predicate.IntrinsicPredicates;
  27 
  28 import java.util.function.BooleanSupplier;
  29 
  30 /**
  31  * Base class for all CLI tests on SHA-related options.
  32  *
  33  * Instead of using huge complex tests for each option, each test is constructed
  34  * from several test cases shared among different tests.
  35  */
  36 public class SHAOptionsBase extends CommandLineOptionTest {
  37     protected static final String USE_SHA_OPTION = "UseSHA";
  38     protected static final String USE_SHA1_INTRINSICS_OPTION
  39             = "UseSHA1Intrinsics";
  40     protected static final String USE_SHA256_INTRINSICS_OPTION
  41             = "UseSHA256Intrinsics";
  42     protected static final String USE_SHA512_INTRINSICS_OPTION
  43             = "UseSHA512Intrinsics";
  44 
  45     // Intrinsics flags are of diagnostic type
  46     // and must be preceded by UnlockDiagnosticVMOptions.
  47     protected static final String UNLOCK_DIAGNOSTIC_VM_OPTIONS
  48             = "-XX:+UnlockDiagnosticVMOptions";
  49 
  50     // Note that strings below will be passed to
  51     // CommandLineOptionTest.verifySameJVMStartup and thus are regular
  52     // expressions, not just a plain strings.
  53     protected static final String SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE
  54             = "SHA instructions are not available on this CPU";
  55     protected static final String SHA1_INTRINSICS_ARE_NOT_AVAILABLE
  56             = "Intrinsics for SHA-1 crypto hash functions not available on this CPU.";
  57     protected static final String SHA256_INTRINSICS_ARE_NOT_AVAILABLE
  58             = "Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.";
  59     protected static final String SHA512_INTRINSICS_ARE_NOT_AVAILABLE
  60             = "Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.";
  61 
  62     private final TestCase[] testCases;
  63 
  64     /**
  65      * Returns warning message that should occur in VM output if an option with
  66      * the name {@code optionName} was turned on and CPU does not support
  67      * required instructions.
  68      *
  69      * @param optionName The name of the option for which warning message should
  70      *                   be returned.
  71      * @return A warning message that will be printed out to VM output if CPU
  72      *         instructions required by the option are not supported.
  73      */
  74     protected static String getWarningForUnsupportedCPU(String optionName) {
  75         if (Platform.isSparc() || Platform.isAArch64() ||
  76             Platform.isX64() || Platform.isX86()) {
  77             switch (optionName) {
  78             case SHAOptionsBase.USE_SHA_OPTION:
  79                 return SHAOptionsBase.SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE;
  80             case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
  81                 return SHAOptionsBase.SHA1_INTRINSICS_ARE_NOT_AVAILABLE;
  82             case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
  83                 return SHAOptionsBase.SHA256_INTRINSICS_ARE_NOT_AVAILABLE;
  84             case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
  85                 return SHAOptionsBase.SHA512_INTRINSICS_ARE_NOT_AVAILABLE;
  86             default:
  87                 throw new Error("Unexpected option " + optionName);
  88             }
  89         } else {
  90             throw new Error("Support for CPUs different fromn X86, SPARC, and AARCH64 "
  91                             + "is not implemented");
  92         }
  93     }
  94 
  95     /**
  96      * Returns the predicate indicating whether or not CPU instructions required
  97      * by the option with name {@code optionName} are available.
  98      *
  99      * @param optionName The name of the option for which a predicate should be
 100      *                   returned.
 101      * @return The predicate on availability of CPU instructions required by the
 102      *         option.
 103      */
 104     protected static BooleanSupplier getPredicateForOption(String optionName) {
 105         switch (optionName) {
 106             case SHAOptionsBase.USE_SHA_OPTION:
 107                 return IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE;
 108             case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
 109                 return IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE;
 110             case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
 111                 return IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE;
 112             case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
 113                 return IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE;
 114             default:
 115                 throw new Error("Unexpected option " + optionName);
 116         }
 117     }
 118 
 119     public SHAOptionsBase(TestCase... testCases) {
 120         super(Boolean.TRUE::booleanValue);
 121         this.testCases = testCases;
 122     }
 123 
 124     @Override




   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;
  25 
  26 import compiler.testlibrary.sha.predicate.IntrinsicPredicates;
  27 import jdk.test.lib.Platform;
  28 import jdk.test.lib.cli.CommandLineOptionTest;

  29 
  30 import java.util.function.BooleanSupplier;
  31 
  32 /**
  33  * Base class for all CLI tests on SHA-related options.
  34  *
  35  * Instead of using huge complex tests for each option, each test is constructed
  36  * from several test cases shared among different tests.
  37  */
  38 public class SHAOptionsBase extends CommandLineOptionTest {
  39     public static final String USE_SHA_OPTION = "UseSHA";
  40     public static final String USE_SHA1_INTRINSICS_OPTION
  41             = "UseSHA1Intrinsics";
  42     public static final String USE_SHA256_INTRINSICS_OPTION
  43             = "UseSHA256Intrinsics";
  44     public static final String USE_SHA512_INTRINSICS_OPTION
  45             = "UseSHA512Intrinsics";
  46 
  47     // Intrinsics flags are of diagnostic type
  48     // and must be preceded by UnlockDiagnosticVMOptions.
  49     public static final String UNLOCK_DIAGNOSTIC_VM_OPTIONS
  50             = "-XX:+UnlockDiagnosticVMOptions";
  51 
  52     // Note that strings below will be passed to
  53     // CommandLineOptionTest.verifySameJVMStartup and thus are regular
  54     // expressions, not just a plain strings.
  55     protected static final String SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE
  56             = "SHA instructions are not available on this CPU";
  57     protected static final String SHA1_INTRINSICS_ARE_NOT_AVAILABLE
  58             = "Intrinsics for SHA-1 crypto hash functions not available on this CPU.";
  59     protected static final String SHA256_INTRINSICS_ARE_NOT_AVAILABLE
  60             = "Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.";
  61     protected static final String SHA512_INTRINSICS_ARE_NOT_AVAILABLE
  62             = "Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.";
  63 
  64     private final TestCase[] testCases;
  65 
  66     /**
  67      * Returns warning message that should occur in VM output if an option with
  68      * the name {@code optionName} was turned on and CPU does not support
  69      * required instructions.
  70      *
  71      * @param optionName The name of the option for which warning message should
  72      *                   be returned.
  73      * @return A warning message that will be printed out to VM output if CPU
  74      *         instructions required by the option are not supported.
  75      */
  76     public static String getWarningForUnsupportedCPU(String optionName) {
  77         if (Platform.isSparc() || Platform.isAArch64() ||
  78             Platform.isX64() || Platform.isX86()) {
  79             switch (optionName) {
  80             case SHAOptionsBase.USE_SHA_OPTION:
  81                 return SHAOptionsBase.SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE;
  82             case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
  83                 return SHAOptionsBase.SHA1_INTRINSICS_ARE_NOT_AVAILABLE;
  84             case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
  85                 return SHAOptionsBase.SHA256_INTRINSICS_ARE_NOT_AVAILABLE;
  86             case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
  87                 return SHAOptionsBase.SHA512_INTRINSICS_ARE_NOT_AVAILABLE;
  88             default:
  89                 throw new Error("Unexpected option " + optionName);
  90             }
  91         } else {
  92             throw new Error("Support for CPUs different fromn X86, SPARC, and AARCH64 "
  93                             + "is not implemented");
  94         }
  95     }
  96 
  97     /**
  98      * Returns the predicate indicating whether or not CPU instructions required
  99      * by the option with name {@code optionName} are available.
 100      *
 101      * @param optionName The name of the option for which a predicate should be
 102      *                   returned.
 103      * @return The predicate on availability of CPU instructions required by the
 104      *         option.
 105      */
 106     public static BooleanSupplier getPredicateForOption(String optionName) {
 107         switch (optionName) {
 108             case SHAOptionsBase.USE_SHA_OPTION:
 109                 return IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE;
 110             case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
 111                 return IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE;
 112             case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
 113                 return IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE;
 114             case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
 115                 return IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE;
 116             default:
 117                 throw new Error("Unexpected option " + optionName);
 118         }
 119     }
 120 
 121     public SHAOptionsBase(TestCase... testCases) {
 122         super(Boolean.TRUE::booleanValue);
 123         this.testCases = testCases;
 124     }
 125 
 126     @Override


< prev index next >