Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/sha/cli/DigestOptionsBase.java
41155 views
/*1* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package compiler.intrinsics.sha.cli;2425import compiler.testlibrary.sha.predicate.IntrinsicPredicates;26import jdk.test.lib.Platform;27import jdk.test.lib.cli.CommandLineOptionTest;2829import java.util.function.BooleanSupplier;3031/**32* Base class for all CLI tests on SHA-related options.33*34* Instead of using huge complex tests for each option, each test is constructed35* from several test cases shared among different tests.36*/37public class DigestOptionsBase extends CommandLineOptionTest {38public static final String USE_MD5_INTRINSICS_OPTION39= "UseMD5Intrinsics";40public static final String USE_SHA_OPTION = "UseSHA";41public static final String USE_SHA1_INTRINSICS_OPTION42= "UseSHA1Intrinsics";43public static final String USE_SHA256_INTRINSICS_OPTION44= "UseSHA256Intrinsics";45public static final String USE_SHA512_INTRINSICS_OPTION46= "UseSHA512Intrinsics";47public static final String USE_SHA3_INTRINSICS_OPTION48= "UseSHA3Intrinsics";4950// Intrinsics flags are of diagnostic type51// and must be preceded by UnlockDiagnosticVMOptions.52public static final String UNLOCK_DIAGNOSTIC_VM_OPTIONS53= "-XX:+UnlockDiagnosticVMOptions";5455// Note that strings below will be passed to56// CommandLineOptionTest.verifySameJVMStartup and thus are regular57// expressions, not just a plain strings.58protected static final String MD5_INTRINSICS_ARE_NOT_AVAILABLE59= "Intrinsics for MD5 crypto hash functions not available on this CPU.";60protected static final String SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE61= "SHA instructions are not available on this CPU";62protected static final String SHA1_INTRINSICS_ARE_NOT_AVAILABLE63= "Intrinsics for SHA-1 crypto hash functions not available on this CPU.";64protected static final String SHA256_INTRINSICS_ARE_NOT_AVAILABLE65= "Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.";66protected static final String SHA512_INTRINSICS_ARE_NOT_AVAILABLE67= "Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.";68protected static final String SHA3_INTRINSICS_ARE_NOT_AVAILABLE69= "Intrinsics for SHA3-224, SHA3-256, SHA3-384 and SHA3-512 crypto hash functions not available on this CPU.";7071private final TestCase[] testCases;7273/**74* Returns warning message that should occur in VM output if an option with75* the name {@code optionName} was turned on and CPU does not support76* required instructions.77*78* @param optionName The name of the option for which warning message should79* be returned.80* @return A warning message that will be printed out to VM output if CPU81* instructions required by the option are not supported.82*/83public static String getWarningForUnsupportedCPU(String optionName) {84switch (optionName) {85case DigestOptionsBase.USE_MD5_INTRINSICS_OPTION:86return DigestOptionsBase.MD5_INTRINSICS_ARE_NOT_AVAILABLE;87case DigestOptionsBase.USE_SHA_OPTION:88return DigestOptionsBase.SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE;89case DigestOptionsBase.USE_SHA1_INTRINSICS_OPTION:90return DigestOptionsBase.SHA1_INTRINSICS_ARE_NOT_AVAILABLE;91case DigestOptionsBase.USE_SHA256_INTRINSICS_OPTION:92return DigestOptionsBase.SHA256_INTRINSICS_ARE_NOT_AVAILABLE;93case DigestOptionsBase.USE_SHA512_INTRINSICS_OPTION:94return DigestOptionsBase.SHA512_INTRINSICS_ARE_NOT_AVAILABLE;95case DigestOptionsBase.USE_SHA3_INTRINSICS_OPTION:96return DigestOptionsBase.SHA3_INTRINSICS_ARE_NOT_AVAILABLE;97default:98throw new Error("Unexpected option " + optionName);99}100}101102/**103* Returns the predicate indicating whether or not CPU instructions required104* by the option with name {@code optionName} are available.105*106* @param optionName The name of the option for which a predicate should be107* returned.108* @return The predicate on availability of CPU instructions required by the109* option.110*/111public static BooleanSupplier getPredicateForOption(String optionName) {112switch (optionName) {113case DigestOptionsBase.USE_MD5_INTRINSICS_OPTION:114return IntrinsicPredicates.MD5_INSTRUCTION_AVAILABLE;115case DigestOptionsBase.USE_SHA_OPTION:116return IntrinsicPredicates.ANY_SHA_INSTRUCTION_AVAILABLE;117case DigestOptionsBase.USE_SHA1_INTRINSICS_OPTION:118return IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE;119case DigestOptionsBase.USE_SHA256_INTRINSICS_OPTION:120return IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE;121case DigestOptionsBase.USE_SHA512_INTRINSICS_OPTION:122return IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE;123case DigestOptionsBase.USE_SHA3_INTRINSICS_OPTION:124return IntrinsicPredicates.SHA3_INSTRUCTION_AVAILABLE;125default:126throw new Error("Unexpected option " + optionName);127}128}129130public DigestOptionsBase(TestCase... testCases) {131super(Boolean.TRUE::booleanValue);132this.testCases = testCases;133}134135@Override136protected void runTestCases() throws Throwable {137for (TestCase testCase : testCases) {138testCase.test();139}140}141142public static abstract class TestCase {143protected final String optionName;144private final BooleanSupplier predicate;145146protected TestCase(String optionName, BooleanSupplier predicate) {147this.optionName = optionName;148this.predicate = predicate;149}150151protected final void test() throws Throwable {152String testCaseName = this.getClass().getName();153if (!predicate.getAsBoolean()) {154System.out.println("Skipping " + testCaseName155+ " due to predicate failure.");156return;157} else {158System.out.println("Running " + testCaseName);159}160161verifyWarnings();162verifyOptionValues();163}164165protected void verifyWarnings() throws Throwable {166}167168protected void verifyOptionValues() throws Throwable {169}170}171}172173174