1 /*
   2  * Copyright (c) 2016, 2018, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.jfr.startupargs;
  27 
  28 import java.util.List;
  29 import java.util.ArrayList;
  30 import java.lang.reflect.Field;
  31 
  32 import jdk.jfr.internal.Options;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 import jdk.test.lib.process.ProcessTools;
  35 import sun.misc.Unsafe;
  36 
  37 /**
  38  * @test
  39  * @key jfr
  40  * 
  41  * @library /lib /
  42  * 
  43  * @run main/timeout=900 jdk.jfr.startupargs.TestMemoryOptions
  44  */
  45 public class TestMemoryOptions {
  46 
  47     public enum Unit {
  48         b('b'), k('k'), m('m'), g('g');
  49 
  50         private char unit;
  51 
  52         Unit(char unit) {
  53             this.unit = unit;
  54         }
  55 
  56         char getUnit() {
  57             return unit;
  58         }
  59     };
  60 
  61     static class Option implements Comparable<Option> {
  62         static final long MIN_GLOBAL_BUFFER_COUNT = 2;
  63         static final long DEFAULT_GLOBAL_BUFFER_COUNT = 20;
  64         static final long MIN_GLOBAL_BUFFER_SIZE = 64 * 1024;
  65         static long DEFAULT_GLOBAL_BUFFER_SIZE = 524288;
  66         static final long MIN_MEMORY_SIZE = 1024 * 1024;
  67         static final long DEFAULT_MEMORY_SIZE = DEFAULT_GLOBAL_BUFFER_COUNT * DEFAULT_GLOBAL_BUFFER_SIZE;
  68         static final long MIN_THREAD_BUFFER_SIZE = 4 * 1024;
  69         static long DEFAULT_THREAD_BUFFER_SIZE;
  70         static final long PAGE_SIZE;
  71         static final long UNDEFINED = -1;
  72 
  73         static {
  74           try {
  75             Field theUnsafeRefLocation = Unsafe.class.getDeclaredField("theUnsafe");
  76             theUnsafeRefLocation.setAccessible(true);
  77             PAGE_SIZE = ((Unsafe)theUnsafeRefLocation.get(null)).pageSize();
  78           }
  79           catch(Exception ex) {
  80             throw new RuntimeException(ex);
  81           }
  82             if (PAGE_SIZE == MIN_THREAD_BUFFER_SIZE) {
  83                 DEFAULT_THREAD_BUFFER_SIZE = PAGE_SIZE * 2;
  84             } else {
  85                 DEFAULT_THREAD_BUFFER_SIZE = PAGE_SIZE;
  86             }
  87             if (PAGE_SIZE > DEFAULT_GLOBAL_BUFFER_SIZE) {
  88                 DEFAULT_GLOBAL_BUFFER_SIZE = PAGE_SIZE;
  89             }
  90         }
  91 
  92         final private long min;
  93         final private long max;
  94         final private String paramName;
  95 
  96         private long input;
  97         private Unit inputUnit;
  98         private long result;
  99         private Unit resultUnit;
 100 
 101         private long getValueAsUnit(long value, Unit unit) {
 102             switch (unit) {
 103                 case b:
 104                     return value;
 105                 case k:
 106                     return value / 1024;
 107                 case m:
 108                     return value / (1024 * 1024);
 109                 case g:
 110                     return value / (1024 * 1024 * 1024);
 111             }
 112             return value;
 113         }
 114 
 115         private long getRawValue(long value, Unit unit) {
 116             switch (unit) {
 117                 case b:
 118                     return value;
 119                 case k:
 120                     return value * 1024;
 121                 case m:
 122                     return value * (1024 * 1024);
 123                 case g:
 124                     return value * (1024 * 1024 * 1024);
 125             }
 126             return value;
 127         }
 128 
 129         private long parseValue(String valueString, char unit) {
 130             if (Character.isLetter(unit)) {
 131                 unit = Character.toLowerCase(unit);
 132                 return getRawValue(Long.parseLong(valueString.substring(0, valueString.length() - 1), 10),
 133                                                   Unit.valueOf(String.valueOf(unit)));
 134             }
 135             // does not have a unit, default is bytes
 136             return Long.parseLong(valueString.substring(0, valueString.length()), 10);
 137         }
 138 
 139         public Option(String minString, String maxString, String paramName) {
 140             if (minString == null) {
 141                 this.min = UNDEFINED;
 142             } else {
 143                 char unit = minString.charAt(minString.length() - 1);
 144                 this.min = parseValue(minString, unit);
 145             }
 146             if (maxString == null) {
 147                 this.max = UNDEFINED;
 148             } else {
 149                 char unit = maxString.charAt(maxString.length() - 1);
 150                 this.max = parseValue(maxString, unit);
 151             }
 152             this.input = UNDEFINED;
 153             this.result = UNDEFINED;
 154             this.paramName = paramName;
 155         }
 156 
 157         private Option(long value, char unit) {
 158             this.resultUnit = Unit.valueOf(String.valueOf(unit));
 159             this.result = getRawValue(value, this.resultUnit);
 160             this.min = UNDEFINED;
 161             this.max = UNDEFINED;
 162             this.paramName = "";
 163         }
 164 
 165         public void setInput(long value, char unit) {
 166             this.inputUnit = Unit.valueOf(String.valueOf(unit));
 167             this.input = getRawValue(value, this.inputUnit);
 168         }
 169 
 170         public long getInput() {
 171             return input;
 172         }
 173 
 174         public void setResult(long value, char unit) {
 175             this.resultUnit = Unit.valueOf(String.valueOf(unit));
 176             this.result = getRawValue(value, this.resultUnit);
 177         }
 178 
 179         public long getResult() {
 180             return result;
 181         }
 182 
 183         public long getResultAs(Unit unit) {
 184             return getValueAsUnit(this.result, unit);
 185         }
 186 
 187         public String getOptionParamName() {
 188             return paramName;
 189         }
 190 
 191         public String getOptionParamString() {
 192             if (input == UNDEFINED) {
 193                 return null;
 194             }
 195             char unit = inputUnit.getUnit();
 196             String unitString = Character.compare(unit, 'b') == 0 ? "" : String.valueOf(unit);
 197             return getOptionParamName() + "=" + Long.toString(getValueAsUnit(input, inputUnit)) + unitString;
 198         }
 199 
 200         public boolean predictedToStartVM() {
 201             if (input == UNDEFINED) {
 202                 // option not set
 203                 return true;
 204             }
 205             if (input >= 0) {
 206                 if (min != UNDEFINED) {
 207                     if (max != UNDEFINED) {
 208                         return input >= min && input <= max;
 209                     }
 210                     return input >= min;
 211                 }
 212                 if (max != UNDEFINED) {
 213                     if (min != UNDEFINED) {
 214                         return input <= max && input >= min;
 215                     }
 216                 }
 217                 return true;
 218             }
 219             return false;
 220         }
 221 
 222         public boolean isSet() {
 223             return input != UNDEFINED;
 224         }
 225 
 226         public boolean validate() throws IllegalArgumentException {
 227             // a result memory options should be page aligned
 228             if (getResult() > PAGE_SIZE) {
 229                 if (getResult() % PAGE_SIZE != 0) {
 230                     throw new IllegalArgumentException("Result value: "
 231                     + getResult() + " for option " + getOptionParamName() + " is not aligned to page size " + PAGE_SIZE);
 232                 }
 233             }
 234             // if min is defined, the result value should be gteq
 235             if (min != UNDEFINED) {
 236                 if (getResult() < min) {
 237                     throw new IllegalArgumentException("Result value: "
 238                     + getResult() + " for option " + getOptionParamName() + " is less than min: " + min);
 239                 }
 240             }
 241             // if max is defined, the result values should be lteq
 242             if (max != UNDEFINED) {
 243                 if (getResult() > max) {
 244                     throw new IllegalArgumentException("Result value: "
 245                     + getResult() + " for option " + getOptionParamName() + " is greater than max: " + max);
 246                 }
 247             }
 248             return true;
 249         }
 250 
 251         @Override
 252         public int compareTo(Option obj) {
 253             if (getResult() == obj.getResult()) {
 254                 return 0;
 255             }
 256             return getResult() > obj.getResult() ? 1 : -1;
 257         }
 258 
 259         @Override
 260         public boolean equals(Object obj) {
 261             if (obj == null) {
 262                 return false;
 263             }
 264             if (!Option.class.isAssignableFrom(obj.getClass())) {
 265                 return false;
 266             }
 267             final Option other = (Option) obj;
 268 
 269             return getResult() == other.getResult();
 270         }
 271 
 272         @Override
 273         public int hashCode() {
 274             long hash = 3;
 275             hash = 53 * hash * getResult();
 276             return (int)hash;
 277         }
 278 
 279         @Override
 280         public String toString() {
 281             return Long.toString(getResult());
 282         }
 283 
 284         public Option multiply(Option rhsFactor) {
 285             return new Option(getResult() * rhsFactor.getResult(), 'b');
 286         }
 287 
 288         public Option divide(Option rhsDivisor) {
 289             long divisor = rhsDivisor.getResult();
 290             if (divisor == 0) {
 291                 return new Option(0, 'b');
 292             }
 293             return new Option(getResult() / divisor, 'b');
 294         }
 295 
 296         boolean isLessThanOrEqual(Option rhs) {
 297             return getResult() <= rhs.getResult();
 298         }
 299 
 300         boolean isGreaterThanOrEqual(Option rhs) {
 301             return getResult() >= rhs.getResult();
 302         }
 303     }
 304 
 305     private static class TestCase {
 306         private static final int MEMORYSIZE = 0;
 307         private static final int GLOBALBUFFERSIZE = 1;
 308         private static final int GLOBALBUFFERCOUNT = 2;
 309         private static final int THREADBUFFERSIZE = 3;
 310 
 311         final private List<Option> optionList = new ArrayList<Option>();
 312         final private String testName;
 313 
 314         public TestCase(String testName, boolean runTest) {
 315             this.testName = testName;
 316             Option memorySize = new Option(Long.toString(Option.MIN_MEMORY_SIZE), null, "memorysize");
 317             optionList.add(memorySize);
 318 
 319             Option globalBufferSize = new Option(Long.toString(Option.MIN_GLOBAL_BUFFER_SIZE),
 320                                                  null, "globalbuffersize");
 321             optionList.add(globalBufferSize);
 322 
 323             Option globalBufferCount = new Option(Long.toString(Option.MIN_GLOBAL_BUFFER_COUNT), null, "numglobalbuffers");
 324             optionList.add(globalBufferCount);
 325 
 326             Option threadBufferSize = new Option(Long.toString(Option.MIN_THREAD_BUFFER_SIZE), null, "threadbuffersize");
 327             optionList.add(threadBufferSize);
 328 
 329             if (runTest) {
 330                 populateResults();
 331                 validateNodes();
 332                 validateEdges();
 333             }
 334         }
 335 
 336         public String getTestString() {
 337             String optionString = "-XX:FlightRecorderOptions=";
 338             for (Option o : optionList) {
 339                 String optionParamString = o.getOptionParamString();
 340                 if (optionParamString == null) {
 341                     continue;
 342                 }
 343                 optionString = optionString.concat(optionParamString);
 344                 optionString = optionString.concat(",");
 345             }
 346             if (optionString.equals("-XX:FlightRecorderOptions=")) {
 347                 return null;
 348             }
 349             // strip last ","
 350             optionString = optionString.substring(0, optionString.length() - 1);
 351             return optionString;
 352         }
 353 
 354         public String getTestName() {
 355             return this.testName;
 356         }
 357 
 358         private void setInputForIndex(int index, long size, char unit) {
 359             optionList.get(index).setInput(size, unit);
 360         }
 361 
 362         private void setResultForIndex(int index, long size, char unit) {
 363             optionList.get(index).setResult(size, unit);
 364         }
 365 
 366         public void setMemorySizeTestParam(long size, char unit) {
 367             setInputForIndex(MEMORYSIZE, size, unit);
 368         }
 369 
 370         public void setMemorySizeTestResult(long size, char unit) {
 371             setResultForIndex(MEMORYSIZE, size, unit);
 372         }
 373 
 374         public void setGlobalBufferSizeTestParam(long size, char unit) {
 375             setInputForIndex(GLOBALBUFFERSIZE, size, unit);
 376         }
 377 
 378         public void setGlobalBufferSizeTestResult(long size, char unit) {
 379             setResultForIndex(GLOBALBUFFERSIZE, size, unit);
 380         }
 381 
 382         public void setGlobalBufferCountTestParam(long size, char unit) {
 383             setInputForIndex(GLOBALBUFFERCOUNT, size, unit);
 384         }
 385 
 386         public void setGlobalBufferCountTestResult(long size, char unit) {
 387             setResultForIndex(GLOBALBUFFERCOUNT, size, unit);
 388         }
 389 
 390         public void setThreadBufferSizeTestParam(long size, char unit) {
 391             setInputForIndex(THREADBUFFERSIZE, size, unit);
 392         }
 393 
 394         public void setThreadBufferSizeTestResult(long size, char unit) {
 395             setResultForIndex(THREADBUFFERSIZE, size, unit);
 396         }
 397 
 398         public void validateNodes() {
 399             for (Option o : optionList) {
 400                 o.validate();
 401             }
 402         }
 403 
 404         public void validateEdges() {
 405             final Option memorySize = optionList.get(MEMORYSIZE);
 406             final Option globalBufferSize = optionList.get(GLOBALBUFFERSIZE);
 407             final Option globalBufferCount = optionList.get(GLOBALBUFFERCOUNT);
 408             final Option threadBufferSize = optionList.get(THREADBUFFERSIZE);
 409 
 410             if (!memorySize.divide(globalBufferCount).equals(globalBufferSize)) {
 411                 throw new IllegalArgumentException(getTestName() + " failure: " + memorySize.getOptionParamName() + " (" + memorySize.getResult() + ") / " +
 412                                                    globalBufferCount.getOptionParamName() + " (" + globalBufferCount.getResult() +
 413                                                    ") (" + memorySize.divide(globalBufferCount).getResult() + ") != " +
 414                                                    globalBufferSize.getOptionParamName() + " (" + globalBufferSize.getResult() + ")");
 415             }
 416 
 417             if (!globalBufferSize.multiply(globalBufferCount).equals(memorySize)) {
 418                 throw new IllegalArgumentException(getTestName() + " failure: " + globalBufferSize.getOptionParamName() + ": " +
 419                                                    globalBufferSize.getResult() +
 420                                                    " * " + globalBufferCount.getOptionParamName() + ": " + globalBufferCount.getResult() +
 421                                                    " != " + memorySize.getOptionParamName() + ": " + memorySize.getResult());
 422             }
 423 
 424             if (!threadBufferSize.isLessThanOrEqual(globalBufferSize)) {
 425                 throw new IllegalArgumentException(getTestName() + " failure: " + threadBufferSize.getOptionParamName() + ": " + threadBufferSize.getResult() +
 426                                                    " is larger than " + globalBufferSize.getOptionParamName() + ": " + globalBufferSize.getResult());
 427             }
 428         }
 429 
 430         public void print() {
 431             System.out.println("Printing information for testcase : " + getTestName());
 432             for (Option o : optionList) {
 433                 System.out.println("Parameter name: " + o.getOptionParamName());
 434                 System.out.println("Parameter test value : " + o.getOptionParamString() != null ?  o.getOptionParamString() : "not enabled for input testing");
 435                 String inputString = o.getInput() == Option.UNDEFINED ? "N/A" : Long.toString(o.getInput());
 436                 System.out.println("Input value: " + inputString);
 437                 System.out.println("Predicted to start VM: " + (o.predictedToStartVM() ? "true" : "false"));
 438             }
 439         }
 440 
 441         private void populateResults() {
 442             optionList.get(MEMORYSIZE).setResult(Options.getMemorySize(), 'b');
 443             optionList.get(GLOBALBUFFERSIZE).setResult(Options.getGlobalBufferSize(), 'b');
 444             optionList.get(GLOBALBUFFERCOUNT).setResult(Options.getGlobalBufferCount(), 'b');
 445             optionList.get(THREADBUFFERSIZE).setResult(Options.getThreadBufferSize(), 'b');
 446         }
 447 
 448         public boolean predictedToStartVM() {
 449             // check each individual option
 450             for (Option o : optionList) {
 451                 if (!o.predictedToStartVM()) {
 452                     return false;
 453                 }
 454             }
 455 
 456             // check known invalid combinations that will not allow the VM to start
 457 
 458             // GLOBALBUFFERSIZE * GLOBALBUFFERCOUNT == MEMORYSIZE
 459             if (optionList.get(GLOBALBUFFERSIZE).isSet() && optionList.get(GLOBALBUFFERCOUNT).isSet()
 460                && optionList.get(MEMORYSIZE).isSet()) {
 461                long calculatedMemorySize = optionList.get(GLOBALBUFFERSIZE).getInput() * optionList.get(GLOBALBUFFERCOUNT).getInput();
 462                if (optionList.get(MEMORYSIZE).getInput() != calculatedMemorySize) {
 463                    return false;
 464                }
 465             }
 466             // GLOBALBUFFERSIZE * GLOBALBUFFERCOUNT >= MIN_MEMORY_SIZE
 467             if (optionList.get(GLOBALBUFFERSIZE).isSet() && optionList.get(GLOBALBUFFERCOUNT).isSet()
 468                 && !optionList.get(MEMORYSIZE).isSet()) {
 469                 long calculatedMemorySize = optionList.get(GLOBALBUFFERSIZE).getInput() * optionList.get(GLOBALBUFFERCOUNT).getInput();
 470                 if (Option.MIN_MEMORY_SIZE > calculatedMemorySize) {
 471                     return false;
 472                 }
 473             }
 474             // GLOBALBUFFERSIZE >= THREADBUFFERSIZE
 475             if (optionList.get(GLOBALBUFFERSIZE).isSet() && optionList.get(THREADBUFFERSIZE).isSet()) {
 476                 if (optionList.get(GLOBALBUFFERSIZE).getInput() < optionList.get(THREADBUFFERSIZE).getInput()) {
 477                     return false;
 478                 }
 479             }
 480             return true;
 481         }
 482     }
 483 
 484     public static class SUT {
 485         public static void main(String[] args) {
 486             TestCase tc = new TestCase(args[0], true);
 487         }
 488     }
 489 
 490     private static class Driver {
 491         private static void launchTestVM(TestCase tc) throws Exception {
 492             final String flightRecorderOptions = tc.getTestString();
 493             ProcessBuilder pb;
 494             if (flightRecorderOptions != null) {
 495                 pb = ProcessTools.createJavaProcessBuilder(true,
 496                                                            flightRecorderOptions,
 497                                                            "-XX:StartFlightRecording",
 498                                                            SUT.class.getName(),
 499                                                            tc.getTestName());
 500             } else {
 501                 // default, no FlightRecorderOptions passed
 502                 pb = ProcessTools.createJavaProcessBuilder(true,
 503                                                            "-XX:StartFlightRecording",
 504                                                            SUT.class.getName(),
 505                                                            tc.getTestName());
 506             }
 507 
 508             System.out.println("Driver launching SUT with string: " + flightRecorderOptions != null ? flightRecorderOptions : "default");
 509             System.out.println("SUT VM " + (tc.predictedToStartVM() ? "is" : "is not") + " expected to start");
 510             tc.print();
 511 
 512             OutputAnalyzer out = ProcessTools.executeProcess(pb);
 513 
 514             if (tc.predictedToStartVM()) {
 515                 out.shouldHaveExitValue(0);
 516             } else {
 517                 out.shouldContain("Failure when starting JFR");
 518                 out.shouldHaveExitValue(1);
 519             }
 520         }
 521 
 522         public static void runTestCase(TestCase tc) throws Exception {
 523             launchTestVM(tc);
 524         }
 525     }
 526 
 527     static private List<TestCase> testCases = new ArrayList<TestCase>();
 528 
 529     static {
 530         // positive example-based tests
 531         TestCase tc = new TestCase("DefaultOptionsPositive", false);
 532         // defaults, no options explicitly set
 533         testCases.add(tc);
 534 
 535         // explicit defaults passed as parameters
 536         tc = new TestCase("MemorySizePositive", false);
 537         tc.setMemorySizeTestParam(10, 'm');
 538         testCases.add(tc);
 539 
 540         tc = new TestCase("GlobalBufferSizePositive", false);
 541         tc.setGlobalBufferSizeTestParam(512, 'k');
 542         testCases.add(tc);
 543 
 544         tc = new TestCase("BufferCountPositive", false);
 545         tc.setGlobalBufferCountTestParam(20, 'b');
 546         testCases.add(tc);
 547 
 548         tc = new TestCase("ThreadBufferSizePositive", false);
 549         tc.setThreadBufferSizeTestParam(Option.DEFAULT_THREAD_BUFFER_SIZE, 'b');
 550         testCases.add(tc);
 551 
 552         // negative example-based tests, each individual option below minimum size
 553         tc = new TestCase("MemorySizeBelowMinNegative", false);
 554         tc.setMemorySizeTestParam(Option.MIN_MEMORY_SIZE - 1, 'b');
 555         testCases.add(tc);
 556 
 557         tc = new TestCase("GlobalBufferSizeBelowMinNegative", false);
 558         tc.setGlobalBufferSizeTestParam(Option.MIN_GLOBAL_BUFFER_SIZE - 1, 'b');
 559         testCases.add(tc);
 560 
 561         tc = new TestCase("BufferCountBelowMinNegative", false);
 562         tc.setGlobalBufferCountTestParam(Option.MIN_GLOBAL_BUFFER_COUNT - 1, 'b');
 563         testCases.add(tc);
 564 
 565         tc = new TestCase("ThreadBufferSizeBelowMinNegative", false);
 566         tc.setThreadBufferSizeTestParam(Option.MIN_THREAD_BUFFER_SIZE - 1, 'b');
 567         testCases.add(tc);
 568 
 569         // Memory size permutations
 570         // a few single memorysize option for deduction
 571         tc = new TestCase("MemorySizeValue1Positive", false);
 572         tc.setMemorySizeTestParam(48128, 'k'); // 47mb
 573         testCases.add(tc);
 574 
 575         tc = new TestCase("MemorySizeValue2Positive", false);
 576         tc.setMemorySizeTestParam(17391, 'k'); // 17808384 bytes
 577         testCases.add(tc);
 578 
 579         tc = new TestCase("MemorySizeValue3Positive", false);
 580         tc.setMemorySizeTestParam(Option.MIN_MEMORY_SIZE + 17, 'b');
 581         testCases.add(tc);
 582 
 583         // positive example-based-tests, memory size combined with other options
 584         tc = new TestCase("MemorySizeGlobalBufferSizePositive", false);
 585         tc.setMemorySizeTestParam(14680064, 'b'); // 14mb
 586         tc.setGlobalBufferSizeTestParam(720, 'k');
 587         testCases.add(tc);
 588 
 589         tc = new TestCase("MemorySizeGlobalBufferCountPositive", false);
 590         tc.setMemorySizeTestParam(14674581, 'b'); // 14mb - 5483 bytes
 591         tc.setGlobalBufferCountTestParam(17, 'b');
 592         testCases.add(tc);
 593 
 594         tc = new TestCase("MemorySizeThreadBufferSizePositive", false);
 595         tc.setMemorySizeTestParam(14586853, 'b'); // 14mb - 93211 bytes
 596         tc.setThreadBufferSizeTestParam(Option.DEFAULT_THREAD_BUFFER_SIZE, 'b');
 597         testCases.add(tc);
 598 
 599         tc = new TestCase("MemorySizeGlobalBufferSizeBufferCountPositive", false);
 600         tc.setMemorySizeTestParam(12240, 'k');
 601         tc.setGlobalBufferSizeTestParam(720, 'k'); // 720 k * 17 == 12240 k
 602         tc.setGlobalBufferCountTestParam(17, 'b');
 603         testCases.add(tc);
 604 
 605         tc = new TestCase("MemorySizeGlobalBufferSizeBufferCountThreadBufferSizePositive", false);
 606         tc.setMemorySizeTestParam(12240, 'k');
 607         tc.setGlobalBufferSizeTestParam(720, 'k'); // 720 k * 17 == 12240 k
 608         tc.setGlobalBufferCountTestParam(17, 'b');
 609         tc.setThreadBufferSizeTestParam(600, 'k');
 610         testCases.add(tc);
 611 
 612         // negative example-based test, create an ambiguous situtation
 613         tc = new TestCase("MemorySizeGlobalBufferSizeBufferCountAmbiguousNegative", false);
 614         tc.setMemorySizeTestParam(12240, 'k');
 615         tc.setGlobalBufferSizeTestParam(720, 'k'); // 720 k * 19 != 12240 k
 616         tc.setGlobalBufferCountTestParam(19, 'b');
 617         testCases.add(tc);
 618 
 619         // Global buffer size permutations
 620         tc = new TestCase("GlobalBufferSizeBufferCountPositive", false);
 621         tc.setGlobalBufferSizeTestParam(917, 'k');
 622         tc.setGlobalBufferCountTestParam(31, 'b');
 623         testCases.add(tc);
 624 
 625         tc = new TestCase("GlobalBufferSizeBufferCountThreadBufferSizePositive", false);
 626         tc.setGlobalBufferSizeTestParam(917, 'k');
 627         tc.setGlobalBufferCountTestParam(31, 'b');
 628         tc.setThreadBufferSizeTestParam(760832, 'b'); // 743 k
 629         testCases.add(tc);
 630 
 631         // negative example-based test, let thread buffer size > global buffer size
 632         tc = new TestCase("GlobalBufferSizeLessThanThreadBufferSizeNegative", false);
 633         tc.setGlobalBufferSizeTestParam(917, 'k');
 634         tc.setThreadBufferSizeTestParam(1317, 'k');
 635         testCases.add(tc);
 636 
 637         // explicitly specifying global buffer size and global buffer count must be gteq min memorysize
 638         tc = new TestCase("GlobalBufferSizeTimesGlobalBufferCountLessThanMinMemorySizeNegative", false);
 639         tc.setGlobalBufferSizeTestParam(67857, 'b');
 640         tc.setGlobalBufferCountTestParam(3, 'b');
 641         testCases.add(tc);
 642 
 643         // absolute minimum size
 644         tc = new TestCase("GlobalBufferSizeTimesGlobalBufferCountEqualToMinMemorySizePositive", false);
 645         tc.setGlobalBufferSizeTestParam(64, 'k');
 646         tc.setGlobalBufferCountTestParam(16, 'b');
 647         testCases.add(tc);
 648     }
 649 
 650     public static void main(String[] args) throws Exception {
 651         System.out.println("Testing " + testCases.size() + " number of testcases");
 652         for (TestCase tc : testCases) {
 653             Driver.runTestCase(tc);
 654         }
 655     }
 656 }