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