Path: blob/master/test/hotspot/jtreg/compiler/cpuflags/TestAESIntrinsicsOnSupportedConfig.java
41149 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @library /test/lib /26* @modules java.base/jdk.internal.misc27* java.management28* @requires vm.cpu.features ~= ".*aes.*" & !vm.graal.enabled29* @build sun.hotspot.WhiteBox30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm/timeout=600 -Xbootclasspath/a:.32* -XX:+UnlockDiagnosticVMOptions33* -XX:+WhiteBoxAPI -Xbatch34* compiler.cpuflags.TestAESIntrinsicsOnSupportedConfig35*/3637package compiler.cpuflags;3839import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.Platform;41import jdk.test.lib.process.ProcessTools;42import sun.hotspot.WhiteBox;43import static jdk.test.lib.cli.CommandLineOptionTest.*;4445public class TestAESIntrinsicsOnSupportedConfig extends AESIntrinsicsBase {4647protected void runTestCases() throws Throwable {48testUseAES();49testUseAESUseSSE2();50testNoUseAES();51testNoUseAESUseSSE2();52testNoUseAESIntrinsic();53}5455/**56* Check if value of TieredStopAtLevel flag is greater than specified level.57*58* @param level tiered compilation level to compare with59*/60private boolean isTieredLevelGreaterThan(int level) {61Long val = WhiteBox.getWhiteBox().getIntxVMFlag("TieredStopAtLevel");62return (val != null && val > level);63}6465/**66* Test checks following situation: <br/>67* UseAES flag is set to true, TestAESMain is executed <br/>68* Expected result: UseAESIntrinsics flag is set to true <br/>69* If vm type is server then output should contain intrinsics usage <br/>70*71* @throws Throwable72*/73private void testUseAES() throws Throwable {74OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(75prepareArguments(prepareBooleanFlag(AESIntrinsicsBase76.USE_AES, true)));77final String errorMessage = "Case testUseAES failed";78if (Platform.isServer() && !Platform.isEmulatedClient() && isTieredLevelGreaterThan(3)) {79verifyOutput(new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,80AESIntrinsicsBase.AES_INTRINSIC}, null, errorMessage,81outputAnalyzer);82} else {83verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,84AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,85outputAnalyzer);86}87verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,88outputAnalyzer);89verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "true",90errorMessage, outputAnalyzer);91}9293/**94* Test checks following situation: <br/>95* UseAES flag is set to true, UseSSE flag is set to 2,96* Platform should support UseSSE (x86 or x64) <br/>97* TestAESMain is executed <br/>98* Expected result: UseAESIntrinsics flag is set to false <br/>99* Output shouldn't contain intrinsics usage <br/>100*101* @throws Throwable102*/103private void testUseAESUseSSE2() throws Throwable {104if (Platform.isX86() || Platform.isX64()) {105OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(106prepareArguments(prepareBooleanFlag(AESIntrinsicsBase107.USE_AES_INTRINSICS, true),108prepareNumericFlag(AESIntrinsicsBase.USE_SSE, 2)));109final String errorMessage = "Case testUseAESUseSSE2 failed";110verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,111AESIntrinsicsBase.AES_INTRINSIC},112errorMessage, outputAnalyzer);113verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,114outputAnalyzer);115verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",116errorMessage, outputAnalyzer);117verifyOptionValue(AESIntrinsicsBase.USE_SSE, "2", errorMessage,118outputAnalyzer);119}120}121122/**123* Test checks following situation: <br/>124* UseAES flag is set to false, UseSSE flag is set to 2,125* Platform should support UseSSE (x86 or x64) <br/>126* TestAESMain is executed <br/>127* Expected result: UseAESIntrinsics flag is set to false <br/>128* Output shouldn't contain intrinsics usage <br/>129*130* @throws Throwable131*/132private void testNoUseAESUseSSE2() throws Throwable {133if (Platform.isX86() || Platform.isX64()) {134OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(135prepareArguments(prepareBooleanFlag(AESIntrinsicsBase136.USE_AES, false),137prepareNumericFlag(AESIntrinsicsBase.USE_SSE, 2)));138final String errorMessage = "Case testNoUseAESUseSSE2 failed";139verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,140AESIntrinsicsBase.AES_INTRINSIC},141errorMessage, outputAnalyzer);142verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,143outputAnalyzer);144verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",145errorMessage, outputAnalyzer);146verifyOptionValue(AESIntrinsicsBase.USE_SSE, "2", errorMessage,147outputAnalyzer);148}149}150151/**152* Test checks following situation: <br/>153* UseAES flag is set to false, TestAESMain is executed <br/>154* Expected result: UseAESIntrinsics flag is set to false <br/>155* Output shouldn't contain intrinsics usage <br/>156*157* @throws Throwable158*/159private void testNoUseAES() throws Throwable {160OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(161prepareArguments(prepareBooleanFlag(AESIntrinsicsBase162.USE_AES, false)));163final String errorMessage = "Case testNoUseAES failed";164verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,165AESIntrinsicsBase.AES_INTRINSIC},166errorMessage, outputAnalyzer);167verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,168outputAnalyzer);169verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",170errorMessage, outputAnalyzer);171}172173/**174* Test checks following situation: <br/>175* UseAESIntrinsics flag is set to false, TestAESMain is executed <br/>176* Expected result: UseAES flag is set to true <br/>177* Output shouldn't contain intrinsics usage <br/>178*179* @throws Throwable180*/181private void testNoUseAESIntrinsic() throws Throwable {182OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(183prepareArguments(prepareBooleanFlag(AESIntrinsicsBase184.USE_AES_INTRINSICS, false)));185final String errorMessage = "Case testNoUseAESIntrinsic failed";186verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,187AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,188outputAnalyzer);189verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,190outputAnalyzer);191verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",192errorMessage, outputAnalyzer);193}194195public static void main(String args[]) throws Throwable {196new TestAESIntrinsicsOnSupportedConfig().runTestCases();197}198}199200201