Mercurial > hg > truffle
diff truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java @ 22223:964e789e17f7
Truffle/Tools; rewrite tests for simple counting tools, e.g. CoverageTracker
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sat, 19 Sep 2015 13:26:06 -0700 |
parents | 1c0f490984d5 |
children | 59e022cee529 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java Sat Sep 19 13:25:41 2015 -0700 +++ b/truffle/com.oracle.truffle.tools.test/src/com/oracle/truffle/tools/test/TruffleToolTest.java Sat Sep 19 13:26:06 2015 -0700 @@ -27,10 +27,13 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.lang.reflect.Field; + import org.junit.Test; import com.oracle.truffle.api.instrument.InstrumentationTool; import com.oracle.truffle.api.instrument.Instrumenter; +import com.oracle.truffle.api.vm.TruffleVM; /** * Test the basic life cycle properties shared by all instances of {@link InstrumentationTool}. @@ -39,7 +42,7 @@ @Test public void testEmptyLifeCycle() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = TestNodes.createInstrumenter(); + final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); assertFalse(tool.isEnabled()); tool.install(instrumenter); @@ -78,7 +81,7 @@ @Test(expected = IllegalStateException.class) public void testAlreadyInstalled() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = TestNodes.createInstrumenter(); + final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); tool.install(instrumenter); tool.install(instrumenter); @@ -86,7 +89,7 @@ @Test(expected = IllegalStateException.class) public void testAlreadyDisposed1() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = TestNodes.createInstrumenter(); + final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); tool.install(instrumenter); tool.dispose(); @@ -95,7 +98,7 @@ @Test(expected = IllegalStateException.class) public void testAlreadyDisposed2() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = TestNodes.createInstrumenter(); + final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); tool.install(instrumenter); tool.dispose(); @@ -104,7 +107,7 @@ @Test(expected = IllegalStateException.class) public void testAlreadyDisposed3() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = TestNodes.createInstrumenter(); + final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); tool.install(instrumenter); tool.dispose(); @@ -113,13 +116,21 @@ @Test(expected = IllegalStateException.class) public void testAlreadyDisposed4() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Instrumenter instrumenter = TestNodes.createInstrumenter(); + final Instrumenter instrumenter = getInstrumenter(); final DummyTruffleTool tool = new DummyTruffleTool(); tool.install(instrumenter); tool.dispose(); tool.dispose(); } + private static Instrumenter getInstrumenter() throws NoSuchFieldException, IllegalAccessException { + final TruffleVM vm = TruffleVM.newVM().build(); + final Field field = TruffleVM.class.getDeclaredField("instrumenter"); + field.setAccessible(true); + final Instrumenter instrumenter = (Instrumenter) field.get(vm); + return instrumenter; + } + private static final class DummyTruffleTool extends InstrumentationTool { @Override