comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/examples/MathPow.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 5309cc9668e3
comparison
equal deleted inserted replaced
22240:f78c72e2e0b6 22241:14e6dfb1ef05
23 package com.oracle.truffle.api.dsl.test.examples; 23 package com.oracle.truffle.api.dsl.test.examples;
24 24
25 import com.oracle.truffle.api.CallTarget; 25 import com.oracle.truffle.api.CallTarget;
26 import com.oracle.truffle.api.dsl.Cached; 26 import com.oracle.truffle.api.dsl.Cached;
27 import com.oracle.truffle.api.dsl.Specialization; 27 import com.oracle.truffle.api.dsl.Specialization;
28
28 import static com.oracle.truffle.api.dsl.test.examples.ExampleNode.createArguments; 29 import static com.oracle.truffle.api.dsl.test.examples.ExampleNode.createArguments;
29 import static com.oracle.truffle.api.dsl.test.examples.ExampleNode.createTarget; 30 import static com.oracle.truffle.api.dsl.test.examples.ExampleNode.createTarget;
31
30 import com.oracle.truffle.api.dsl.test.examples.MathPowFactory.MathPowNodeGen; 32 import com.oracle.truffle.api.dsl.test.examples.MathPowFactory.MathPowNodeGen;
33 import com.oracle.truffle.api.dsl.test.utilities.InstrumentationTestMode;
31 import com.oracle.truffle.api.nodes.Node; 34 import com.oracle.truffle.api.nodes.Node;
35
32 import static org.junit.Assert.assertEquals; 36 import static org.junit.Assert.assertEquals;
37
38 import org.junit.After;
39 import org.junit.Before;
33 import org.junit.Test; 40 import org.junit.Test;
34 41
35 /** 42 /**
36 * This example shows possible specializations for a simplified math pow node. It demonstrates how 43 * This example shows possible specializations for a simplified math pow node. It demonstrates how
37 * multiple caches can coexist within in the same node. This example does not show the best possible 44 * multiple caches can coexist within in the same node. This example does not show the best possible
39 * 46 *
40 * Note: int values are implicitly casted to double values. 47 * Note: int values are implicitly casted to double values.
41 */ 48 */
42 @SuppressWarnings("unused") 49 @SuppressWarnings("unused")
43 public class MathPow extends Node { 50 public class MathPow extends Node {
51
52 @Before
53 public void before() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
54 InstrumentationTestMode.set(true);
55 }
56
57 @After
58 public void after() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
59 InstrumentationTestMode.set(false);
60 }
44 61
45 @Test 62 @Test
46 public void testPow() { 63 public void testPow() {
47 MathPowNode node = MathPowNodeGen.create(createArguments(2)); 64 MathPowNode node = MathPowNodeGen.create(createArguments(2));
48 CallTarget target = createTarget(node); 65 CallTarget target = createTarget(node);