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 errorMessage = CommandLineOptionTest.
  51                         getDiagnosticOptionErrorMessage(optionName);
  52                 // verify that option is actually diagnostic
  53                 CommandLineOptionTest.verifySameJVMStartup(
  54                         new String[] { errorMessage }, null, ExitCode.FAIL,
  55                         prepareOptionValue("true"));
  56 
  57                 CommandLineOptionTest.verifySameJVMStartup(null,
  58                         new String[] { errorMessage }, ExitCode.OK,
  59                         CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
  60                         prepareOptionValue("true"));
  61             } else {
  62                 CommandLineOptionTest.verifySameJVMStartup(
  63                         null, null, ExitCode.OK, prepareOptionValue("true"));
  64             }
  65         } else {
  66             String errorMessage = CommandLineOptionTest.
  67                     getUnrecognizedOptionErrorMessage(optionName);
  68 
  69             CommandLineOptionTest.verifySameJVMStartup(
  70                     new String[]{errorMessage}, null, ExitCode.FAIL,
  71                     CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
  72                     prepareOptionValue("true"));
  73         }
  74     }
  75 
  76     @Override
  77     protected void verifyOptionValues() throws Throwable {
  78         if (Platform.isServer()) {
  79             // Verify default value
  80             CommandLineOptionTest.verifyOptionValueForSameVM(optionName,
  81                     TestPrintPreciseRTMLockingStatisticsBase.DEFAULT_VALUE,
  82                     CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS);
  83         }
  84     }
  85 }