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  * Note that this test intended to verify that VM could be launched with
  33  * specific options and that values of these options processed correctly.
  34  * In order to do that test launch a new VM with tested options, the same
  35  * flavor-specific flag as one that was used for parent VM (-client, -server,
  36  * -minimal, -graal) and '-version'.
  37  */
  38 public class BMIUnsupportedCPUTest extends BMICommandLineOptionTestBase {
  39 
  40     /**
  41      * Construct new test on {@code optionName} option.
  42      *
  43      * @param optionName Name of the option to be tested
  44      *                   without -XX:[+-] prefix.
  45      * @param warningMessage Message that can occur in VM output
  46      *                       if CPU on test box does not support
  47      *                       features required by the option.
  48      * @param cpuFeatures CPU features requires by the option.
  49      */
  50     public BMIUnsupportedCPUTest(String optionName,
  51                                  String warningMessage,
  52                                  String... cpuFeatures) {
  53         super(optionName, warningMessage, null, cpuFeatures);
  54     }
  55 
  56     @Override
  57     public void runTestCases() throws Throwable {
  58         if (Platform.isX86() || Platform.isX64()) {
  59             unsupportedX86CPUTestCases();
  60         } else {
  61             unsupportedNonX86CPUTestCases();
  62         }
  63     }
  64 
  65     /**
  66      * Run test cases common for all bit manipulation related VM options
  67      * targeted to X86 CPU that does not support required features.
  68      *
  69      * @throws Throwable if test failed.
  70      */
  71     public void unsupportedX86CPUTestCases() throws Throwable {
  72 
  73         /*
  74           Verify that VM will successfully start up, but output will contain a
  75           warning. VM will be launched with following options:
  76           -XX:+<tested option> -version
  77         */
  78         CommandLineOptionTest.verifySameJVMStartup(
  79                 new String[] { warningMessage }, new String[] { errorMessage },
  80                 ExitCode.OK, CommandLineOptionTest.prepareBooleanFlag(
  81                         optionName, true));
  82 
  83         /*
  84           Verify that VM will successfully startup without any warnings.
  85           VM will be launched with following options:
  86           -XX:-<tested option> -version
  87         */
  88         CommandLineOptionTest.verifySameJVMStartup(null,
  89                 new String[] { warningMessage, errorMessage }, ExitCode.OK,
  90                 CommandLineOptionTest.prepareBooleanFlag(optionName, false));
  91 
  92         /*
  93           Verify that on unsupported CPUs option is off by default.
  94           VM will be launched with following options: -version
  95         */
  96         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false");
  97 
  98         /*
  99           Verify that on unsupported CPUs option will be off even if
 100           it was explicitly turned on by user. VM will be launched with
 101           following options: -XX:+<tested option> -version
 102         */
 103         CommandLineOptionTest.verifyOptionValueForSameVM(optionName, "false",
 104                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
 105 
 106     }
 107 
 108     /**
 109      * Run test cases common for all bit manipulation related VM options
 110      * targeted to non-X86 CPU that does not support required features.
 111      *
 112      * @throws Throwable if test failed.
 113      */
 114     public void unsupportedNonX86CPUTestCases() throws Throwable {
 115 
 116         /*
 117           Verify that VM known nothing about tested option. VM will be launched
 118           with following options: -XX:[+-]<tested option> -version
 119         */
 120         CommandLineOptionTest.verifySameJVMStartup(
 121                 new String[] { errorMessage }, null, ExitCode.FAIL,
 122                 CommandLineOptionTest.prepareBooleanFlag(optionName, true));
 123 
 124         CommandLineOptionTest.verifySameJVMStartup(
 125                 new String[] { errorMessage }, null, ExitCode.FAIL,
 126                 CommandLineOptionTest.prepareBooleanFlag(optionName, false));
 127     }
 128 }
 129