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