1 /*
   2  * Copyright (c) 2015, 2020, 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 // --- start auto-generated
  25 // the following portion is auto-generated by TestOptionsWithRanges_generate.sh. Do not edit manually.
  26 /*
  27  * @test
  28  * @bug 8205633
  29  * @summary Test VM Options with ranges (1 of 10)
  30  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  *          jdk.attach/sun.tools.attach
  34  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  35  * @run driver/timeout=1800 TestOptionsWithRanges 1 of 10
  36  */
  37 /*
  38  * @test
  39  * @bug 8205633
  40  * @summary Test VM Options with ranges (2 of 10)
  41  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  42  * @modules java.base/jdk.internal.misc
  43  *          java.management
  44  *          jdk.attach/sun.tools.attach
  45  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  46  * @run driver/timeout=1800 TestOptionsWithRanges 2 of 10
  47  */
  48 /*
  49  * @test
  50  * @bug 8205633
  51  * @summary Test VM Options with ranges (3 of 10)
  52  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  53  * @modules java.base/jdk.internal.misc
  54  *          java.management
  55  *          jdk.attach/sun.tools.attach
  56  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  57  * @run driver/timeout=1800 TestOptionsWithRanges 3 of 10
  58  */
  59 /*
  60  * @test
  61  * @bug 8205633
  62  * @summary Test VM Options with ranges (4 of 10)
  63  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  64  * @modules java.base/jdk.internal.misc
  65  *          java.management
  66  *          jdk.attach/sun.tools.attach
  67  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  68  * @run driver/timeout=1800 TestOptionsWithRanges 4 of 10
  69  */
  70 /*
  71  * @test
  72  * @bug 8205633
  73  * @summary Test VM Options with ranges (5 of 10)
  74  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  75  * @modules java.base/jdk.internal.misc
  76  *          java.management
  77  *          jdk.attach/sun.tools.attach
  78  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  79  * @run driver/timeout=1800 TestOptionsWithRanges 5 of 10
  80  */
  81 /*
  82  * @test
  83  * @bug 8205633
  84  * @summary Test VM Options with ranges (6 of 10)
  85  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  86  * @modules java.base/jdk.internal.misc
  87  *          java.management
  88  *          jdk.attach/sun.tools.attach
  89  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  90  * @run driver/timeout=1800 TestOptionsWithRanges 6 of 10
  91  */
  92 /*
  93  * @test
  94  * @bug 8205633
  95  * @summary Test VM Options with ranges (7 of 10)
  96  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
  97  * @modules java.base/jdk.internal.misc
  98  *          java.management
  99  *          jdk.attach/sun.tools.attach
 100  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 101  * @run driver/timeout=1800 TestOptionsWithRanges 7 of 10
 102  */
 103 /*
 104  * @test
 105  * @bug 8205633
 106  * @summary Test VM Options with ranges (8 of 10)
 107  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
 108  * @modules java.base/jdk.internal.misc
 109  *          java.management
 110  *          jdk.attach/sun.tools.attach
 111  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 112  * @run driver/timeout=1800 TestOptionsWithRanges 8 of 10
 113  */
 114 /*
 115  * @test
 116  * @bug 8205633
 117  * @summary Test VM Options with ranges (9 of 10)
 118  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
 119  * @modules java.base/jdk.internal.misc
 120  *          java.management
 121  *          jdk.attach/sun.tools.attach
 122  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 123  * @run driver/timeout=1800 TestOptionsWithRanges 9 of 10
 124  */
 125 /*
 126  * @test
 127  * @bug 8205633
 128  * @summary Test VM Options with ranges (10 of 10)
 129  * @library /test/lib /runtime/CommandLine/OptionsValidation/common
 130  * @modules java.base/jdk.internal.misc
 131  *          java.management
 132  *          jdk.attach/sun.tools.attach
 133  *          jdk.internal.jvmstat/sun.jvmstat.monitor
 134  * @run driver/timeout=1800 TestOptionsWithRanges 10 of 10
 135  */
 136 // --- end auto-generated
 137 
 138 import java.util.ArrayList;
 139 import java.util.Collections;
 140 import java.util.List;
 141 import java.util.Map;
 142 import jdk.test.lib.Asserts;
 143 import optionsvalidation.JVMOption;
 144 import optionsvalidation.JVMOptionsUtils;
 145 
 146 public class TestOptionsWithRanges {
 147 
 148     private static Map<String, JVMOption> allOptionsAsMap;
 149 
 150     private static void excludeTestMaxRange(String optionName) {
 151         JVMOption option = allOptionsAsMap.get(optionName);
 152 
 153         if (option != null) {
 154             option.excludeTestMaxRange();
 155         }
 156     }
 157 
 158     private static void excludeTestMinRange(String optionName) {
 159         JVMOption option = allOptionsAsMap.get(optionName);
 160 
 161         if (option != null) {
 162             option.excludeTestMinRange();
 163         }
 164     }
 165 
 166     private static void excludeTestRange(String optionName) {
 167         allOptionsAsMap.remove(optionName);
 168     }
 169 
 170     private static void setAllowedExitCodes(String optionName, Integer... allowedExitCodes) {
 171         JVMOption option = allOptionsAsMap.get(optionName);
 172 
 173         if (option != null) {
 174             option.setAllowedExitCodes(allowedExitCodes);
 175         }
 176     }
 177 
 178     // Return a subset of the test cases, so we can break up allOptionsAsMap into small parts
 179     // and use them in separate JTREG @test blocks (for parallel execution).
 180     //
 181     // args[] must be {part, "of", numParts}. The first part should be "1".
 182     private static List<JVMOption> getTestSubset(String[] args) throws Exception {
 183         int part = Integer.parseInt(args[0]) - 1;
 184         int numParts = Integer.parseInt(args[2]);
 185         List<String> keys = new ArrayList<>(allOptionsAsMap.keySet());
 186         Collections.sort(keys);
 187         int numTests = keys.size();
 188         int start = numTests * (part    ) / numParts;
 189         int end   = numTests * (part + 1) / numParts;
 190 
 191         List<JVMOption> subset = new ArrayList<>();
 192         for (int i=start; i < end; i++) {
 193             subset.add(allOptionsAsMap.get(keys.get(i)));
 194         }
 195         System.out.println("Generating subset [" + start + " ... " + end + ") of " +
 196                            subset.size() + " tests out of " + keys.size() + " total tests");
 197         return subset;
 198     }
 199 
 200     public static void main(String[] args) throws Exception {
 201         int failedTests;
 202 
 203         allOptionsAsMap = JVMOptionsUtils.getOptionsWithRangeAsMap(origin -> (!(origin.contains("develop") || origin.contains("notproduct"))));
 204 
 205         /*
 206          * Exclude VMThreadStackSize from max range testing, because it will always exit with code 1,
 207          * which technically passes, but really it fails, and worse yet, it produces hs_err_pid file.
 208          */
 209         excludeTestMaxRange("VMThreadStackSize");
 210 
 211         /*
 212          * Exclude CICompilerCount from testing because currently it can hang system
 213          */
 214         excludeTestMaxRange("CICompilerCount");
 215 
 216         /*
 217          * Exclude JVMCI threads counts from testing similar to other threads counts.
 218          */
 219         excludeTestMaxRange("JVMCIThreads");
 220         excludeTestMaxRange("JVMCIHostThreads");
 221 
 222         /*
 223          * Exclude MallocMaxTestWords as it is expected to exit VM at small values (>=0)
 224          */
 225         excludeTestMinRange("MallocMaxTestWords");
 226 
 227         /*
 228          * Exclude below options as their maximum value would consume too much memory
 229          * and would affect other tests that run in parallel.
 230          */
 231         excludeTestMaxRange("ConcGCThreads");
 232         excludeTestMaxRange("G1ConcRefinementThreads");
 233         excludeTestMaxRange("G1RSetRegionEntries");
 234         excludeTestMaxRange("G1RSetSparseRegionEntries");
 235         excludeTestMaxRange("G1UpdateBufferSize");
 236         excludeTestMaxRange("InitialBootClassLoaderMetaspaceSize");
 237         excludeTestMaxRange("InitialHeapSize");
 238         excludeTestMaxRange("MaxHeapSize");
 239         excludeTestMaxRange("MaxRAM");
 240         excludeTestMaxRange("NewSize");
 241         excludeTestMaxRange("OldSize");
 242         excludeTestMaxRange("ParallelGCThreads");
 243         excludeTestMaxRange("TLABSize");
 244 
 245         /*
 246          * Remove parameters controlling the code cache. As these
 247          * parameters have implications on the physical memory
 248          * reserved by the VM, setting them to large values may hang
 249          * the system and/or may cause concurrently executed tests to
 250          * fail. These parameters are rigorously checked when the code
 251          * cache is initialized (see
 252          * hotspot/src/shared/vm/code/codeCache.cpp), therefore
 253          * omitting testing for them does not pose a problem.
 254          */
 255         excludeTestMaxRange("InitialCodeCacheSize");
 256         excludeTestMaxRange("CodeCacheMinimumUseSpace");
 257         excludeTestMaxRange("ReservedCodeCacheSize");
 258         excludeTestMaxRange("NonProfiledCodeHeapSize");
 259         excludeTestMaxRange("ProfiledCodeHeapSize");
 260         excludeTestMaxRange("NonNMethodCodeHeapSize");
 261         excludeTestMaxRange("CodeCacheExpansionSize");
 262 
 263         List<JVMOption> testSubset = getTestSubset(args);
 264 
 265         Asserts.assertGT(testSubset.size(), 0, "Options with ranges not found!");
 266 
 267         System.out.println("Parsed " + testSubset.size() + " options with ranges. Start test!");
 268 
 269         failedTests = JVMOptionsUtils.runCommandLineTests(testSubset);
 270 
 271         Asserts.assertEQ(failedTests, 0,
 272                 String.format("%d tests failed! %s", failedTests, JVMOptionsUtils.getMessageWithFailures()));
 273     }
 274 }