GenericTestCaseForUnsupportedSparcCPU.java revision 11707:ad7af1afda7a
1/*
2 * Copyright (c) 2014, 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
24package compiler.intrinsics.sha.cli.testcases;
25
26import compiler.intrinsics.sha.cli.SHAOptionsBase;
27import jdk.test.lib.ExitCode;
28import jdk.test.lib.Platform;
29import jdk.test.lib.cli.CommandLineOptionTest;
30import jdk.test.lib.cli.predicate.AndPredicate;
31import jdk.test.lib.cli.predicate.NotPredicate;
32
33/**
34 * Generic test case for SHA-related options targeted to SPARC CPUs which don't
35 * support instruction required by the tested option.
36 */
37public class GenericTestCaseForUnsupportedSparcCPU extends
38        SHAOptionsBase.TestCase {
39    public GenericTestCaseForUnsupportedSparcCPU(String optionName) {
40        super(optionName, new AndPredicate(Platform::isSparc,
41                new NotPredicate(SHAOptionsBase.getPredicateForOption(
42                        optionName))));
43    }
44
45    @Override
46    protected void verifyWarnings() throws Throwable {
47        String shouldPassMessage = String.format("JVM startup should pass with"
48                + "option '-XX:-%s' without any warnings", optionName);
49        //Verify that option could be disabled without any warnings.
50        CommandLineOptionTest.verifySameJVMStartup(null, new String[] {
51                        SHAOptionsBase.getWarningForUnsupportedCPU(optionName)
52                }, shouldPassMessage, shouldPassMessage, ExitCode.OK,
53                SHAOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
54                CommandLineOptionTest.prepareBooleanFlag(optionName, false));
55
56        // Verify that when the tested option is enabled, then
57        // a warning will occur in VM output if UseSHA is disabled.
58        if (!optionName.equals(SHAOptionsBase.USE_SHA_OPTION)) {
59            CommandLineOptionTest.verifySameJVMStartup(
60                    new String[] { SHAOptionsBase.getWarningForUnsupportedCPU(optionName) },
61                    null,
62                    shouldPassMessage,
63                    shouldPassMessage,
64                    ExitCode.OK,
65                    SHAOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
66                    CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false),
67                    CommandLineOptionTest.prepareBooleanFlag(optionName, true));
68        }
69    }
70
71    @Override
72    protected void verifyOptionValues() throws Throwable {
73        // Verify that option is disabled by default.
74        CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
75                String.format("Option '%s' should be disabled by default",
76                        optionName),
77                SHAOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS);
78
79        // Verify that option is disabled even if it was explicitly enabled
80        // using CLI options.
81        CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
82                String.format("Option '%s' should be off on unsupported "
83                        + "SparcCPU even if set to true directly", optionName),
84                SHAOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
85                CommandLineOptionTest.prepareBooleanFlag(optionName, true));
86
87        // Verify that option is disabled when +UseSHA was passed to JVM.
88        CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
89                String.format("Option '%s' should be off on unsupported "
90                        + "SparcCPU even if %s flag set to JVM",
91                        optionName, CommandLineOptionTest.prepareBooleanFlag(
92                            SHAOptionsBase.USE_SHA_OPTION, true)),
93                SHAOptionsBase.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
94                CommandLineOptionTest.prepareBooleanFlag(
95                        SHAOptionsBase.USE_SHA_OPTION, true));
96    }
97}
98