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 * 31 * @build compiler.cpuflags.TestAESIntrinsicsOnUnsupportedConfig 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.TestAESIntrinsicsOnUnsupportedConfig 38 */ 39 40 package compiler.cpuflags; 41 42 import jdk.test.lib.OutputAnalyzer; 43 import jdk.test.lib.ProcessTools; 44 import jdk.test.lib.cli.predicate.NotPredicate; 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 /** 54 * Constructs new TestAESIntrinsicsOnUnsupportedConfig that will be 55 * executed only if AESSupportPredicate returns false 56 */ 57 private TestAESIntrinsicsOnUnsupportedConfig() { 58 super(new NotPredicate(AESIntrinsicsBase.AES_SUPPORTED_PREDICATE)); 59 } 60 61 @Override 62 protected void runTestCases() throws Throwable { 63 testUseAES(); 64 testUseAESIntrinsics(); 65 } 66 67 /** 68 * Test checks following situation: <br/> 69 * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/> 70 * Expected result: UseAESIntrinsics flag is set to false <br/> 71 * UseAES flag is set to false <br/> 72 * Output shouldn't contain intrinsics usage <br/> 73 * Output should contain message about intrinsics unavailability 74 * @throws Throwable 75 */ 76 private void testUseAESIntrinsics() throws Throwable { 77 OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm( 78 AESIntrinsicsBase.prepareArguments(prepareBooleanFlag( 79 AESIntrinsicsBase.USE_AES_INTRINSICS, true))); 80 final String errorMessage = "Case testUseAESIntrinsics failed"; 81 verifyOutput(new String[] {INTRINSICS_NOT_AVAILABLE_MSG}, 82 new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC, 83 AESIntrinsicsBase.AES_INTRINSIC}, 84 errorMessage, outputAnalyzer); 85 verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false", 86 errorMessage, outputAnalyzer); 87 verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage, 88 outputAnalyzer); 89 } 90 91 /** 92 * Test checks following situation: <br/> 93 * UseAESIntrinsics flag is set to true, TestAESMain is executed <br/> 94 * Expected result: UseAES flag is set to false <br/> 95 * UseAES flag is set to false <br/> 96 * Output shouldn't contain intrinsics usage <br/> 97 * Output should contain message about AES unavailability <br/> 98 * @throws Throwable 99 */ 100 private void testUseAES() throws Throwable { 101 OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm( 102 AESIntrinsicsBase.prepareArguments(prepareBooleanFlag 103 (AESIntrinsicsBase.USE_AES, true))); 104 final String errorMessage = "Case testUseAES failed"; 105 verifyOutput(new String[] {AES_NOT_AVAILABLE_MSG}, 106 new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC, 107 AESIntrinsicsBase.AES_INTRINSIC}, errorMessage, outputAnalyzer); 108 verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false", 109 errorMessage, outputAnalyzer); 110 verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage, 111 outputAnalyzer); 112 } 113 114 public static void main(String args[]) throws Throwable { 115 new TestAESIntrinsicsOnUnsupportedConfig().test(); 116 } 117 }