Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/sha/sanity/DigestSanityTestBase.java
41161 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.sanity;2425import compiler.intrinsics.sha.TestDigest;26import compiler.testlibrary.intrinsics.Verifier;27import sun.hotspot.WhiteBox;2829import java.io.FileOutputStream;30import java.io.IOException;31import java.util.Objects;32import java.util.Properties;33import java.util.function.BooleanSupplier;3435/**36* Base class for sanity tests on SHA intrinsics support.37*/38public class DigestSanityTestBase {39protected static final String MD5_INTRINSIC_ID40= "_md5_implCompress";41protected static final String SHA1_INTRINSIC_ID42= "_sha_implCompress";43protected static final String SHA256_INTRINSIC_ID44= "_sha2_implCompress";45protected static final String SHA512_INTRINSIC_ID46= "_sha5_implCompress";47protected static final String SHA3_INTRINSIC_ID48= "_sha3_implCompress";49protected static final String MB_INTRINSIC_ID50= "_digestBase_implCompressMB";5152private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();53private static final int MSG_SIZE = 1024;54private static final int OFFSET = 0;55private static final int ITERATIONS = 10000;56private static final int WARMUP_ITERATIONS = 1;57private static final String PROVIDER = "SUN";5859private final BooleanSupplier predicate;60private final String intrinsicID;6162/**63* Construct the new test on intrinsic with ID {@code intrinsicID},64* which is expected to be emitted if {@code predicate} is evaluated to65* {@code true}.66*67* @param predicate The predicate indicating if the intrinsic is expected to68* be used.69* @param intrinsicID The ID of the intrinsic to be tested.70*/71protected DigestSanityTestBase(BooleanSupplier predicate, String intrinsicID) {72this.predicate = predicate;73this.intrinsicID = intrinsicID;74}7576/**77* Run the test and dump properties to file.78*79* @throws Exception when something went wrong.80*/81public final void test() throws Exception {82String algorithm = Objects.requireNonNull(83System.getProperty("algorithm"),84"Algorithm name should be specified.");8586dumpProperties();8788TestDigest.testDigest(DigestSanityTestBase.PROVIDER, algorithm,89DigestSanityTestBase.MSG_SIZE, DigestSanityTestBase.OFFSET,90DigestSanityTestBase.ITERATIONS,91DigestSanityTestBase.WARMUP_ITERATIONS);92}9394/**95* Dump properties containing information about the tested intrinsic name96* and whether or not is should be used to the file97* <LogFile value>.verify.properties.98*99* @throws IOException when something went wrong during dumping to file.100*/101private void dumpProperties() throws IOException {102Properties properties = new Properties();103properties.setProperty(Verifier.INTRINSIC_NAME_PROPERTY, intrinsicID);104properties.setProperty(Verifier.INTRINSIC_IS_EXPECTED_PROPERTY,105String.valueOf(predicate.getAsBoolean()));106107String logFileName108= DigestSanityTestBase.WHITE_BOX.getStringVMFlag("LogFile");109FileOutputStream fileOutputStream = new FileOutputStream(logFileName110+ Verifier.PROPERTY_FILE_SUFFIX);111112properties.store(fileOutputStream, null);113fileOutputStream.close();114}115}116117118