Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NullTest.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 |
---|---|
18760
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
6fa3999631d8
Truffle-DSL: added test for null
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.createRoot; |
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 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
|
27 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
|
28 |
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.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
|
30 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
|
31 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
|
32 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
33 import com.oracle.truffle.api.dsl.Fallback; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
34 import com.oracle.truffle.api.dsl.NodeChild; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
35 import com.oracle.truffle.api.dsl.Specialization; |
18760
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.dsl.test.NullTestFactory.NullTest1Factory; |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
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
|
39 import com.oracle.truffle.api.dsl.test.utilities.InstrumentationTestMode; |
18760
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 public class NullTest { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
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
|
43 @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
|
44 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
|
45 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
|
46 } |
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 |
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 @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
|
49 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
|
50 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
|
51 } |
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
|
52 |
18760
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 @Test |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 public void testGuardInvocations() { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 TestRootNode<NullTest1> root = createRoot(NullTest1Factory.getInstance()); |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 assertEquals("fallback", executeWith(root, (Object) null)); |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 assertEquals(true, executeWith(root, true)); |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 assertEquals(42L, executeWith(root, 42)); |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 assertEquals("string", executeWith(root, "s")); |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 assertEquals("fallback", executeWith(root, (Object) null)); |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 } |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 @SuppressWarnings("unused") |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 @NodeChild("a") |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 abstract static class NullTest1 extends ValueNode { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 @Specialization |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 long s(long a) { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 return a; |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 } |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 @Specialization |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 boolean s(boolean a) { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 return a; |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 } |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 @Specialization |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 String s(String a) { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 return "string"; |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 } |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 @Fallback |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 Object s(Object a) { |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
85 return "fallback"; |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 } |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 } |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 |
6fa3999631d8
Truffle-DSL: added test for null
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 } |