|
| 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 compiler.lib.ir_framework; |
| 25 | + |
| 26 | +import compiler.lib.ir_framework.shared.TestFormatException; |
| 27 | + |
| 28 | +import java.lang.annotation.Retention; |
| 29 | +import java.lang.annotation.RetentionPolicy; |
| 30 | + |
| 31 | +/** |
| 32 | + * Annotation for a check method of a <b>checked test</b>. |
| 33 | + * |
| 34 | + * <p> |
| 35 | + * Let {@code t} be a test method specifying the {@link Test @Test} annotation and {@code c} be a check method specifying |
| 36 | + * the {@code @Check(test = "t")} annotation. These two methods represent a so-called <i>checked test</i>. The only |
| 37 | + * difference to a <i>base test</i> (see {@link Test}) is that the framework will invoke the check method {@code c} |
| 38 | + * directly after the invocation of the test method {@code t} which allows to do some additional verification, |
| 39 | + * including the return value of {@code t}. The framework does the following, similar as for <i>base tests</i>: |
| 40 | + * <ol> |
| 41 | + * <li><p>The framework warms {@code t} up by invoking it for a predefined number of iterations (default: 2000) |
| 42 | + * or any number specified by an additional {@link Warmup @Warmup} annotation at {@code t} or by using |
| 43 | + * {@link TestFramework#setDefaultWarmup(int)} (could also be 0 which skips the warm-up completely which is |
| 44 | + * similar to simulating {@code -Xcomp}). After each invocation of {@code t}, the framework also invokes |
| 45 | + * {@code c} if the {@code @Check} annotation specifies {@link CheckAt#EACH_INVOCATION} at {@link #when()}. |
| 46 | + * More information about the warm-up in general can be found at {@link Warmup}</li> |
| 47 | + * <li><p>After the warm-up, the framework compiles {@code t} at the specified compilation level set by |
| 48 | + * {@link Test#compLevel()} (default {@link CompLevel#ANY} will pick the highest available level which is |
| 49 | + * usually {@link CompLevel#C2}).</li> |
| 50 | + * <li><p>The framework invokes {@code t} one more time to run the compilation. Afterwards, the framework will |
| 51 | + * always invoke {@code c} again to be able perform additional checks after the compilation of {@code t}.</li> |
| 52 | + * <li><p>The framework checks any specified {@link IR @IR} constraints at the test method {@code t}. |
| 53 | + * More information about IR matching can be found at {@link IR}.</li> |
| 54 | + * </ol> |
| 55 | + * |
| 56 | + * <p> |
| 57 | + * The test method {@code t} has the same properties and follows the same constraints as stated in {@link Test}. |
| 58 | + * <p> |
| 59 | + * The following additional constraints must be met for the test method {@code t} and check method {@code c}: |
| 60 | + * <ul> |
| 61 | + * <li><p>{@code c} must specify the method name {@code t} as property in {@code @Check(test = "t")} |
| 62 | + * (see {@link #test()}. Specifying a non-{@code @Test} annotated method or a {@code @Test} method that |
| 63 | + * has already been used by another {@code @Check} or {@link Run @Run} method results in a {@link TestFormatException}. |
| 64 | + * <li><p>{@code c} can specify the following method parameter combinations: |
| 65 | + * <ul> |
| 66 | + * <li><p>void</li> |
| 67 | + * <li><p>One parameter: {@link TestInfo} which provides some information about {@code t} and utility methods.</li> |
| 68 | + * <li><p>One parameter: the <i>exact</i> same type as the return value of {@code t}. When {@code c} is |
| 69 | + * invoked by the framework, this parameter contains the return value of {@code t}.</li> |
| 70 | + * <li><p>1st parameter: {@link TestInfo}; 2nd parameter: the <i>exact</i> same type as the return value of |
| 71 | + * {@code t} (see above)</li> |
| 72 | + * <li><p> Any other combination will result in a {@link TestFormatException}. |
| 73 | + * </ul> |
| 74 | + * <li><p>{@code c} is not compiled nor inlined. |
| 75 | + * <li><p>{@code c} must be part of the test class. Using {@code @Check} in nested or other classes is not allowed.</li> |
| 76 | + * <li><p>{@code c} cannot specify any helper-method-specific compile command annotations |
| 77 | + * ({@link ForceCompile @ForceCompile}, {@link DontCompile @DontCompile}, {@link ForceInline @ForceInline}, |
| 78 | + * {@link DontInline @DontInline}).</li> |
| 79 | + * </ul> |
| 80 | + * |
| 81 | + * <p> |
| 82 | + * If no verification is required, use a <i>base test</i> (see {@link Test}). If {@code t} must be invoked with more |
| 83 | + * complex or varying arguments and/or the {@code t} must be invoked differently in subsequent invocations, use a |
| 84 | + * <i>custom run test</i> (see {@link Run}). |
| 85 | + * |
| 86 | + * <p> |
| 87 | + * Examples on how to write checked tests can be found in {@link jdk.test.lib.hotspot.ir_framework.examples.CheckedTestExample} |
| 88 | + * and also as part of the internal testing in the package {@link jdk.test.lib.hotspot.ir_framework.tests}. |
| 89 | + * |
| 90 | + * @see Test |
| 91 | + * @see TestInfo |
| 92 | + * @see CheckAt |
| 93 | + */ |
| 94 | +@Retention(RetentionPolicy.RUNTIME) |
| 95 | +public @interface Check { |
| 96 | + /** |
| 97 | + * The unique associated {@link Test} method for this {@code @Check} annotated check method. The framework will directly |
| 98 | + * invoke the {@code @Check} method after each invocation or only after the compilation of the associated {@code @Test} |
| 99 | + * method (depending on the value set with {@link #when()}). |
| 100 | + * <p> |
| 101 | + * If a non-{@code @Test} annotated method or a {@code @Test} method that has already been used by another |
| 102 | + * {@code @Check} or {@link Run} method is specified, then a {@link TestFormatException} is thrown. |
| 103 | + * |
| 104 | + * @see Test |
| 105 | + */ |
| 106 | + String test(); |
| 107 | + /** |
| 108 | + * When should the {@code @Check} method be invoked? By default, the check is done after each invocation which is |
| 109 | + * encouraged if performance is not critical. |
| 110 | + * |
| 111 | + * @see CheckAt |
| 112 | + */ |
| 113 | + CheckAt when() default CheckAt.EACH_INVOCATION; |
| 114 | +} |
0 commit comments