|
| 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.driver.IRViolationException; |
| 28 | +import compiler.lib.ir_framework.driver.TestVMException; |
| 29 | +import jdk.test.lib.Asserts; |
| 30 | + |
| 31 | +/* |
| 32 | + * @test |
| 33 | + * @bug 8273410 |
| 34 | + * @requires vm.debug == true & vm.compMode != "Xint" & vm.compiler2.enabled & vm.flagless |
| 35 | + * @summary Test different custom run tests. |
| 36 | + * @library /test/lib /testlibrary_tests / |
| 37 | + * @run driver ir_framework.tests.TestCheckedTests |
| 38 | + */ |
| 39 | + |
| 40 | +public class TestCheckedTests { |
| 41 | + public int iFld; |
| 42 | + |
| 43 | + public static void main(String[] args) { |
| 44 | + TestFramework.run(); |
| 45 | + try { |
| 46 | + TestFramework.run(BadIRAndRuntimeCheckedTests.class); |
| 47 | + Utils.shouldHaveThrownException(); |
| 48 | + } catch (TestVMException e) { |
| 49 | + Asserts.assertTrue(e.getExceptionInfo().contains("Test Failures (2)")); |
| 50 | + Asserts.assertTrue(e.getExceptionInfo().contains("checkTestBad3")); |
| 51 | + Asserts.assertTrue(e.getExceptionInfo().contains("checkTestBad5")); |
| 52 | + Asserts.assertTrue(e.getExceptionInfo().split("BadCheckedTestException").length == 3); |
| 53 | + Asserts.assertFalse(e.getExceptionInfo().contains("Failed IR Rules")); |
| 54 | + } |
| 55 | + |
| 56 | + try { |
| 57 | + TestFramework.run(BadIRCheckedTests.class); |
| 58 | + Utils.shouldHaveThrownException(); |
| 59 | + } catch (IRViolationException e) { |
| 60 | + Asserts.assertTrue(e.getExceptionInfo().contains("Failed IR Rules (3)")); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + @IR(counts = {IRNode.STORE_I, "1"}) |
| 66 | + public void testGood1() { |
| 67 | + iFld = 3; |
| 68 | + } |
| 69 | + |
| 70 | + @Check(test = "testGood1") |
| 71 | + public void checkTestGood1(TestInfo info) { |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @IR(failOn = IRNode.LOAD) |
| 76 | + public int testGood2() { |
| 77 | + iFld = 3; |
| 78 | + return 3; |
| 79 | + } |
| 80 | + |
| 81 | + @Check(test = "testGood2") |
| 82 | + public void sameName(int retValue) { |
| 83 | + if (retValue != 3) { |
| 84 | + throw new RuntimeException("must be 3 but was " + retValue); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + @Arguments(Argument.NUMBER_42) |
| 90 | + @IR(failOn = IRNode.LOAD) |
| 91 | + @IR(counts = {IRNode.STORE_I, "0"}) |
| 92 | + public int testGood3(int x) { |
| 93 | + return x; |
| 94 | + } |
| 95 | + |
| 96 | + @Check(test = "testGood3") |
| 97 | + public void sameName(int retValue, TestInfo info) { |
| 98 | + if (retValue != 42) { |
| 99 | + throw new RuntimeException("must be 42"); |
| 100 | + } |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +class BadIRAndRuntimeCheckedTests { |
| 105 | + public int iFld; |
| 106 | + |
| 107 | + @Test |
| 108 | + @IR(counts = {IRNode.STORE_I, "2"}) |
| 109 | + public void testBad1() { |
| 110 | + iFld = 3; |
| 111 | + } |
| 112 | + |
| 113 | + @Check(test = "testBad1") |
| 114 | + public void checkTestBad1(TestInfo info) { |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + @IR(failOn = IRNode.STORE_I) |
| 119 | + public int testBad2() { |
| 120 | + iFld = 3; |
| 121 | + return 3; |
| 122 | + } |
| 123 | + |
| 124 | + @Check(test = "testBad2") |
| 125 | + public void sameName(int retValue) { |
| 126 | + if (retValue != 3) { |
| 127 | + throw new RuntimeException("must be 3"); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + @Arguments(Argument.NUMBER_42) |
| 133 | + public int testBad3(int x) { |
| 134 | + return x; |
| 135 | + } |
| 136 | + |
| 137 | + @Check(test = "testBad3") |
| 138 | + public void checkTestBad3(int retValue) { |
| 139 | + if (retValue == 42) { |
| 140 | + // Always |
| 141 | + throw new BadCheckedTestException("expected"); |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + @Arguments(Argument.NUMBER_42) |
| 147 | + @IR(failOn = IRNode.LOAD) |
| 148 | + @IR(counts = {IRNode.STORE_I, "1"}) |
| 149 | + public int testBad4(int x) { |
| 150 | + return x; |
| 151 | + } |
| 152 | + |
| 153 | + @Check(test = "testBad4") |
| 154 | + public void sameName(int retValue, TestInfo info) { |
| 155 | + if (retValue != 42) { |
| 156 | + throw new RuntimeException("must be 42"); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + @Arguments(Argument.NUMBER_42) |
| 162 | + public int testBad5(int x) { |
| 163 | + return x; |
| 164 | + } |
| 165 | + |
| 166 | + @Check(test = "testBad5") |
| 167 | + public void checkTestBad5(int retValue) { |
| 168 | + if (retValue == 42) { |
| 169 | + // Always |
| 170 | + throw new BadCheckedTestException("expected"); |
| 171 | + } |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +class BadIRCheckedTests { |
| 176 | + public int iFld; |
| 177 | + |
| 178 | + @Test |
| 179 | + @IR(counts = {IRNode.STORE_I, "2"}) |
| 180 | + public void testBad1() { |
| 181 | + iFld = 3; |
| 182 | + } |
| 183 | + |
| 184 | + @Check(test = "testBad1") |
| 185 | + public void checkTestBad1(TestInfo info) { |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + @IR(failOn = IRNode.STORE_I) |
| 190 | + public int testBad2() { |
| 191 | + iFld = 3; |
| 192 | + return 3; |
| 193 | + } |
| 194 | + |
| 195 | + @Check(test = "testBad2") |
| 196 | + public void sameName(int retValue) { |
| 197 | + if (retValue != 3) { |
| 198 | + throw new RuntimeException("must be 3"); |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + @Test |
| 203 | + @Arguments(Argument.NUMBER_42) |
| 204 | + @IR(failOn = IRNode.LOAD) |
| 205 | + @IR(counts = {IRNode.STORE_I, "1"}) |
| 206 | + public int testBad4(int x) { |
| 207 | + return x; |
| 208 | + } |
| 209 | + |
| 210 | + @Check(test = "testBad4") |
| 211 | + public void sameName(int retValue, TestInfo info) { |
| 212 | + if (retValue != 42) { |
| 213 | + throw new RuntimeException("must be 42"); |
| 214 | + } |
| 215 | + } |
| 216 | +} |
| 217 | + |
| 218 | +class BadCheckedTestException extends RuntimeException { |
| 219 | + BadCheckedTestException(String s) { |
| 220 | + super(s); |
| 221 | + } |
| 222 | +} |
0 commit comments