Mercurial > hg > truffle
diff truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/AdvancedInstrumentTest.java @ 22220:20380d1d41f2
Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
- deprecate Node.isInstrumentable() and Node.createWrapperNode(), now Instrumenter methods
- Instrumenter uses new Accessor methods to delegate implementation to TruffleLanguage implementations
- rework many instrumentation-related tests
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Thu, 17 Sep 2015 21:23:57 -0700 |
parents | 1c0f490984d5 |
children | 69156ed8192b |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/AdvancedInstrumentTest.java Wed Sep 16 15:36:22 2015 -0700 +++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/AdvancedInstrumentTest.java Thu Sep 17 21:23:57 2015 -0700 @@ -22,23 +22,27 @@ */ package com.oracle.truffle.api.test.instrument; +import static com.oracle.truffle.api.test.instrument.InstrumentationTestingLanguage.ADD_TAG; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.lang.reflect.Field; import org.junit.Test; -import com.oracle.truffle.api.CallTarget; -import com.oracle.truffle.api.Truffle; -import com.oracle.truffle.api.TruffleRuntime; import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot; import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; import com.oracle.truffle.api.instrument.Instrument; import com.oracle.truffle.api.instrument.Instrumenter; import com.oracle.truffle.api.instrument.Probe; +import com.oracle.truffle.api.instrument.ProbeListener; +import com.oracle.truffle.api.instrument.SyntaxTag; import com.oracle.truffle.api.nodes.Node; -import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdditionNode; +import com.oracle.truffle.api.source.Source; import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestAdvancedInstrumentCounterRoot; -import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestRootNode; -import com.oracle.truffle.api.test.instrument.InstrumentationTestNodes.TestValueNode; +import com.oracle.truffle.api.vm.TruffleVM; /** * Tests the kind of instrumentation where a client can provide an AST fragment to be @@ -47,24 +51,36 @@ public class AdvancedInstrumentTest { @Test - public void testAdvancedInstrumentListener() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = InstrumentationTestNodes.createInstrumenter(); + public void testAdvancedInstrumentListener() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, IOException { + + final TruffleVM vm = TruffleVM.newVM().build(); + final Field field = TruffleVM.class.getDeclaredField("instrumenter"); + field.setAccessible(true); + final Instrumenter instrumenter = (Instrumenter) field.get(vm); + final Source source = Source.fromText("testAdvancedInstrumentListener text", "testAdvancedInstrumentListener").withMimeType("text/x-instTest"); + + final Probe[] addNodeProbe = new Probe[1]; + instrumenter.addProbeListener(new ProbeListener() { + + public void startASTProbing(Source s) { + } - // Create a simple addition AST - final TruffleRuntime runtime = Truffle.getRuntime(); - final TestValueNode leftValueNode = new TestValueNode(6); - final TestValueNode rightValueNode = new TestValueNode(7); - final TestAdditionNode addNode = new TestAdditionNode(leftValueNode, rightValueNode); - final TestRootNode rootNode = new TestRootNode(addNode, instrumenter); - final CallTarget callTarget1 = runtime.createCallTarget(rootNode); + public void newProbeInserted(Probe p) { + } - // Ensure it executes correctly - assertEquals(13, callTarget1.call()); + public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) { + if (tag == ADD_TAG) { + assertNull("only one add node", addNodeProbe[0]); + addNodeProbe[0] = probe; + } + } - // Probe the addition node - final Probe probe = instrumenter.probe(addNode); + public void endASTProbing(Source s) { + } - assertEquals(13, callTarget1.call()); + }); + assertEquals(vm.eval(source).get(), 13); + assertNotNull("Add node should be probed", addNodeProbe[0]); // Attach a null factory; it never actually attaches a node. final Instrument instrument = Instrument.create(null, new AdvancedInstrumentRootFactory() { @@ -73,23 +89,21 @@ return null; } }, null, "test AdvancedInstrument"); - probe.attach(instrument); + addNodeProbe[0].attach(instrument); - assertEquals(13, callTarget1.call()); + assertEquals(vm.eval(source).get(), 13); final TestAdvancedInstrumentCounterRoot counter = new TestAdvancedInstrumentCounterRoot(); // Attach a factory that splices an execution counter into the AST. - probe.attach(Instrument.create(null, new AdvancedInstrumentRootFactory() { + addNodeProbe[0].attach(Instrument.create(null, new AdvancedInstrumentRootFactory() { public AdvancedInstrumentRoot createInstrumentRoot(Probe p, Node n) { return counter; } }, null, "test AdvancedInstrument")); assertEquals(0, counter.getCount()); - - assertEquals(13, callTarget1.call()); - + assertEquals(vm.eval(source).get(), 13); assertEquals(1, counter.getCount()); } }