1 /* 2 * Copyright (c) 2013, 2015, 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 * @test TestHeapFreeRatio 26 * @key gc 27 * @bug 8025661 28 * @summary Test parsing of -Xminf and -Xmaxf 29 * @library /testlibrary 30 * @modules java.base/sun.misc 31 * java.management 32 * @run main/othervm TestHeapFreeRatio 33 */ 34 35 import jdk.test.lib.*; 36 37 public class TestHeapFreeRatio { 38 39 enum Validation { 40 VALID, 41 MIN_INVALID, 42 MAX_INVALID, 43 OUT_OF_RANGE, 44 COMBINATION_INVALID 45 } 46 47 private static void testMinMaxFreeRatio(String min, String max, Validation type) throws Exception { 48 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 49 "-Xminf" + min, 50 "-Xmaxf" + max, 51 "-version"); 52 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 53 54 switch (type) { 55 case VALID: 56 output.shouldNotContain("Error"); 57 output.shouldHaveExitValue(0); 58 break; 59 case MIN_INVALID: 60 output.shouldContain("Bad min heap free percentage size: -Xminf" + min); 61 output.shouldContain("Error"); 62 output.shouldHaveExitValue(1); 63 break; 64 case MAX_INVALID: 65 output.shouldContain("Bad max heap free percentage size: -Xmaxf" + max); 66 output.shouldContain("Error"); 67 output.shouldHaveExitValue(1); 68 break; 69 case OUT_OF_RANGE: 70 output.shouldContain("outside the allowed range"); 71 output.shouldContain("Error"); 72 output.shouldHaveExitValue(1); 73 break; 74 case COMBINATION_INVALID: 75 output.shouldContain("must be less than or equal to MaxHeapFreeRatio"); 76 output.shouldContain("Error"); 77 output.shouldHaveExitValue(1); 78 break; 79 default: 80 throw new IllegalStateException("Must specify expected validation type"); 81 } 82 83 System.out.println(output.getOutput()); 84 } 85 86 public static void main(String args[]) throws Exception { 87 testMinMaxFreeRatio( "0.1", "0.5", Validation.VALID); 88 testMinMaxFreeRatio( ".1", ".5", Validation.VALID); 89 testMinMaxFreeRatio( "0.5", "0.5", Validation.VALID); 90 91 testMinMaxFreeRatio("=0.1", "0.5", Validation.MIN_INVALID); 92 testMinMaxFreeRatio("0.1f", "0.5", Validation.MIN_INVALID); 93 testMinMaxFreeRatio( 94 "INVALID", "0.5", Validation.MIN_INVALID); 95 96 testMinMaxFreeRatio( "0.1", "0.5f", Validation.MAX_INVALID); 97 testMinMaxFreeRatio( "0.1", "=0.5", Validation.MAX_INVALID); 98 testMinMaxFreeRatio( 99 "0.1", "INVALID", Validation.MAX_INVALID); 100 101 testMinMaxFreeRatio("-0.1", "0.5", Validation.OUT_OF_RANGE); 102 testMinMaxFreeRatio( "1.1", "0.5", Validation.OUT_OF_RANGE); 103 testMinMaxFreeRatio( 104 "2147483647", "0.5", Validation.OUT_OF_RANGE); 105 testMinMaxFreeRatio( "0.1", "-0.5", Validation.OUT_OF_RANGE); 106 testMinMaxFreeRatio( "0.1", "1.5", Validation.OUT_OF_RANGE); 107 testMinMaxFreeRatio( 108 "0.1", "2147483647", Validation.OUT_OF_RANGE); 109 110 testMinMaxFreeRatio( "0.5", "0.1", Validation.COMBINATION_INVALID); 111 testMinMaxFreeRatio( ".5", ".10", Validation.COMBINATION_INVALID); 112 testMinMaxFreeRatio("0.12","0.100", Validation.COMBINATION_INVALID); 113 } 114 }