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 import com.oracle.java.testlibrary.*;
  25 import com.oracle.java.testlibrary.cli.*;
  26 
  27 /**
  28  * Test on bit manipulation related command line options,
  29  * that should be executed on CPU that does not support
  30  * required features.
  31  */
  32 public class BMIUnsupportedCPUTest extends BMICommandLineOptionTestBase {
  33 
  34     /**
  35      * Construct new test on {@code optionName} option.
  36      *
  37      * @param optionName Name of the option to be tested
  38      *                   without -XX:[+-] prefix.
  39      * @param warningMessage Message that can occur in VM output
  40      *                       if CPU on test box does not support
  41      *                       features required by the option.
  42      * @param cpuFeatures CPU features requires by the option.
  43      */
  44     public BMIUnsupportedCPUTest(String optionName,
  45                                  String warningMessage,
  46                                  String... cpuFeatures) {
  47         super(optionName, warningMessage, null, cpuFeatures);
  48     }
  49 
  50     @Override
  51     public void runTestCases() throws Throwable {
  52         if (Platform.isX86() || Platform.isX64()) {
  53             unsupportedX86CPUTestCases();
  54         } else {
  55             unsupportedNonX86CPUTestCases();
  56         }
  57     }
  58 
  59     /**
  60      * Run test cases common for all bit manipulation related VM options
  61      * targeted to X86 CPU that does not support required features.
  62      *
  63      * @throws Throwable if test failed.
  64      */
  65     public void unsupportedX86CPUTestCases() throws Throwable {
  66 
  67         // verify that VM will successfully start up, but output will
  68         // contain a warning
  69         CommandLineOptionTest.verifySameJVMStartup(
  70                 new String[] { warningMessage }, new String[] { errorMessage },
  71                 ExitCode.OK, CommandLineOptionTest.prepareBooleanFlag(
  72                         optionName, true));
  73 
  74         // verify that VM will successfully startup without any warnings
  75         CommandLineOptionTest.verifySameJVMStartup(null,
  76                 new String[] { warningMessage, errorMessage }, ExitCode.OK,
  77                 CommandLineOptionTest.prepareBooleanFlag(optionName, false));
  78 
  79         // verify that on unsupported CPUs option is off by default
  80         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false");
  81 
  82         // verify that on unsupported CPUs option will be off even if
  83         // it was explicitly turned on by user
  84         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
  85                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
  86 
  87     }
  88 
  89     /**
  90      * Run test cases common for all bit manipulation related VM options
  91      * targeted to non-X86 CPU that does not support required features.
  92      *
  93      * @throws Throwable if test failed.
  94      */
  95     public void unsupportedNonX86CPUTestCases() throws Throwable {
  96 
  97         // verify that VM known nothing about tested option
  98         CommandLineOptionTest.verifySameJVMStartup(
  99                 new String[] { errorMessage }, null, ExitCode.FAIL,
 100                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
 101 
 102         CommandLineOptionTest.verifySameJVMStartup(
 103                 new String[] { errorMessage }, null, ExitCode.FAIL,
 104                 CommandLineOptionTest.prepareBooleanFlag(optionName, false));
 105     }
 106 }
 107