Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/FallbackTest.java @ 16756:5148aab962af
Truffle-DSL: updated tests for the new generation layout.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:05 +0200 |
parents | |
children | 9f38d222fa6c |
comparison
equal
deleted
inserted
replaced
16755:bd28da642eea | 16756:5148aab962af |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2012, 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 package com.oracle.truffle.api.dsl.test; | |
24 | |
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; | |
26 | |
27 import org.junit.*; | |
28 | |
29 import com.oracle.truffle.api.dsl.*; | |
30 import com.oracle.truffle.api.dsl.test.FallbackTestFactory.Fallback1Factory; | |
31 import com.oracle.truffle.api.dsl.test.FallbackTestFactory.Fallback2Factory; | |
32 import com.oracle.truffle.api.dsl.test.FallbackTestFactory.Fallback3Factory; | |
33 import com.oracle.truffle.api.dsl.test.FallbackTestFactory.Fallback4Factory; | |
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.*; | |
35 import com.oracle.truffle.api.nodes.*; | |
36 | |
37 public class FallbackTest { | |
38 | |
39 private static final Object UNKNOWN_OBJECT = new Object() { | |
40 }; | |
41 | |
42 @Test | |
43 public void testFallback1() { | |
44 assertRuns(Fallback1Factory.getInstance(), // | |
45 array(42, UNKNOWN_OBJECT), // | |
46 array("(int)", "(fallback)")); | |
47 } | |
48 | |
49 /** | |
50 * test with fallback handler defined | |
51 */ | |
52 @SuppressWarnings("unused") | |
53 @NodeChild("a") | |
54 abstract static class Fallback1 extends ValueNode { | |
55 | |
56 @Specialization | |
57 String f1(int a) { | |
58 return "(int)"; | |
59 } | |
60 | |
61 @Generic | |
62 String f2(Object a) { | |
63 return "(fallback)"; | |
64 } | |
65 } | |
66 | |
67 @Test | |
68 public void testFallback2() { | |
69 assertRuns(Fallback2Factory.getInstance(), // | |
70 array(42, UNKNOWN_OBJECT), // | |
71 array("(int)", UnsupportedSpecializationException.class)); | |
72 } | |
73 | |
74 /** | |
75 * test without fallback handler defined | |
76 */ | |
77 @SuppressWarnings("unused") | |
78 @NodeChild("a") | |
79 abstract static class Fallback2 extends ValueNode { | |
80 | |
81 @Specialization | |
82 String f1(int a) { | |
83 return "(int)"; | |
84 } | |
85 | |
86 } | |
87 | |
88 @Test | |
89 public void testFallback3() { | |
90 assertRuns(Fallback3Factory.getInstance(), // | |
91 array(42, 43, UNKNOWN_OBJECT, "somestring"), // | |
92 array("(int)", "(int)", "(object)", "(object)")); | |
93 } | |
94 | |
95 /** | |
96 * test without fallback handler and unreachable | |
97 */ | |
98 @SuppressWarnings("unused") | |
99 @NodeChild("a") | |
100 abstract static class Fallback3 extends ValueNode { | |
101 | |
102 @Specialization | |
103 String f1(int a) { | |
104 return "(int)"; | |
105 } | |
106 | |
107 @Specialization(guards = "notInt") | |
108 String f2(Object a) { | |
109 return "(object)"; | |
110 } | |
111 | |
112 boolean notInt(Object value) { | |
113 return !(value instanceof Integer); | |
114 } | |
115 | |
116 } | |
117 | |
118 /** | |
119 * Tests the contents of the {@link UnsupportedSpecializationException} contents in polymorphic | |
120 * nodes. | |
121 */ | |
122 @Test | |
123 public void testFallback4() { | |
124 TestRootNode<Fallback4> node = createRoot(Fallback4Factory.getInstance()); | |
125 | |
126 Assert.assertEquals("(int)", executeWith(node, 1)); | |
127 Assert.assertEquals("(boolean)", executeWith(node, true)); | |
128 try { | |
129 executeWith(node, UNKNOWN_OBJECT); | |
130 Assert.fail(); | |
131 } catch (UnsupportedSpecializationException e) { | |
132 Assert.assertEquals(node.getNode(), e.getNode()); | |
133 Assert.assertArrayEquals(NodeUtil.findNodeChildren(node.getNode()).subList(0, 1).toArray(new Node[0]), e.getSuppliedNodes()); | |
134 Assert.assertArrayEquals(new Object[]{UNKNOWN_OBJECT}, e.getSuppliedValues()); | |
135 } | |
136 } | |
137 | |
138 /** | |
139 * test without fallback handler and unreachable | |
140 */ | |
141 @SuppressWarnings("unused") | |
142 @NodeChild("a") | |
143 abstract static class Fallback4 extends ValueNode { | |
144 | |
145 @Specialization | |
146 String f1(int a) { | |
147 return "(int)"; | |
148 } | |
149 | |
150 @Specialization | |
151 String f2(boolean a) { | |
152 return "(boolean)"; | |
153 } | |
154 } | |
155 | |
156 /** | |
157 * Tests the contents of the {@link UnsupportedSpecializationException} contents in monomorphic | |
158 * nodes. | |
159 */ | |
160 @Test | |
161 public void testFallback5() { | |
162 TestRootNode<Fallback4> node = createRoot(Fallback4Factory.getInstance()); | |
163 | |
164 Assert.assertEquals("(int)", executeWith(node, 1)); | |
165 try { | |
166 executeWith(node, UNKNOWN_OBJECT); | |
167 Assert.fail(); | |
168 } catch (UnsupportedSpecializationException e) { | |
169 Assert.assertEquals(node.getNode(), e.getNode()); | |
170 Assert.assertArrayEquals(NodeUtil.findNodeChildren(node.getNode()).subList(0, 1).toArray(new Node[0]), e.getSuppliedNodes()); | |
171 Assert.assertArrayEquals(new Object[]{UNKNOWN_OBJECT}, e.getSuppliedValues()); | |
172 } | |
173 } | |
174 | |
175 // test without fallback handler and unreachable | |
176 @SuppressWarnings("unused") | |
177 @NodeChild("a") | |
178 abstract static class Fallback5 extends ValueNode { | |
179 | |
180 @Specialization | |
181 String f1(int a) { | |
182 return "(int)"; | |
183 } | |
184 } | |
185 | |
186 } |