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