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 COMBINATION_INVALID 44 } 45 46 private static void testMinMaxFreeRatio(String min, String max, Validation type) throws Exception { 47 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 48 "-Xminf" + min, 49 "-Xmaxf" + max, 50 "-version"); 51 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 52 53 switch (type) { 54 case VALID: 55 output.shouldNotContain("Error"); 56 output.shouldHaveExitValue(0); 57 break; 58 case MIN_INVALID: 59 output.shouldContain("Bad min heap free percentage size: -Xminf" + min); 60 output.shouldContain("Error"); 61 output.shouldHaveExitValue(1); 62 break; 63 case MAX_INVALID: 64 output.shouldContain("Bad max heap free percentage size: -Xmaxf" + max); 65 output.shouldContain("Error"); 66 output.shouldHaveExitValue(1); 67 break; 68 case COMBINATION_INVALID: 69 output.shouldContain("must be less than or equal to MaxHeapFreeRatio"); 70 output.shouldContain("Error"); 71 output.shouldHaveExitValue(1); 72 break; 73 default: 74 throw new IllegalStateException("Must specify expected validation type"); 75 } 76 77 System.out.println(output.getOutput()); 78 } 79 80 public static void main(String args[]) throws Exception { 81 testMinMaxFreeRatio( "0.1", "0.5", Validation.VALID); 82 testMinMaxFreeRatio( ".1", ".5", Validation.VALID); 83 testMinMaxFreeRatio( "0.5", "0.5", Validation.VALID); 84 85 testMinMaxFreeRatio("-0.1", "0.5", Validation.MIN_INVALID); 86 testMinMaxFreeRatio( "1.1", "0.5", Validation.MIN_INVALID); 87 testMinMaxFreeRatio("=0.1", "0.5", Validation.MIN_INVALID); 88 testMinMaxFreeRatio("0.1f", "0.5", Validation.MIN_INVALID); 89 testMinMaxFreeRatio( 90 "INVALID", "0.5", Validation.MIN_INVALID); 91 testMinMaxFreeRatio( 92 "2147483647", "0.5", Validation.MIN_INVALID); 93 94 testMinMaxFreeRatio( "0.1", "-0.5", Validation.MAX_INVALID); 95 testMinMaxFreeRatio( "0.1", "1.5", Validation.MAX_INVALID); 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 testMinMaxFreeRatio( 101 "0.1", "2147483647", Validation.MAX_INVALID); 102 103 testMinMaxFreeRatio( "0.5", "0.1", Validation.COMBINATION_INVALID); 104 testMinMaxFreeRatio( ".5", ".10", Validation.COMBINATION_INVALID); 105 testMinMaxFreeRatio("0.12","0.100", Validation.COMBINATION_INVALID); 106 } 107 }