test/hotspot/jtreg/gc/arguments/TestHeapFreeRatio.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40631 hotspot/test/gc/arguments/TestHeapFreeRatio.java@ed82623d7831
child 53523 4c5184c56dc2
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     4
 *
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     7
 * published by the Free Software Foundation.
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     8
 *
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    13
 * accompanied this code).
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    14
 *
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    18
 *
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    21
 * questions.
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    22
 */
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    23
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    24
/*
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    25
 * @test TestHeapFreeRatio
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    26
 * @key gc
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    27
 * @bug 8025661
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    28
 * @summary Test parsing of -Xminf and -Xmaxf
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    29
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 33144
diff changeset
    30
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 20723
diff changeset
    31
 *          java.management
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    32
 * @run main/othervm TestHeapFreeRatio
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    33
 */
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    34
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    35
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    36
import jdk.test.lib.process.ProcessTools;
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    37
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    38
public class TestHeapFreeRatio {
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    39
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    40
  enum Validation {
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    41
    VALID,
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    42
    MIN_INVALID,
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    43
    MAX_INVALID,
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    44
    OUT_OF_RANGE,
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    45
    COMBINATION_INVALID
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    46
  }
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    47
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    48
  private static void testMinMaxFreeRatio(String min, String max, Validation type) throws Exception {
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    49
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    50
        "-Xminf" + min,
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    51
        "-Xmaxf" + max,
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    52
        "-version");
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    53
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    54
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    55
    switch (type) {
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    56
    case VALID:
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    57
      output.shouldNotContain("Error");
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    58
      output.shouldHaveExitValue(0);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    59
      break;
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    60
    case MIN_INVALID:
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    61
      output.shouldContain("Bad min heap free percentage size: -Xminf" + min);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    62
      output.shouldContain("Error");
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    63
      output.shouldHaveExitValue(1);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    64
      break;
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    65
    case MAX_INVALID:
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    66
      output.shouldContain("Bad max heap free percentage size: -Xmaxf" + max);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    67
      output.shouldContain("Error");
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    68
      output.shouldHaveExitValue(1);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    69
      break;
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    70
    case OUT_OF_RANGE:
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    71
      output.shouldContain("outside the allowed range");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    72
      output.shouldContain("Error");
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    73
      output.shouldHaveExitValue(1);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
    74
      break;
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    75
    case COMBINATION_INVALID:
33144
c56850e328fc 8134995: [REDO] GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents: 32613
diff changeset
    76
      output.shouldContain("must be less than or equal to MaxHeapFreeRatio");
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    77
      output.shouldContain("Error");
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    78
      output.shouldHaveExitValue(1);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    79
      break;
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    80
    default:
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    81
      throw new IllegalStateException("Must specify expected validation type");
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    82
    }
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    83
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    84
    System.out.println(output.getOutput());
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    85
  }
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    86
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    87
  public static void main(String args[]) throws Exception {
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    88
    testMinMaxFreeRatio( "0.1", "0.5", Validation.VALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    89
    testMinMaxFreeRatio(  ".1",  ".5", Validation.VALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    90
    testMinMaxFreeRatio( "0.5", "0.5", Validation.VALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    91
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    92
    testMinMaxFreeRatio("=0.1", "0.5", Validation.MIN_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    93
    testMinMaxFreeRatio("0.1f", "0.5", Validation.MIN_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    94
    testMinMaxFreeRatio(
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    95
                     "INVALID", "0.5", Validation.MIN_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    96
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    97
    testMinMaxFreeRatio( "0.1", "0.5f", Validation.MAX_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    98
    testMinMaxFreeRatio( "0.1", "=0.5", Validation.MAX_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
    99
    testMinMaxFreeRatio(
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   100
                     "0.1",  "INVALID", Validation.MAX_INVALID);
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   101
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   102
    testMinMaxFreeRatio("-0.1", "0.5", Validation.OUT_OF_RANGE);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   103
    testMinMaxFreeRatio( "1.1", "0.5", Validation.OUT_OF_RANGE);
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   104
    testMinMaxFreeRatio(
31371
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   105
                  "2147483647", "0.5", Validation.OUT_OF_RANGE);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   106
    testMinMaxFreeRatio( "0.1", "-0.5", Validation.OUT_OF_RANGE);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   107
    testMinMaxFreeRatio( "0.1",  "1.5", Validation.OUT_OF_RANGE);
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   108
    testMinMaxFreeRatio(
311143309e73 8122937: [JEP 245] Validate JVM Command-Line Flag Arguments.
gziemski
parents: 30604
diff changeset
   109
                   "0.1", "2147483647", Validation.OUT_OF_RANGE);
20723
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   110
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   111
    testMinMaxFreeRatio( "0.5",  "0.1", Validation.COMBINATION_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   112
    testMinMaxFreeRatio(  ".5",  ".10", Validation.COMBINATION_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   113
    testMinMaxFreeRatio("0.12","0.100", Validation.COMBINATION_INVALID);
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   114
  }
929cc8568f8e 8025661: Ill-formed -Xminf and -Xmaxf options values interpreted as 0
sjohanss
parents:
diff changeset
   115
}