1 /*
   2  * Copyright (c) 2015, 2016, 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 
  25 /*
  26  * @test
  27  * @library /test/lib /
  28  * @modules java.base/jdk.internal.misc
  29  *          java.management
  30  * @build sun.hotspot.WhiteBox
  31  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  32  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  33  * @run main/othervm/timeout=600 -Xbootclasspath/a:.
  34  *                   -XX:+UnlockDiagnosticVMOptions
  35  *                   -XX:+WhiteBoxAPI -Xbatch
  36  *                   compiler.cpuflags.TestAESIntrinsicsOnSupportedConfig
  37  */
  38 
  39 package compiler.cpuflags;
  40 
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 import jdk.test.lib.Platform;
  43 import jdk.test.lib.process.ProcessTools;
  44 
  45 public class TestAESIntrinsicsOnSupportedConfig extends AESIntrinsicsBase {
  46 
  47     /**
  48      * Constructs new TestAESIntrinsicsOnSupportedConfig that will be executed
  49      * only if AESSupportPredicate returns true
  50      */
  51     private TestAESIntrinsicsOnSupportedConfig() {
  52         super(AESIntrinsicsBase.AES_SUPPORTED_PREDICATE);
  53     }
  54 
  55     @Override
  56     protected void runTestCases() throws Throwable {
  57         testUseAES();
  58         testUseAESUseSSE2();
  59         testUseAESUseVIS2();
  60         testNoUseAES();
  61         testNoUseAESUseSSE2();
  62         testNoUseAESUseVIS2();
  63         testNoUseAESIntrinsic();
  64     }
  65 
  66     /**
  67      * Test checks following situation: <br/>
  68      * UseAES flag is set to true, TestAESMain is executed <br/>
  69      * Expected result: UseAESIntrinsics flag is set to true <br/>
  70      * If vm type is server then output should contain intrinsics usage <br/>
  71      *
  72      * @throws Throwable
  73      */
  74     private void testUseAES() throws Throwable {
  75         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
  76                 prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
  77                         .USE_AES, true)));
  78         final String errorMessage = "Case testUseAES failed";
  79         if (Platform.isServer()) {
  80             verifyOutput(new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
  81                     AESIntrinsicsBase.AES_INTRINSIC}, null, errorMessage,
  82                     outputAnalyzer);
  83         } else {
  84             verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
  85                     AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,
  86                     outputAnalyzer);
  87         }
  88         verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
  89                 outputAnalyzer);
  90         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "true",
  91                 errorMessage, outputAnalyzer);
  92     }
  93 
  94     /**
  95      * Test checks following situation: <br/>
  96      * UseAES flag is set to true, UseSSE flag is set to 2,
  97      * Platform should support UseSSE (x86 or x64) <br/>
  98      * TestAESMain is executed <br/>
  99      * Expected result: UseAESIntrinsics flag is set to false <br/>
 100      * Output shouldn't contain intrinsics usage <br/>
 101      *
 102      * @throws Throwable
 103      */
 104     private void testUseAESUseSSE2() throws Throwable {
 105         if (Platform.isX86() || Platform.isX64()) {
 106             OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 107                     prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
 108                                     .USE_AES_INTRINSICS, true),
 109                             prepareNumericFlag(AESIntrinsicsBase.USE_SSE, 2)));
 110             final String errorMessage = "Case testUseAESUseSSE2 failed";
 111             verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
 112                             AESIntrinsicsBase.AES_INTRINSIC},
 113                     errorMessage, outputAnalyzer);
 114             verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
 115                     outputAnalyzer);
 116             verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 117                     errorMessage, outputAnalyzer);
 118             verifyOptionValue(AESIntrinsicsBase.USE_SSE, "2", errorMessage,
 119                     outputAnalyzer);
 120         }
 121     }
 122 
 123     /**
 124      * Test checks following situation: <br/>
 125      * UseAES flag is set to false, UseSSE flag is set to 2,
 126      * Platform should support UseSSE (x86 or x64) <br/>
 127      * TestAESMain is executed <br/>
 128      * Expected result: UseAESIntrinsics flag is set to false <br/>
 129      * Output shouldn't contain intrinsics usage <br/>
 130      *
 131      * @throws Throwable
 132      */
 133     private void testNoUseAESUseSSE2() throws Throwable {
 134         if (Platform.isX86() || Platform.isX64()) {
 135             OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 136                     prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
 137                                     .USE_AES, false),
 138                             prepareNumericFlag(AESIntrinsicsBase.USE_SSE, 2)));
 139             final String errorMessage = "Case testNoUseAESUseSSE2 failed";
 140             verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
 141                             AESIntrinsicsBase.AES_INTRINSIC},
 142                     errorMessage, outputAnalyzer);
 143             verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
 144                     outputAnalyzer);
 145             verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 146                     errorMessage, outputAnalyzer);
 147             verifyOptionValue(AESIntrinsicsBase.USE_SSE, "2", errorMessage,
 148                     outputAnalyzer);
 149         }
 150     }
 151 
 152     /**
 153      * Test checks following situation: <br/>
 154      * UseAES flag is set to true, UseVIS flag is set to 2,
 155      * Platform should support UseVIS (sparc) <br/>
 156      * TestAESMain is executed <br/>
 157      * Expected result: UseAESIntrinsics flag is set to false <br/>
 158      * Output shouldn't contain intrinsics usage <br/>
 159      *
 160      * @throws Throwable
 161      */
 162     private void testUseAESUseVIS2() throws Throwable {
 163         if (Platform.isSparc()) {
 164             OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 165                     prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
 166                                     .USE_AES_INTRINSICS, true),
 167                             prepareNumericFlag(AESIntrinsicsBase.USE_VIS, 2)));
 168             final String errorMessage = "Case testUseAESUseVIS2 failed";
 169             verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
 170                             AESIntrinsicsBase.AES_INTRINSIC},
 171                     errorMessage, outputAnalyzer);
 172             verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
 173                     outputAnalyzer);
 174             verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 175                     errorMessage, outputAnalyzer);
 176             verifyOptionValue(AESIntrinsicsBase.USE_VIS, "2", errorMessage,
 177                     outputAnalyzer);
 178         }
 179     }
 180 
 181 
 182     /**
 183      * Test checks following situation: <br/>
 184      * UseAES flag is set to false, UseVIS flag is set to 2,
 185      * Platform should support UseVIS (sparc) <br/>
 186      * TestAESMain is executed <br/>
 187      * Expected result: UseAESIntrinsics flag is set to false <br/>
 188      * Output shouldn't contain intrinsics usage <br/>
 189      *
 190      * @throws Throwable
 191      */
 192     private void testNoUseAESUseVIS2() throws Throwable {
 193         if (Platform.isSparc()) {
 194             OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 195                     prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
 196                                     .USE_AES, false),
 197                             prepareNumericFlag(AESIntrinsicsBase.USE_VIS, 2)));
 198             final String errorMessage = "Case testNoUseAESUseVIS2 failed";
 199             verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
 200                             AESIntrinsicsBase.AES_INTRINSIC},
 201                     errorMessage, outputAnalyzer);
 202             verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
 203                     outputAnalyzer);
 204             verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 205                     errorMessage, outputAnalyzer);
 206             verifyOptionValue(AESIntrinsicsBase.USE_VIS, "2", errorMessage,
 207                     outputAnalyzer);
 208         }
 209     }
 210 
 211     /**
 212      * Test checks following situation: <br/>
 213      * UseAES flag is set to false, TestAESMain is executed <br/>
 214      * Expected result: UseAESIntrinsics flag is set to false <br/>
 215      * Output shouldn't contain intrinsics usage <br/>
 216      *
 217      * @throws Throwable
 218      */
 219     private void testNoUseAES() throws Throwable {
 220         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 221                 prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
 222                         .USE_AES, false)));
 223         final String errorMessage = "Case testNoUseAES failed";
 224         verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
 225                         AESIntrinsicsBase.AES_INTRINSIC},
 226                 errorMessage, outputAnalyzer);
 227         verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
 228                 outputAnalyzer);
 229         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 230                 errorMessage, outputAnalyzer);
 231     }
 232 
 233     /**
 234      * Test checks following situation: <br/>
 235      * UseAESIntrinsics flag is set to false, TestAESMain is executed <br/>
 236      * Expected result: UseAES flag is set to true <br/>
 237      * Output shouldn't contain intrinsics usage <br/>
 238      *
 239      * @throws Throwable
 240      */
 241     private void testNoUseAESIntrinsic() throws Throwable {
 242         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 243                 prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
 244                         .USE_AES_INTRINSICS, false)));
 245         final String errorMessage = "Case testNoUseAESIntrinsic failed";
 246         verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
 247                         AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,
 248                 outputAnalyzer);
 249         verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
 250                 outputAnalyzer);
 251         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 252                 errorMessage, outputAnalyzer);
 253     }
 254 
 255     public static void main(String args[]) throws Throwable {
 256         new TestAESIntrinsicsOnSupportedConfig().test();
 257     }
 258 }