1 /* 2 * Copyright (c) 2014, 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 import com.oracle.java.testlibrary.*; 26 import com.oracle.java.testlibrary.cli.*; 27 28 import java.util.function.BooleanSupplier; 29 30 public abstract class TestPrintPreciseRTMLockingStatisticsBase 31 extends RTMGenericCommandLineOptionTest { 32 protected static final String DEFAULT_VALUE = "false"; 33 34 protected TestPrintPreciseRTMLockingStatisticsBase( 35 BooleanSupplier predicate) { 36 super(predicate, "PrintPreciseRTMLockingStatistics", true, false, 37 TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE); 38 } 39 40 @Override 41 protected void runNonX86TestCases() throws Throwable { 42 verifyJVMStartup(); 43 verifyOptionValues(); 44 } 45 46 @Override 47 protected void verifyJVMStartup() throws Throwable { 48 if (Platform.isServer()) { 49 if (!Platform.isDebugBuild()) { 50 String shouldFailMessage = String.format("VM option '%s' is " 51 + "diagnostic%nJVM startup should fail without " 52 + "-XX:\\+UnlockDiagnosticVMOptions flag", optionName); 53 String shouldPassMessage = String.format("VM option '%s' is " 54 + "diagnostic%nJVM startup should pass with " 55 + "-XX:\\+UnlockDiagnosticVMOptions in debug build", 56 optionName); 57 String errorMessage = CommandLineOptionTest. 58 getDiagnosticOptionErrorMessage(optionName); 59 // verify that option is actually diagnostic 60 CommandLineOptionTest.verifySameJVMStartup( 61 new String[] { errorMessage }, null, shouldFailMessage, 62 shouldFailMessage, ExitCode.FAIL, 63 prepareOptionValue("true")); 64 65 CommandLineOptionTest.verifySameJVMStartup(null, 66 new String[] { errorMessage }, shouldPassMessage, 67 shouldPassMessage + "without any warnings", ExitCode.OK, 68 CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS, 69 prepareOptionValue("true")); 70 } else { 71 String shouldPassMessage = String.format("JVM startup should " 72 + "pass with '%s' option in debug build", 73 optionName); 74 CommandLineOptionTest.verifySameJVMStartup(null, null, 75 shouldPassMessage, shouldPassMessage, 76 ExitCode.OK, prepareOptionValue("true")); 77 } 78 } else { 79 String errorMessage = CommandLineOptionTest. 80 getUnrecognizedOptionErrorMessage(optionName); 81 String shouldFailMessage = String.format("JVM startup should fail" 82 + " with '%s' option in not debug build", optionName); 83 CommandLineOptionTest.verifySameJVMStartup( 84 new String[]{errorMessage}, null, shouldFailMessage, 85 shouldFailMessage, ExitCode.FAIL, 86 CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS, 87 prepareOptionValue("true")); 88 } 89 } 90 91 @Override 92 protected void verifyOptionValues() throws Throwable { 93 if (Platform.isServer()) { 94 // Verify default value 95 CommandLineOptionTest.verifyOptionValueForSameVM(optionName, 96 TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE, 97 String.format("Option '%s' should have '%s' default value", 98 optionName, 99 TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE), 100 CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS); 101 } 102 } 103 }