Path: blob/master/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/DoubleJVMOption.java
41161 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package optionsvalidation;2425import java.util.ArrayList;26import java.util.List;27import java.util.Locale;2829public class DoubleJVMOption extends JVMOption {3031/**32* Additional double values to test33*/34private static final double ADDITIONAL_TEST_DOUBLE_NEGATIVE = -1.5;35private static final double ADDITIONAL_TEST_DOUBLE_ZERO = 0.0;36private static final double ADDITIONAL_TEST_DOUBLE_POSITIVE = 1.75;3738/**39* Mininum option value40*/41private double min;42/**43* Maximum option value44*/45private double max;4647/**48* Initialize double option with passed name49*50* @param name name of the option51*/52DoubleJVMOption(String name) {53this.name = name;54min = Double.MIN_VALUE;55max = Double.MAX_VALUE;56}5758/**59* Initialize double option with passed name, min and max values60*61* @param name name of the option62* @param min minimum value of the option63* @param max maximum value of the option64*/65public DoubleJVMOption(String name, double min, double max) {66this(name);67this.min = min;68this.max = max;69}7071/**72* Set new minimum option value73*74* @param min new minimum value75*/76@Override77void setMin(String min) {78this.min = Double.valueOf(min);79}8081/**82* Get string with minimum value of the option83*84* @return string with minimum value of the option85*/86@Override87String getMin() {88return formatValue(min);89}9091/**92* Set new maximum option value93*94* @param max new maximum value95*/96@Override97void setMax(String max) {98this.max = Double.valueOf(max);99}100101/**102* Get string with maximum value of the option103*104* @return string with maximum value of the option105*/106@Override107String getMax() {108return formatValue(max);109}110111private String formatValue(double value) {112return String.format(Locale.US, "%f", value);113}114115/**116* Return list of strings with valid option values which used for testing117* using jcmd, attach and etc.118*119* @return list of strings which contain valid values for option120*/121@Override122protected List<String> getValidValues() {123List<String> validValues = new ArrayList<>();124125if (testMinRange) {126validValues.add(formatValue(min));127}128if (testMaxRange) {129validValues.add(formatValue(max));130}131132if (testMinRange) {133if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_NEGATIVE) < 0)134&& (Double.compare(max, ADDITIONAL_TEST_DOUBLE_NEGATIVE) > 0)) {135validValues.add(formatValue(ADDITIONAL_TEST_DOUBLE_NEGATIVE));136}137138if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_ZERO) < 0)139&& (Double.compare(max, ADDITIONAL_TEST_DOUBLE_ZERO) > 0)) {140validValues.add(formatValue(ADDITIONAL_TEST_DOUBLE_ZERO));141}142143if ((Double.compare(min, ADDITIONAL_TEST_DOUBLE_POSITIVE) < 0)144&& (Double.compare(max, ADDITIONAL_TEST_DOUBLE_POSITIVE) > 0)) {145validValues.add(formatValue(ADDITIONAL_TEST_DOUBLE_POSITIVE));146}147}148149return validValues;150}151152/**153* Return list of strings with invalid option values which used for testing154* using jcmd, attach and etc.155*156* @return list of strings which contain invalid values for option157*/158@Override159protected List<String> getInvalidValues() {160List<String> invalidValues = new ArrayList<>();161162if (withRange) {163/* Return invalid values only for options which have defined range in VM */164if (Double.compare(min, Double.MIN_VALUE) != 0) {165if ((Double.compare(min, 0.0) > 0)166&& (Double.isNaN(min * 0.999) == false)) {167invalidValues.add(formatValue(min * 0.999));168} else if ((Double.compare(min, 0.0) < 0)169&& (Double.isNaN(min * 1.001) == false)) {170invalidValues.add(formatValue(min * 1.001));171}172}173174if (Double.compare(max, Double.MAX_VALUE) != 0) {175if ((Double.compare(max, 0.0) > 0)176&& (Double.isNaN(max * 1.001) == false)) {177invalidValues.add(formatValue(max * 1.001));178} else if ((Double.compare(max, 0.0) < 0)179&& (Double.isNaN(max * 0.999) == false)) {180invalidValues.add(formatValue(max * 0.999));181}182}183}184185return invalidValues;186}187188/**189* Return expected error message for option with value "value" when it used190* on command line with passed value191*192* @param value option value193* @return expected error message194*/195@Override196protected String getErrorMessageCommandLine(String value) {197String errorMsg;198199if (withRange) {200/* Option have defined range in VM */201errorMsg = "is outside the allowed range";202} else {203errorMsg = "";204}205206return errorMsg;207}208}209210211