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  * @test
  26  * @library /test/lib /
  27  * @modules java.base/jdk.internal.misc
  28  *          java.management
  29  *
  30  * @build sun.hotspot.WhiteBox
  31  * @requires !(vm.cpu.features ~= ".*aes.*")
  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 import static jdk.test.lib.cli.CommandLineOptionTest.*;
  45 
  46 public class TestAESIntrinsicsOnUnsupportedConfig extends AESIntrinsicsBase {
  47 
  48     private static final String INTRINSICS_NOT_AVAILABLE_MSG = "warning: AES "
  49             + "intrinsics are not available on this CPU";
  50     private static final String AES_NOT_AVAILABLE_MSG = "warning: AES "
  51             + "instructions are not available on this CPU";
  52 
  53     protected void runTestCases() throws Throwable {
  54         testUseAES();
  55         testUseAESIntrinsics();
  56     }
  57 
  58     /**
  59      * Test checks following situation: <br/>
  60      * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
  61      * Expected result: UseAESIntrinsics flag is set to false <br/>
  62      * UseAES flag is set to false <br/>
  63      * Output shouldn't contain intrinsics usage <br/>
  64      * Output should contain message about intrinsics unavailability
  65      * @throws Throwable
  66      */
  67     private void testUseAESIntrinsics() throws Throwable {
  68         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
  69                 AESIntrinsicsBase.prepareArguments(prepareBooleanFlag(
  70                         AESIntrinsicsBase.USE_AES_INTRINSICS, true)));
  71         final String errorMessage = "Case testUseAESIntrinsics failed";
  72         verifyOutput(new String[] {INTRINSICS_NOT_AVAILABLE_MSG},
  73                 new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
  74                         AESIntrinsicsBase.AES_INTRINSIC},
  75                 errorMessage, outputAnalyzer);
  76         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
  77                 errorMessage, outputAnalyzer);
  78         verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
  79                 outputAnalyzer);
  80     }
  81 
  82     /**
  83      * Test checks following situation: <br/>
  84      * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
  85      * Expected result: UseAES flag is set to false <br/>
  86      * UseAES flag is set to false <br/>
  87      * Output shouldn't contain intrinsics usage <br/>
  88      * Output should contain message about AES unavailability <br/>
  89      * @throws Throwable
  90      */
  91     private void testUseAES() throws Throwable {
  92         OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
  93                 AESIntrinsicsBase.prepareArguments(prepareBooleanFlag
  94                         (AESIntrinsicsBase.USE_AES, true)));
  95         final String errorMessage = "Case testUseAES failed";
  96         verifyOutput(new String[] {AES_NOT_AVAILABLE_MSG},
  97                 new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
  98                 AESIntrinsicsBase.AES_INTRINSIC}, errorMessage, outputAnalyzer);
  99         verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
 100                 errorMessage, outputAnalyzer);
 101         verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
 102                 outputAnalyzer);
 103     }
 104 
 105     public static void main(String args[]) throws Throwable {
 106         new TestAESIntrinsicsOnUnsupportedConfig().runTestCases();
 107     }
 108 }