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 /test/lib /
  28  * @modules java.base/jdk.internal.misc
  29  *          java.management
  30  *
  31  * @build sun.hotspot.WhiteBox
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  33  *                                sun.hotspot.WhiteBox$WhiteBoxPermission
  34  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
  35  *       -XX:+WhiteBoxAPI -Xbatch
  36  *       compiler.cpuflags.TestAESIntrinsicsOnUnsupportedConfig
  37  */
  38 
  39 package compiler.cpuflags;
  40 
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 import jdk.test.lib.process.ProcessTools;
  43 import jdk.test.lib.cli.predicate.NotPredicate;
  44 
  45 public class TestAESIntrinsicsOnUnsupportedConfig extends AESIntrinsicsBase {
  46 
  47     private static final String INTRINSICS_NOT_AVAILABLE_MSG = "warning: AES "
  48             + "intrinsics are not available on this CPU";
  49     private static final String AES_NOT_AVAILABLE_MSG = "warning: AES "
  50             + "instructions are not available on this CPU";
  51 
  52     /**
  53      * Constructs new TestAESIntrinsicsOnUnsupportedConfig that will be
  54      * executed only if AESSupportPredicate returns false
  55      */
  56     private TestAESIntrinsicsOnUnsupportedConfig() {
  57         super(new NotPredicate(AESIntrinsicsBase.AES_SUPPORTED_PREDICATE));
  58     }
  59 
  60     @Override
  61     protected void runTestCases() throws Throwable {
  62         testUseAES();
  63         testUseAESIntrinsics();
  64     }
  65 
  66     /**
  67      * Test checks following situation: <br/>
  68      * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
  69      * Expected result: UseAESIntrinsics flag is set to false <br/>
  70      * UseAES flag is set to false <br/>
  71      * Output shouldn't contain intrinsics usage <br/>
  72      * Output should contain message about intrinsics unavailability
  73      * @throws Throwable
  74      */
  75     private void testUseAESIntrinsics() throws Throwable {
  76         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
  77                 AESIntrinsicsBase.prepareArguments(prepareBooleanFlag(
  78                         AESIntrinsicsBase.USE_AES_INTRINSICS, true)));
  79         final String errorMessage = "Case testUseAESIntrinsics failed";
  80         verifyOutput(new String[] {INTRINSICS_NOT_AVAILABLE_MSG},
  81                 new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
  82                         AESIntrinsicsBase.AES_INTRINSIC},
  83                 errorMessage, outputAnalyzer);
  84         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
  85                 errorMessage, outputAnalyzer);
  86         verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
  87                 outputAnalyzer);
  88     }
  89 
  90     /**
  91      * Test checks following situation: <br/>
  92      * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
  93      * Expected result: UseAES flag is set to false <br/>
  94      * UseAES flag is set to false <br/>
  95      * Output shouldn't contain intrinsics usage <br/>
  96      * Output should contain message about AES unavailability <br/>
  97      * @throws Throwable
  98      */
  99     private void testUseAES() throws Throwable {
 100         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
 101                 AESIntrinsicsBase.prepareArguments(prepareBooleanFlag
 102                         (AESIntrinsicsBase.USE_AES, true)));
 103         final String errorMessage = "Case testUseAES failed";
 104         verifyOutput(new String[] {AES_NOT_AVAILABLE_MSG},
 105                 new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
 106                 AESIntrinsicsBase.AES_INTRINSIC}, errorMessage, outputAnalyzer);
 107         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 108                 errorMessage, outputAnalyzer);
 109         verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
 110                 outputAnalyzer);
 111     }
 112 
 113     public static void main(String args[]) throws Throwable {
 114         new TestAESIntrinsicsOnUnsupportedConfig().test();
 115     }
 116 }