1 /* 2 * Copyright (c) 2021, 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 package ir_framework.tests; 25 26 import compiler.lib.ir_framework.*; 27 import compiler.lib.ir_framework.test.TestVM; 28 29 import java.lang.reflect.Method; 30 import java.util.Arrays; 31 import java.util.stream.Stream; 32 33 /* 34 * @test 35 * @requires vm.compiler2.enabled & vm.flagless 36 * @summary Test basics of the framework. This test runs directly the test VM which normally does not happen. 37 * @library /test/lib / 38 * @build sun.hotspot.WhiteBox 39 * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox 40 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 41 * -Xbatch ir_framework.tests.TestBasics 42 */ 43 44 public class TestBasics { 45 private static boolean wasExecuted = false; 46 private boolean lastToggleBoolean = true; 47 private final static int[] executed = new int[100]; 48 private final static int[] executedOnce = new int[5]; 49 private long[] nonFloatingRandomNumbers = new long[10]; 50 private double[] floatingRandomNumbers = new double[10]; 51 private Boolean[] randomBooleans = new Boolean[64]; 52 main(String[] args)53 public static void main(String[] args) throws Exception { 54 // Run on same VM to make this test easier as we are not interested in any output processing. 55 Class<?> c = TestFramework.class; // Enable JTreg test to compile TestFramework 56 Method runTestsOnSameVM = TestVM.class.getDeclaredMethod("runTestsOnSameVM", Class.class); 57 runTestsOnSameVM.setAccessible(true); 58 runTestsOnSameVM.invoke(null, new Object[]{ null }); 59 60 if (wasExecuted) { 61 throw new RuntimeException("Executed non @Test method or a method that was not intended to be run"); 62 } 63 for (int i = 0; i < executed.length; i++) { 64 int value = executed[i]; 65 if (value != TestVM.WARMUP_ITERATIONS + 1) { 66 // Warmups + 1 C2 compiled invocation 67 throw new RuntimeException("Test " + i + " was executed " + value + " times instead stead of " 68 + (TestVM.WARMUP_ITERATIONS + 1) + " times." ); 69 } 70 } 71 72 for (int value : executedOnce) { 73 if (value != 1) { 74 throw new RuntimeException("Check function should have been executed exactly once"); 75 } 76 } 77 } 78 clearNonFloatingRandomNumbers()79 private void clearNonFloatingRandomNumbers() { 80 nonFloatingRandomNumbers = new long[10]; 81 } 82 clearFloatingRandomNumbers()83 private void clearFloatingRandomNumbers() { 84 floatingRandomNumbers = new double[10]; 85 } 86 clearRandomBooleans()87 private void clearRandomBooleans() { 88 randomBooleans = new Boolean[64]; 89 } 90 91 // Base test, no arguments, directly invoked. 92 @Test test()93 public void test() { 94 executed[0]++; 95 } 96 97 // Not a test noTest()98 public void noTest() { 99 wasExecuted = true; 100 } 101 102 // Not a test test2()103 public void test2() { 104 wasExecuted = true; 105 } 106 107 // Can overload non- @Test test2(int i)108 public static void test2(int i) { 109 wasExecuted = true; 110 } 111 112 // Can overload a @Test if it is not a @Test itself. test(double i)113 public static void test(double i) { 114 wasExecuted = true; 115 } 116 117 @Test staticTest()118 public static void staticTest() { 119 executed[1]++; 120 } 121 122 @Test finalTest()123 public final void finalTest() { 124 executed[2]++; 125 } 126 127 @Test returnValueTest()128 public int returnValueTest() { 129 executed[3]++; 130 return 4; 131 } 132 133 // Base test, with arguments, directly invoked. 134 // Specify the argument values with @Arguments 135 @Test 136 @Arguments(Argument.DEFAULT) byteDefaultArgument(byte x)137 public void byteDefaultArgument(byte x) { 138 executed[4]++; 139 if (x != 0) { 140 throw new RuntimeException("Must be 0"); 141 } 142 } 143 144 @Test 145 @Arguments(Argument.DEFAULT) shortDefaultArgument(short x)146 public void shortDefaultArgument(short x) { 147 executed[5]++; 148 if (x != 0) { 149 throw new RuntimeException("Must be 0"); 150 } 151 } 152 153 @Test 154 @Arguments(Argument.DEFAULT) intDefaultArgument(int x)155 public void intDefaultArgument(int x) { 156 executed[6]++; 157 if (x != 0) { 158 throw new RuntimeException("Must be 0"); 159 } 160 } 161 162 @Test 163 @Arguments(Argument.DEFAULT) longDefaultArgument(long x)164 public void longDefaultArgument(long x) { 165 executed[7]++; 166 if (x != 0L) { 167 throw new RuntimeException("Must be 0"); 168 } 169 } 170 171 @Test 172 @Arguments(Argument.DEFAULT) floatDefaultArgument(float x)173 public void floatDefaultArgument(float x) { 174 executed[8]++; 175 if (x != 0.0f) { 176 throw new RuntimeException("Must be 0.0"); 177 } 178 } 179 180 @Test 181 @Arguments(Argument.DEFAULT) doubleDefaultArgument(double x)182 public void doubleDefaultArgument(double x) { 183 executed[9]++; 184 if (x != 0.0f) { 185 throw new RuntimeException("Must be 0.0"); 186 } 187 } 188 189 @Test 190 @Arguments(Argument.DEFAULT) charDefaultArgument(char x)191 public void charDefaultArgument(char x) { 192 executed[10]++; 193 if (x != '\u0000') { 194 throw new RuntimeException("Must be \u0000"); 195 } 196 } 197 198 @Test 199 @Arguments(Argument.DEFAULT) booleanDefaultArgument(boolean x)200 public void booleanDefaultArgument(boolean x) { 201 executed[11]++; 202 if (x) { 203 throw new RuntimeException("Must be false"); 204 } 205 } 206 207 @Test 208 @Arguments(Argument.DEFAULT) stringObjectDefaultArgument(String x)209 public void stringObjectDefaultArgument(String x) { 210 executed[12]++; 211 if (x == null || x.length() != 0) { 212 throw new RuntimeException("Default string object must be non-null and having a length of zero"); 213 } 214 } 215 216 @Test 217 @Arguments(Argument.DEFAULT) defaultObjectDefaultArgument(DefaultObject x)218 public void defaultObjectDefaultArgument(DefaultObject x) { 219 executed[13]++; 220 if (x == null || x.i != 4) { 221 throw new RuntimeException("Default object must not be null and its i field must be 4"); 222 } 223 } 224 225 @Test 226 @Arguments(Argument.NUMBER_42) byte42(byte x)227 public void byte42(byte x) { 228 executed[14]++; 229 if (x != 42) { 230 throw new RuntimeException("Must be 42"); 231 } 232 } 233 234 @Test 235 @Arguments(Argument.NUMBER_42) short42(short x)236 public void short42(short x) { 237 executed[15]++; 238 if (x != 42) { 239 throw new RuntimeException("Must be 42"); 240 } 241 } 242 243 @Test 244 @Arguments(Argument.NUMBER_42) int42(int x)245 public void int42(int x) { 246 executed[16]++; 247 if (x != 42) { 248 throw new RuntimeException("Must be 42"); 249 } 250 } 251 252 @Test 253 @Arguments(Argument.NUMBER_42) long42(long x)254 public void long42(long x) { 255 executed[17]++; 256 if (x != 42) { 257 throw new RuntimeException("Must be 42"); 258 } 259 } 260 261 @Test 262 @Arguments(Argument.NUMBER_42) float42(float x)263 public void float42(float x) { 264 executed[18]++; 265 if (x != 42.0) { 266 throw new RuntimeException("Must be 42"); 267 } 268 } 269 270 @Test 271 @Arguments(Argument.NUMBER_42) double42(double x)272 public void double42(double x) { 273 executed[19]++; 274 if (x != 42.0) { 275 throw new RuntimeException("Must be 42"); 276 } 277 } 278 279 @Test 280 @Arguments(Argument.FALSE) booleanFalse(boolean x)281 public void booleanFalse(boolean x) { 282 executed[20]++; 283 if (x) { 284 throw new RuntimeException("Must be false"); 285 } 286 } 287 288 @Test 289 @Arguments(Argument.TRUE) booleanTrue(boolean x)290 public void booleanTrue(boolean x) { 291 executed[21]++; 292 if (!x) { 293 throw new RuntimeException("Must be true"); 294 } 295 } 296 297 @Test 298 @Arguments(Argument.RANDOM_ONCE) randomByte(byte x)299 public void randomByte(byte x) { 300 executed[22]++; 301 } 302 303 @Test 304 @Arguments(Argument.RANDOM_ONCE) randomShort(short x)305 public void randomShort(short x) { 306 executed[23]++; 307 } 308 309 @Test 310 @Arguments(Argument.RANDOM_ONCE) randomInt(int x)311 public void randomInt(int x) { 312 executed[24]++; 313 } 314 315 @Test 316 @Arguments(Argument.RANDOM_ONCE) randomLong(long x)317 public void randomLong(long x) { 318 executed[25]++; 319 } 320 321 @Test 322 @Arguments(Argument.RANDOM_ONCE) randomFloat(float x)323 public void randomFloat(float x) { 324 executed[26]++; 325 } 326 327 @Test 328 @Arguments(Argument.RANDOM_ONCE) randomDouble(double x)329 public void randomDouble(double x) { 330 executed[27]++; 331 } 332 333 // Not executed randomNotExecutedTest(double x)334 public void randomNotExecutedTest(double x) { 335 wasExecuted = true; 336 } 337 338 @Test 339 @Arguments(Argument.RANDOM_ONCE) randomBoolean(boolean x)340 public void randomBoolean(boolean x) { 341 executed[28]++; 342 } 343 344 @Test 345 @Arguments(Argument.BOOLEAN_TOGGLE_FIRST_FALSE) booleanToggleFirstFalse(boolean x)346 public void booleanToggleFirstFalse(boolean x) { 347 if (executed[29] == 0) { 348 // First invocation 349 if (x) { 350 throw new RuntimeException("BOOLEAN_TOGGLE_FIRST_FALSE must be false on first invocation"); 351 } 352 } else if (x == lastToggleBoolean) { 353 throw new RuntimeException("BOOLEAN_TOGGLE_FIRST_FALSE did not toggle"); 354 } 355 lastToggleBoolean = x; 356 executed[29]++; 357 } 358 359 @Test 360 @Arguments(Argument.RANDOM_EACH) randomEachByte(byte x)361 public void randomEachByte(byte x) { 362 checkNonFloatingRandomNumber(x, executed[30]); 363 executed[30]++; 364 } 365 366 @Test 367 @Arguments(Argument.RANDOM_EACH) randomEachShort(short x)368 public void randomEachShort(short x) { 369 checkNonFloatingRandomNumber(x, executed[31]); 370 executed[31]++; 371 } 372 373 @Test 374 @Arguments(Argument.RANDOM_EACH) randomEachInt(int x)375 public void randomEachInt(int x) { 376 checkNonFloatingRandomNumber(x, executed[32]); 377 executed[32]++; 378 } 379 380 @Test 381 @Arguments(Argument.RANDOM_EACH) randomEachLong(long x)382 public void randomEachLong(long x) { 383 checkNonFloatingRandomNumber(x, executed[33]); 384 executed[33]++; 385 } 386 387 @Test 388 @Arguments(Argument.RANDOM_EACH) randomEachChar(char x)389 public void randomEachChar(char x) { 390 checkNonFloatingRandomNumber(x, executed[34]); 391 executed[34]++; 392 } 393 394 @Test 395 @Arguments(Argument.RANDOM_EACH) randomEachFloat(float x)396 public void randomEachFloat(float x) { 397 checkFloatingRandomNumber(x, executed[35]); 398 executed[35]++; 399 } 400 401 @Test 402 @Arguments(Argument.RANDOM_EACH) randomEachDouble(double x)403 public void randomEachDouble(double x) { 404 checkFloatingRandomNumber(x, executed[36]); 405 executed[36]++; 406 } 407 408 @Test 409 @Arguments(Argument.RANDOM_EACH) randomEachBoolean(boolean x)410 public void randomEachBoolean(boolean x) { 411 checkRandomBoolean(x, executed[37]); 412 executed[37]++; 413 } 414 checkNonFloatingRandomNumber(long x, int invocationCount)415 private void checkNonFloatingRandomNumber(long x, int invocationCount) { 416 int mod10 = invocationCount % 10; 417 if (invocationCount > 0 && mod10 == 0) { 418 // Not first invocation 419 // Check the last 10 numbers and ensure that there are at least 2 different ones. 420 // All numbers are equal? Very unlikely nd we should really consider to play the lottery... 421 long first = nonFloatingRandomNumbers[0]; 422 if (Arrays.stream(nonFloatingRandomNumbers).allMatch(n -> n == first)) { 423 throw new RuntimeException("RANDOM_EACH does not generate random integer numbers"); 424 } 425 clearNonFloatingRandomNumbers(); 426 } 427 nonFloatingRandomNumbers[mod10] = x; 428 } 429 checkFloatingRandomNumber(double x, int invocationCount)430 private void checkFloatingRandomNumber(double x, int invocationCount) { 431 int mod10 = invocationCount % 10; 432 if (invocationCount > 0 && mod10 == 0) { 433 // Not first invocation 434 // Check the last 10 numbers and ensure that there are at least 2 different ones. 435 // All numbers are equal? Very unlikely nd we should really consider to play the lottery... 436 double first = floatingRandomNumbers[0]; 437 if (Arrays.stream(floatingRandomNumbers).allMatch(n -> n == first)) { 438 throw new RuntimeException("RANDOM_EACH does not generate random floating point numbers"); 439 } 440 clearFloatingRandomNumbers(); 441 } 442 floatingRandomNumbers[mod10] = x; 443 } 444 checkRandomBoolean(boolean x, int invocationCount)445 private void checkRandomBoolean(boolean x, int invocationCount) { 446 int mod64 = invocationCount % 64; 447 if (invocationCount > 0 && mod64 == 0) { 448 // Not first invocation 449 // Check the last 64 booleans and ensure that there are at least one true and one false. 450 // All booleans are equal? Very unlikely (chance of 2^64) and we should really consider 451 // to play the lottery... 452 if (Arrays.stream(randomBooleans).allMatch(b -> b == randomBooleans[0])) { 453 throw new RuntimeException("RANDOM_EACH does not generate random booleans"); 454 } 455 clearRandomBooleans(); 456 } 457 randomBooleans[mod64] = x; 458 } 459 460 461 @Test 462 @Arguments(Argument.NUMBER_MINUS_42) byteMinus42(byte x)463 public void byteMinus42(byte x) { 464 executed[38]++; 465 if (x != -42) { 466 throw new RuntimeException("Must be -42"); 467 } 468 } 469 470 @Test 471 @Arguments(Argument.NUMBER_MINUS_42) shortMinus42(short x)472 public void shortMinus42(short x) { 473 executed[39]++; 474 if (x != -42) { 475 throw new RuntimeException("Must be -42"); 476 } 477 } 478 479 @Test 480 @Arguments(Argument.NUMBER_MINUS_42) intMinus42(int x)481 public void intMinus42(int x) { 482 executed[40]++; 483 if (x != -42) { 484 throw new RuntimeException("Must be -42"); 485 } 486 } 487 488 @Test 489 @Arguments(Argument.NUMBER_MINUS_42) longMinus42(long x)490 public void longMinus42(long x) { 491 executed[41]++; 492 if (x != -42) { 493 throw new RuntimeException("Must be -42"); 494 } 495 } 496 497 @Test 498 @Arguments(Argument.NUMBER_MINUS_42) floatMinus42(float x)499 public void floatMinus42(float x) { 500 executed[42]++; 501 if (x != -42.0) { 502 throw new RuntimeException("Must be -42"); 503 } 504 } 505 506 @Test 507 @Arguments(Argument.NUMBER_MINUS_42) doubleMinus42(double x)508 public void doubleMinus42(double x) { 509 executed[43]++; 510 if (x != -42.0) { 511 throw new RuntimeException("Must be -42"); 512 } 513 } 514 515 @Test 516 @Arguments(Argument.MIN) byteMin(byte x)517 public void byteMin(byte x) { 518 executed[79]++; 519 if (x != Byte.MIN_VALUE) { 520 throw new RuntimeException("Must be MIN_VALUE"); 521 } 522 } 523 524 @Test 525 @Arguments(Argument.MIN) charMin(char x)526 public void charMin(char x) { 527 executed[80]++; 528 if (x != Character.MIN_VALUE) { 529 throw new RuntimeException("Must be MIN_VALUE"); 530 } 531 } 532 533 @Test 534 @Arguments(Argument.MIN) shortMin(short x)535 public void shortMin(short x) { 536 executed[81]++; 537 if (x != Short.MIN_VALUE) { 538 throw new RuntimeException("Must be MIN_VALUE"); 539 } 540 } 541 542 @Test 543 @Arguments(Argument.MIN) intMin(int x)544 public void intMin(int x) { 545 executed[82]++; 546 if (x != Integer.MIN_VALUE) { 547 throw new RuntimeException("Must be MIN_VALUE"); 548 } 549 } 550 551 @Test 552 @Arguments(Argument.MIN) longMin(long x)553 public void longMin(long x) { 554 executed[83]++; 555 if (x != Long.MIN_VALUE) { 556 throw new RuntimeException("Must be MIN_VALUE"); 557 } 558 } 559 560 @Test 561 @Arguments(Argument.MIN) floatMin(float x)562 public void floatMin(float x) { 563 executed[84]++; 564 if (x != Float.MIN_VALUE) { 565 throw new RuntimeException("Must be MIN_VALUE"); 566 } 567 } 568 569 @Test 570 @Arguments(Argument.MIN) doubleMin(double x)571 public void doubleMin(double x) { 572 executed[85]++; 573 if (x != Double.MIN_VALUE) { 574 throw new RuntimeException("Must be MIN_VALUE"); 575 } 576 } 577 578 @Test 579 @Arguments(Argument.MAX) byteMax(byte x)580 public void byteMax(byte x) { 581 executed[86]++; 582 if (x != Byte.MAX_VALUE) { 583 throw new RuntimeException("Must be MAX_VALUE"); 584 } 585 } 586 587 @Test 588 @Arguments(Argument.MAX) charMax(char x)589 public void charMax(char x) { 590 executed[87]++; 591 if (x != Character.MAX_VALUE) { 592 throw new RuntimeException("Must be MAX_VALUE"); 593 } 594 } 595 596 @Test 597 @Arguments(Argument.MAX) shortMax(short x)598 public void shortMax(short x) { 599 executed[88]++; 600 if (x != Short.MAX_VALUE) { 601 throw new RuntimeException("Must be MAX_VALUE"); 602 } 603 } 604 605 @Test 606 @Arguments(Argument.MAX) intMax(int x)607 public void intMax(int x) { 608 executed[89]++; 609 if (x != Integer.MAX_VALUE) { 610 throw new RuntimeException("Must be MAX_VALUE"); 611 } 612 } 613 614 @Test 615 @Arguments(Argument.MAX) longMax(long x)616 public void longMax(long x) { 617 executed[90]++; 618 if (x != Long.MAX_VALUE) { 619 throw new RuntimeException("Must be MAX_VALUE"); 620 } 621 } 622 623 @Test 624 @Arguments(Argument.MAX) floatMax(float x)625 public void floatMax(float x) { 626 executed[91]++; 627 if (x != Float.MAX_VALUE) { 628 throw new RuntimeException("Must be MAX_VALUE"); 629 } 630 } 631 632 @Test 633 @Arguments(Argument.MAX) doubleMax(double x)634 public void doubleMax(double x) { 635 executed[78]++; 636 if (x != Double.MAX_VALUE) { 637 throw new RuntimeException("Must be MAX_VALUE"); 638 } 639 } 640 641 @Test 642 @Arguments({Argument.DEFAULT, Argument.DEFAULT}) twoArgsDefault1(byte x, short y)643 public void twoArgsDefault1(byte x, short y) { 644 executed[44]++; 645 if (x != 0 || y != 0) { 646 throw new RuntimeException("Both must be 0"); 647 } 648 } 649 650 @Test 651 @Arguments({Argument.DEFAULT, Argument.DEFAULT}) twoArgsDefault2(int x, short y)652 public void twoArgsDefault2(int x, short y) { 653 executed[45]++; 654 if (x != 0 || y != 0) { 655 throw new RuntimeException("Both must be 0"); 656 } 657 } 658 659 @Test 660 @Arguments({Argument.DEFAULT, Argument.DEFAULT}) twoArgsDefault3(short x, long y)661 public void twoArgsDefault3(short x, long y) { 662 executed[46]++; 663 if (x != 0 || y != 0) { 664 throw new RuntimeException("Both must be 0"); 665 } 666 } 667 668 @Test 669 @Arguments({Argument.DEFAULT, Argument.DEFAULT}) twoArgsDefault4(float x, boolean y)670 public void twoArgsDefault4(float x, boolean y) { 671 executed[47]++; 672 if (x != 0.0 || y) { 673 throw new RuntimeException("Must be 0 and false"); 674 } 675 } 676 677 @Test 678 @Arguments({Argument.DEFAULT, Argument.DEFAULT}) twoArgsDefault5(boolean x, char y)679 public void twoArgsDefault5(boolean x, char y) { 680 executed[48]++; 681 if (x || y != '\u0000') { 682 throw new RuntimeException("Must be false and \u0000"); 683 } 684 } 685 686 @Test 687 @Arguments({Argument.DEFAULT, Argument.DEFAULT}) twoArgsDefault6(char x, byte y)688 public void twoArgsDefault6(char x, byte y) { 689 executed[49]++; 690 if (x != '\u0000' || y != 0) { 691 throw new RuntimeException("Must be\u0000 and 0"); 692 } 693 } 694 695 @Test 696 @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) twoArgsRandomOnce(char x, byte y)697 public void twoArgsRandomOnce(char x, byte y) { 698 executed[50]++; 699 } 700 701 @Test 702 @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 703 Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 704 Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 705 Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) checkRandomOnceDifferentArgs(int a, int b, int c, int d, int e, int f, int g, int h)706 public void checkRandomOnceDifferentArgs(int a, int b, int c, int d, int e, int f, int g, int h) { 707 if (Stream.of(a, b, c, d, e, f, g, h).allMatch(i -> i == a)) { 708 throw new RuntimeException("RANDOM_ONCE does not produce random values for different arguments"); 709 } 710 executed[51]++; 711 } 712 713 @Test 714 @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 715 Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 716 Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 717 Argument.RANDOM_ONCE, Argument.RANDOM_ONCE}) checkMixedRandoms1(byte a, short b, int c, long d, char e, boolean f, float g, double h)718 public void checkMixedRandoms1(byte a, short b, int c, long d, char e, boolean f, float g, double h) { 719 executed[52]++; 720 } 721 722 @Test 723 @Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, 724 Argument.RANDOM_EACH, Argument.RANDOM_EACH, 725 Argument.RANDOM_EACH, Argument.RANDOM_EACH, 726 Argument.RANDOM_EACH, Argument.RANDOM_EACH}) checkMixedRandoms2(byte a, short b, int c, long d, char e, boolean f, float g, double h)727 public void checkMixedRandoms2(byte a, short b, int c, long d, char e, boolean f, float g, double h) { 728 executed[53]++; 729 } 730 731 @Test 732 @Arguments({Argument.RANDOM_ONCE, Argument.RANDOM_ONCE, 733 Argument.RANDOM_EACH, Argument.RANDOM_EACH, 734 Argument.RANDOM_ONCE, Argument.RANDOM_EACH, 735 Argument.RANDOM_EACH, Argument.RANDOM_ONCE}) checkMixedRandoms3(byte a, short b, int c, long d, char e, boolean f, float g, double h)736 public void checkMixedRandoms3(byte a, short b, int c, long d, char e, boolean f, float g, double h) { 737 executed[54]++; 738 } 739 740 @Test 741 @Arguments({Argument.NUMBER_42, Argument.NUMBER_42, 742 Argument.NUMBER_42, Argument.NUMBER_42, 743 Argument.NUMBER_42, Argument.NUMBER_42}) check42Mix1(byte a, short b, int c, long d, float e, double f)744 public void check42Mix1(byte a, short b, int c, long d, float e, double f) { 745 if (a != 42 || b != 42 || c != 42 || d != 42 || e != 42.0 || f != 42.0) { 746 throw new RuntimeException("Must all be 42"); 747 } 748 executed[55]++; 749 } 750 751 @Test 752 @Arguments({Argument.NUMBER_MINUS_42, Argument.NUMBER_MINUS_42, 753 Argument.NUMBER_MINUS_42, Argument.NUMBER_MINUS_42, 754 Argument.NUMBER_MINUS_42, Argument.NUMBER_MINUS_42}) check42Mix2(byte a, short b, int c, long d, float e, double f)755 public void check42Mix2(byte a, short b, int c, long d, float e, double f) { 756 if (a != -42 || b != -42 || c != -42 || d != -42 || e != -42.0 || f != -42.0) { 757 throw new RuntimeException("Must all be -42"); 758 } 759 executed[56]++; 760 } 761 762 @Test 763 @Arguments({Argument.NUMBER_MINUS_42, Argument.NUMBER_42, 764 Argument.NUMBER_MINUS_42, Argument.NUMBER_MINUS_42, 765 Argument.NUMBER_42, Argument.NUMBER_MINUS_42}) check42Mix3(byte a, short b, int c, long d, float e, double f)766 public void check42Mix3(byte a, short b, int c, long d, float e, double f) { 767 if (a != -42 || b != 42 || c != -42 || d != -42 || e != 42.0 || f != -42.0) { 768 throw new RuntimeException("Do not match the right 42 version"); 769 } 770 executed[57]++; 771 } 772 773 774 @Test 775 @Arguments(Argument.BOOLEAN_TOGGLE_FIRST_TRUE) booleanToggleFirstTrue(boolean x)776 public void booleanToggleFirstTrue(boolean x) { 777 if (executed[58] == 0) { 778 // First invocation 779 if (!x) { 780 throw new RuntimeException("BOOLEAN_TOGGLE_FIRST_FALSE must be false on first invocation"); 781 } 782 } else if (x == lastToggleBoolean) { 783 throw new RuntimeException("BOOLEAN_TOGGLE_FIRST_FALSE did not toggle"); 784 } 785 lastToggleBoolean = x; 786 executed[58]++; 787 } 788 789 @Test 790 @Arguments({Argument.BOOLEAN_TOGGLE_FIRST_FALSE, Argument.BOOLEAN_TOGGLE_FIRST_TRUE}) checkTwoToggles(boolean b1, boolean b2)791 public void checkTwoToggles(boolean b1, boolean b2) { 792 if (executed[59] == 0) { 793 // First invocation 794 if (b1 || !b2) { 795 throw new RuntimeException("BOOLEAN_TOGGLES have wrong initial value"); 796 } 797 } else if (b1 == b2) { 798 throw new RuntimeException("Boolean values must be different"); 799 } else if (b1 == lastToggleBoolean) { 800 throw new RuntimeException("Booleans did not toggle"); 801 } 802 lastToggleBoolean = b1; 803 executed[59]++; 804 } 805 806 @Test 807 @Arguments({Argument.BOOLEAN_TOGGLE_FIRST_FALSE, Argument.FALSE, 808 Argument.TRUE, Argument.BOOLEAN_TOGGLE_FIRST_TRUE}) booleanMix(boolean b1, boolean b2, boolean b3, boolean b4)809 public void booleanMix(boolean b1, boolean b2, boolean b3, boolean b4) { 810 if (executed[60] == 0) { 811 // First invocation 812 if (b1 || b2 || !b3 || !b4) { 813 throw new RuntimeException("BOOLEAN_TOGGLES have wrong initial value"); 814 } 815 } else if (b1 == b4) { 816 throw new RuntimeException("Boolean values must be different"); 817 } else if (b1 == lastToggleBoolean) { 818 throw new RuntimeException("Booleans did not toggle"); 819 } 820 lastToggleBoolean = b1; 821 executed[60]++; 822 } 823 824 /* 825 * Checked tests. 826 */ 827 828 @Test testCheck()829 public int testCheck() { 830 executed[63]++; 831 return 1; 832 } 833 834 // Checked test. Check invoked after invoking "testCheck". Perform some more things after invocation. 835 @Check(test = "testCheck") checkTestCheck()836 public void checkTestCheck() { 837 executed[64]++; // Executed on each invocation 838 } 839 840 @Test testCheckReturn()841 public int testCheckReturn() { 842 executed[65]++; 843 return 2; 844 } 845 846 // Checked test with return value. Perform checks on it. 847 @Check(test = "testCheckReturn") checkTestCheckReturn(int returnValue)848 public void checkTestCheckReturn(int returnValue) { 849 if (returnValue != 2) { 850 throw new RuntimeException("Must be 2"); 851 } 852 executed[66]++; // Executed on each invocation 853 } 854 855 @Test 856 @Arguments(Argument.NUMBER_42) testCheckWithArgs(short x)857 public short testCheckWithArgs(short x) { 858 executed[94]++; 859 return x; 860 } 861 862 @Check(test = "testCheckWithArgs") checkTestCheckWithArgs(short returnValue)863 public void checkTestCheckWithArgs(short returnValue) { 864 if (returnValue != 42) { 865 throw new RuntimeException("Must be 42"); 866 } 867 executed[95]++; // Executed on each invocation 868 } 869 870 @Test testCheckTestInfo()871 public int testCheckTestInfo() { 872 executed[67]++; 873 return 3; 874 } 875 876 // Checked test with info object about test. 877 @Check(test = "testCheckTestInfo") checkTestCheckTestInfo(TestInfo testInfo)878 public void checkTestCheckTestInfo(TestInfo testInfo) { 879 executed[68]++; // Executed on each invocation 880 } 881 882 883 @Test testCheckBoth()884 public int testCheckBoth() { 885 executed[69]++; 886 return 4; 887 } 888 889 // Checked test with return value and info object about test. 890 @Check(test = "testCheckBoth") checkTestCheckTestInfo(int returnValue, TestInfo testInfo)891 public void checkTestCheckTestInfo(int returnValue, TestInfo testInfo) { 892 if (returnValue != 4) { 893 throw new RuntimeException("Must be 4"); 894 } 895 executed[70]++; // Executed on each invocation 896 } 897 898 @Test testCheckOnce()899 public int testCheckOnce() { 900 executed[71]++; 901 return 1; 902 } 903 904 // Check method only invoked once after method is compiled after warm up. 905 @Check(test = "testCheckOnce", when = CheckAt.COMPILED) checkTestCheckOnce()906 public void checkTestCheckOnce() { 907 executedOnce[0]++; // Executed once 908 } 909 910 @Test testCheckReturnOnce()911 public int testCheckReturnOnce() { 912 executed[72]++; 913 return 2; 914 } 915 916 @Check(test = "testCheckReturnOnce", when = CheckAt.COMPILED) checkTestCheckReturnOnce(int returnValue)917 public void checkTestCheckReturnOnce(int returnValue) { 918 if (returnValue != 2) { 919 throw new RuntimeException("Must be 2"); 920 } 921 executedOnce[1]++; // Executed once 922 } 923 924 @Test testCheckTestInfoOnce()925 public int testCheckTestInfoOnce() { 926 executed[73]++; 927 return 3; 928 } 929 930 @Check(test = "testCheckTestInfoOnce", when = CheckAt.COMPILED) checkTestCheckTestInfoOnce(TestInfo testInfo)931 public void checkTestCheckTestInfoOnce(TestInfo testInfo) { 932 executedOnce[2]++; // Executed once 933 } 934 935 @Test testCheckBothOnce()936 public int testCheckBothOnce() { 937 executed[74]++; 938 return 4; 939 } 940 941 @Check(test = "testCheckBothOnce", when = CheckAt.COMPILED) checkTestCheckBothOnce(int returnValue, TestInfo testInfo)942 public void checkTestCheckBothOnce(int returnValue, TestInfo testInfo) { 943 if (returnValue != 4) { 944 throw new RuntimeException("Must be 4"); 945 } 946 executedOnce[3]++; // Executed once 947 } 948 949 @Test sameName()950 public void sameName() { 951 executed[76]++; 952 } 953 954 // Allowed to overload test method if not test method itself sameName(boolean a)955 public void sameName(boolean a) { 956 wasExecuted = true; 957 } 958 959 // Allowed to overload test method if not test method itself 960 @Check(test = "sameName") sameName(TestInfo info)961 public void sameName(TestInfo info) { 962 executed[77]++; 963 } 964 965 966 /* 967 * Custom run tests. 968 */ 969 970 @Test sameName2()971 public void sameName2() { 972 executed[92]++; 973 } 974 975 // Allowed to overload test method if not test method itself 976 @Run(test = "sameName2") sameName2(RunInfo info)977 public void sameName2(RunInfo info) { 978 executed[93]++; 979 sameName2(); 980 } 981 982 @Test testRun()983 public void testRun() { 984 executed[61]++; 985 } 986 987 // Custom run test. This method is invoked each time instead of @Test method. This method responsible for calling 988 // the @Test method. @Test method is compiled after warm up. This is similar to the verifiers in the old Valhalla framework. 989 @Run(test = "testRun") runTestRun(RunInfo info)990 public void runTestRun(RunInfo info) { 991 testRun(); 992 } 993 994 @Test testRunNoTestInfo(int i)995 public void testRunNoTestInfo(int i) { // Argument allowed when run by @Run 996 executed[62]++; 997 } 998 999 @Run(test = "testRunNoTestInfo") runTestRunNoTestInfo()1000 public void runTestRunNoTestInfo() { 1001 testRunNoTestInfo(3); 1002 } 1003 1004 @Test testNotRun()1005 public void testNotRun() { 1006 wasExecuted = true; 1007 } 1008 1009 @Run(test = "testNotRun") runTestNotRun()1010 public void runTestNotRun() { 1011 // Do not execute the test. Pointless but need to test that as well. 1012 } 1013 1014 @Test testRunOnce()1015 public void testRunOnce() { 1016 executedOnce[4]++; 1017 } 1018 1019 // Custom run test that is only invoked once. There is no warm up and no compilation. This method is responsible 1020 // for triggering compilation. 1021 @Run(test = "testRunOnce", mode = RunMode.STANDALONE) runTestRunOnce(RunInfo info)1022 public void runTestRunOnce(RunInfo info) { 1023 testRunOnce(); 1024 } 1025 1026 @Test testRunOnce2()1027 public void testRunOnce2() { 1028 executed[75]++; 1029 } 1030 1031 @Run(test = "testRunOnce2", mode = RunMode.STANDALONE) runTestRunOnce2(RunInfo info)1032 public void runTestRunOnce2(RunInfo info) { 1033 for (int i = 0; i < TestVM.WARMUP_ITERATIONS + 1; i++) { 1034 testRunOnce2(); 1035 } 1036 } 1037 1038 @Test testRunMultiple()1039 public void testRunMultiple() { 1040 executed[96]++; 1041 } 1042 1043 @Test testRunMultiple2()1044 public void testRunMultiple2() { 1045 executed[97]++; 1046 } 1047 1048 @Test testRunMultipleNotExecuted()1049 public void testRunMultipleNotExecuted() { 1050 wasExecuted = true; 1051 } 1052 1053 @Run(test = {"testRunMultiple", "testRunMultiple2", "testRunMultipleNotExecuted"}) runTestRunMultiple()1054 public void runTestRunMultiple() { 1055 testRunMultiple(); 1056 testRunMultiple2(); 1057 } 1058 1059 1060 @Test testRunMultiple3()1061 public void testRunMultiple3() { 1062 executed[98]++; 1063 } 1064 1065 @Test testRunMultiple4()1066 public void testRunMultiple4() { 1067 executed[99]++; 1068 } 1069 1070 @Test testRunMultipleNotExecuted2()1071 public void testRunMultipleNotExecuted2() { 1072 wasExecuted = true; 1073 } 1074 1075 @Run(test = {"testRunMultiple3", "testRunMultiple4", "testRunMultipleNotExecuted2"}, mode = RunMode.STANDALONE) runTestRunMultipl2(RunInfo info)1076 public void runTestRunMultipl2(RunInfo info) { 1077 for (int i = 0; i < TestVM.WARMUP_ITERATIONS + 1; i++) { 1078 testRunMultiple3(); 1079 testRunMultiple4(); 1080 } 1081 } 1082 } 1083 1084 class DefaultObject { 1085 int i = 4; 1086 } 1087