8079667: port vm/compiler/AESIntrinsics/CheckIntrinsics into jtreg

Reviewed-by: kvn
This commit is contained in:
Alexander Vorobyev 2015-12-15 17:31:18 +03:00 committed by Igor Ignatyev
parent c095394bce
commit 1a135175c4
5 changed files with 511 additions and 5 deletions

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
import jdk.test.lib.cli.CommandLineOptionTest;
import predicate.AESSupportPredicate;
import java.util.Arrays;
import java.util.function.BooleanSupplier;
public abstract class AESIntrinsicsBase extends CommandLineOptionTest {
public static final BooleanSupplier AES_SUPPORTED_PREDICATE
= new AESSupportPredicate();
public static final String CIPHER_INTRINSIC = "com\\.sun\\.crypto\\"
+ ".provider\\.CipherBlockChaining::"
+ "(implEncrypt|implDecrypt) \\([0-9]+ bytes\\)\\s+\\(intrinsic[,\\)]";
public static final String AES_INTRINSIC = "com\\.sun\\.crypto\\"
+ ".provider\\.AESCrypt::(implEncryptBlock|implDecryptBlock) \\([0-9]+ "
+ "bytes\\)\\s+\\(intrinsic[,\\)]";
public static final String USE_AES = "UseAES";
public static final String USE_AES_INTRINSICS = "UseAESIntrinsics";
public static final String USE_SSE = "UseSSE";
public static final String USE_VIS = "UseVIS";
public static final String[] TEST_AES_CMD
= {"-XX:+IgnoreUnrecognizedVMOptions", "-XX:+PrintFlagsFinal",
"-Xbatch","-XX:+UnlockDiagnosticVMOptions",
"-XX:+PrintIntrinsics", "-DcheckOutput=true", "-Dmode=CBC",
"TestAESMain"};
protected AESIntrinsicsBase(BooleanSupplier predicate) {
super(predicate);
}
/**
* Prepares command for TestAESMain execution.
* @param args flags that must be added to command
* @return command for TestAESMain execution
*/
public static String[] prepareArguments(String... args) {
String[] command = Arrays.copyOf(args, TEST_AES_CMD.length
+ args.length);
System.arraycopy(TEST_AES_CMD, 0, command, args.length,
TEST_AES_CMD.length);
return command;
}
}

View File

