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 } | 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 greater than or equal to MinHeapFreeRatio"); 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 } |