Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest2.java @ 22241:14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
- Caused by lack of a "vm" known to the Accessor during most testing, making the Instrumenter unavailable, which is now required to create a CallTarget
- Modified the Instrumenter/Accessor with a static field that can be reflectively "poked" with a vm value for testing
- Create a pair of methods to globally enable/disable testing mode to modify that static field and restore it when tests complete.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 22 Sep 2015 20:31:19 -0700 |
parents | dc83cc1f94f2 |
children | 0d36601f233e |
rev | line source |
---|---|
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.executeWith; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
26 import static org.junit.Assert.assertEquals; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
27 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
28 import org.junit.After; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
29 import org.junit.Before; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
30 import org.junit.Test; |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
31 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
32 import com.oracle.truffle.api.dsl.Specialization; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode; |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
34 import com.oracle.truffle.api.dsl.test.PolymorphicTest2Factory.Polymorphic1Factory; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
36 import com.oracle.truffle.api.dsl.test.utilities.InstrumentationTestMode; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
37 import com.oracle.truffle.api.nodes.NodeCost; |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public class PolymorphicTest2 { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
22241
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
41 @Before |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
42 public void before() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
43 InstrumentationTestMode.set(true); |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
44 } |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
45 |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
46 @After |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
47 public void after() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
48 InstrumentationTestMode.set(false); |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
49 } |
14e6dfb1ef05
Truffle/Testing: massive rework of tests to accommodate recent instrumentation change with respect to "applyInstrumentation"
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
50 |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 @Test |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 public void testMultipleTypes() { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 /* Tests the unexpected polymorphic case. */ |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
54 TestRootNode<Polymorphic1> node = TestHelper.createRoot(Polymorphic1Factory.getInstance()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 assertEquals(21, executeWith(node, false, false)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 assertEquals(42, executeWith(node, 21, 21)); |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 assertEquals("(boolean,int)", executeWith(node, false, 42)); |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
58 assertEquals(NodeCost.POLYMORPHIC, node.getNode().getCost()); |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 @SuppressWarnings("unused") |
16756
5148aab962af
Truffle-DSL: updated tests for the new generation layout.
Christian Humer <christian.humer@gmail.com>
parents:
14641
diff
changeset
|
62 abstract static class Polymorphic1 extends BinaryNode { |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
64 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 int add(int left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 return 42; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
69 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 int add(boolean left, boolean right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 return 21; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
16756
diff
changeset
|
74 @Specialization |
10743
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 String add(boolean left, int right) { |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 return "(boolean,int)"; |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 } |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 |
ff6eb563a2e2
Truffle-DSL: Added additional test case for polymporphic generation.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 } |