@ -0,0 +1,254 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
import jdk.test.lib.OutputAnalyzer;
import jdk.test.lib.Platform;
import jdk.test.lib.ProcessTools;
/*
* @test
* @library /testlibrary /../../test/lib /compiler/whitebox
* /compiler/testlibrary /compiler/codegen/7184394
* @modules java.base/sun.misc
* java.management
* @build TestAESIntrinsicsOnSupportedConfig TestAESMain
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -Xbatch
* TestAESIntrinsicsOnSupportedConfig
*/
public class TestAESIntrinsicsOnSupportedConfig extends AESIntrinsicsBase {
/**
* Constructs new TestAESIntrinsicsOnSupportedConfig that will be executed
* only if AESSupportPredicate returns true
*/
private TestAESIntrinsicsOnSupportedConfig() {
super(AESIntrinsicsBase.AES_SUPPORTED_PREDICATE);
}
@Override
protected void runTestCases() throws Throwable {
testUseAES();
testUseAESUseSSE2();
testUseAESUseVIS2();
testNoUseAES();
testNoUseAESUseSSE2();
testNoUseAESUseVIS2();
testNoUseAESIntrinsic();
}
/**
* Test checks following situation: <br/>
* UseAES flag is set to true, TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to true <br/>
* If vm type is server then output should contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testUseAES() throws Throwable {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES, true)));
final String errorMessage = "Case testUseAES failed";
if (Platform.isServer()) {
verifyOutput(new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC}, null, errorMessage,
outputAnalyzer);
} else {
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,
outputAnalyzer);
}
verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "true",
errorMessage, outputAnalyzer);
}
/**
* Test checks following situation: <br/>
* UseAES flag is set to true, UseSSE flag is set to 2,
* Platform should support UseSSE (x86 or x64) <br/>
* TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testUseAESUseSSE2() throws Throwable {
if (Platform.isX86() || Platform.isX64()) {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES_INTRINSICS, true),
prepareNumericFlag(AESIntrinsicsBase.USE_SSE, 2)));
final String errorMessage = "Case testUseAESUseSSE2 failed";
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC},
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_SSE, "2", errorMessage,
outputAnalyzer);
}
}
/**
* Test checks following situation: <br/>
* UseAES flag is set to false, UseSSE flag is set to 2,
* Platform should support UseSSE (x86 or x64) <br/>
* TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testNoUseAESUseSSE2() throws Throwable {
if (Platform.isX86() || Platform.isX64()) {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES, false),
prepareNumericFlag(AESIntrinsicsBase.USE_SSE, 2)));
final String errorMessage = "Case testNoUseAESUseSSE2 failed";
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC},
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_SSE, "2", errorMessage,
outputAnalyzer);
}
}
/**
* Test checks following situation: <br/>
* UseAES flag is set to true, UseVIS flag is set to 2,
* Platform should support UseVIS (sparc) <br/>
* TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testUseAESUseVIS2() throws Throwable {
if (Platform.isSparc()) {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES_INTRINSICS, true),
prepareNumericFlag(AESIntrinsicsBase.USE_VIS, 2)));
final String errorMessage = "Case testUseAESUseVIS2 failed";
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC},
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_VIS, "2", errorMessage,
outputAnalyzer);
}
}
/**
* Test checks following situation: <br/>
* UseAES flag is set to false, UseVIS flag is set to 2,
* Platform should support UseVIS (sparc) <br/>
* TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testNoUseAESUseVIS2() throws Throwable {
if (Platform.isSparc()) {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES, false),
prepareNumericFlag(AESIntrinsicsBase.USE_VIS, 2)));
final String errorMessage = "Case testNoUseAESUseVIS2 failed";
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC},
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_VIS, "2", errorMessage,
outputAnalyzer);
}
}
/**
* Test checks following situation: <br/>
* UseAES flag is set to false, TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testNoUseAES() throws Throwable {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES, false)));
final String errorMessage = "Case testNoUseAES failed";
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC},
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
}
/**
* Test checks following situation: <br/>
* UseAESIntrinsics flag is set to false, TestAESMain is executed <br/>
* Expected result: UseAES flag is set to true <br/>
* Output shouldn't contain intrinsics usage <br/>
*
* @throws Throwable
*/
private void testNoUseAESIntrinsic() throws Throwable {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
prepareArguments(prepareBooleanFlag(AESIntrinsicsBase
.USE_AES_INTRINSICS, false)));
final String errorMessage = "Case testNoUseAESIntrinsic failed";
verifyOutput(null, new String[]{AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC}, errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "true", errorMessage,
outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
}
public static void main(String args[]) throws Throwable {
new TestAESIntrinsicsOnSupportedConfig().test();
}
}

View File

@ -0,0 +1,112 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
import jdk.test.lib.cli.predicate.NotPredicate;
import jdk.test.lib.OutputAnalyzer;
import jdk.test.lib.ProcessTools;
/*
* @test
* @library /testlibrary /../../test/lib /compiler/whitebox
* /compiler/testlibrary /compiler/codegen/7184394
* @modules java.base/sun.misc
* java.management
* @build TestAESIntrinsicsOnUnsupportedConfig TestAESMain
* @run main ClassFileInstaller
* sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -Xbatch TestAESIntrinsicsOnUnsupportedConfig
*/
public class TestAESIntrinsicsOnUnsupportedConfig extends AESIntrinsicsBase {
private static final String INTRINSICS_NOT_AVAILABLE_MSG = "warning: AES "
+ "intrinsics are not available on this CPU";
private static final String AES_NOT_AVAILABLE_MSG = "warning: AES "
+ "instructions are not available on this CPU";
/**
* Constructs new TestAESIntrinsicsOnUnsupportedConfig that will be
* executed only if AESSupportPredicate returns false
*/
private TestAESIntrinsicsOnUnsupportedConfig() {
super(new NotPredicate(AESIntrinsicsBase.AES_SUPPORTED_PREDICATE));
}
@Override
protected void runTestCases() throws Throwable {
testUseAES();
testUseAESIntrinsics();
}
/**
* Test checks following situation: <br/>
* UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
* Expected result: UseAESIntrinsics flag is set to false <br/>
* UseAES flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
* Output should contain message about intrinsics unavailability
* @throws Throwable
*/
private void testUseAESIntrinsics() throws Throwable {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
AESIntrinsicsBase.prepareArguments(prepareBooleanFlag(
AESIntrinsicsBase.USE_AES_INTRINSICS, true)));
final String errorMessage = "Case testUseAESIntrinsics failed";
verifyOutput(new String[] {INTRINSICS_NOT_AVAILABLE_MSG},
new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC},
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
outputAnalyzer);
}
/**
* Test checks following situation: <br/>
* UseAESIntrinsics flag is set to true, TestAESMain is executed <br/>
* Expected result: UseAES flag is set to false <br/>
* UseAES flag is set to false <br/>
* Output shouldn't contain intrinsics usage <br/>
* Output should contain message about AES unavailability <br/>
* @throws Throwable
*/
private void testUseAES() throws Throwable {
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(
AESIntrinsicsBase.prepareArguments(prepareBooleanFlag
(AESIntrinsicsBase.USE_AES, true)));
final String errorMessage = "Case testUseAES failed";
verifyOutput(new String[] {AES_NOT_AVAILABLE_MSG},
new String[] {AESIntrinsicsBase.CIPHER_INTRINSIC,
AESIntrinsicsBase.AES_INTRINSIC}, errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES_INTRINSICS, "false",
errorMessage, outputAnalyzer);
verifyOptionValue(AESIntrinsicsBase.USE_AES, "false", errorMessage,
outputAnalyzer);
}
public static void main(String args[]) throws Throwable {
new TestAESIntrinsicsOnUnsupportedConfig().test();
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
package predicate;
import sun.hotspot.cpuinfo.CPUInfo;
import java.util.function.BooleanSupplier;
public class AESSupportPredicate implements BooleanSupplier {
private static final String AES = "aes";
@Override
public boolean getAsBoolean() {
return CPUInfo.getFeatures().contains(AES);
}
}

View File

@ -121,7 +121,27 @@ public abstract class CommandLineOptionTest {
throw new AssertionError(errorMessage, e);
}
verifyOutput(expectedMessages, unexpectedMessages,
wrongWarningMessage, outputAnalyzer);
}
/**
* Verifies that JVM startup behavior matches our expectations.
*
* @param expectedMessages an array of patterns that should occur in JVM
* output. If {@code null} then
* JVM output could be empty.
* @param unexpectedMessages an array of patterns that should not occur
* in JVM output. If {@code null} then
* JVM output could be empty.
* @param wrongWarningMessage message that will be shown if messages are
* not as expected.
* @param outputAnalyzer OutputAnalyzer instance
* @throws AssertionError if verification fails.
*/
public static void verifyOutput(String[] expectedMessages,
String[] unexpectedMessages, String wrongWarningMessage,
OutputAnalyzer outputAnalyzer) {
if (expectedMessages != null) {
for (String expectedMessage : expectedMessages) {
try {
@ -199,7 +219,7 @@ public abstract class CommandLineOptionTest {
public static void verifyOptionValue(String optionName,
String expectedValue, String optionErrorString,
String... additionalVMOpts) throws Throwable {
verifyOptionValue(optionName, expectedValue, optionErrorString,
verifyOptionValue(optionName, expectedValue, optionErrorString,
true, additionalVMOpts);
}
@ -247,12 +267,30 @@ public abstract class CommandLineOptionTest {
optionName);
throw new AssertionError(errorMessage, e);
}
verifyOptionValue(optionName, expectedValue, optionErrorString,
outputAnalyzer);
}
/**
* Verifies that value of specified JVM option is the same as
* expected value.
*
* @param optionName a name of tested option.
* @param expectedValue expected value of tested option.
* @param optionErrorString message will be shown if option value is not
* as expected.
* @param outputAnalyzer OutputAnalyzer instance
* @throws AssertionError if verification fails
*/
public static void verifyOptionValue(String optionName,
String expectedValue, String optionErrorString,
OutputAnalyzer outputAnalyzer) {
try {
outputAnalyzer.shouldMatch(String.format(
CommandLineOptionTest.PRINT_FLAGS_FINAL_FORMAT,
optionName, expectedValue));
outputAnalyzer.shouldMatch(String.format(
CommandLineOptionTest.PRINT_FLAGS_FINAL_FORMAT,
optionName, expectedValue));
} catch (RuntimeException e) {
String errorMessage = String.format(
String errorMessage = String.format(
"Option '%s' is expected to have '%s' value%n%s",
optionName, expectedValue,
optionErrorString);