Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/EvalInstrumentTest.java @ 22352:7d9b7365b675
Adding Map<String,Object> parameter to the attach(Eval*Listener) method to allow passing parameter values that the evaluated Source can reference.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 04 Nov 2015 16:54:36 +0100 |
parents | 906a5f6e07cc |
children |
comparison
equal
deleted
inserted
replaced
22335:906a5f6e07cc | 22352:7d9b7365b675 |
---|---|
97 assertNotNull("Add node should be probed", addNodeProbe[0]); | 97 assertNotNull("Add node should be probed", addNodeProbe[0]); |
98 | 98 |
99 final Source source42 = InstrumentationTestingLanguage.createConstantSource42("testEvalInstrumentListener"); | 99 final Source source42 = InstrumentationTestingLanguage.createConstantSource42("testEvalInstrumentListener"); |
100 final int[] evalResult = {0}; | 100 final int[] evalResult = {0}; |
101 final int[] evalCount = {0}; | 101 final int[] evalCount = {0}; |
102 final Instrument instrument = instrumenter.attach(addNodeProbe[0], InstrumentationTestingLanguage.class, source42, new EvalInstrumentListener() { | 102 final Instrument instrument = instrumenter.attach(addNodeProbe[0], source42, new EvalInstrumentListener() { |
103 | 103 |
104 public void onExecution(Node node, VirtualFrame vFrame, Object result) { | 104 public void onExecution(Node node, VirtualFrame vFrame, Object result) { |
105 evalCount[0] = evalCount[0] + 1; | 105 evalCount[0] = evalCount[0] + 1; |
106 if (result instanceof Integer) { | 106 if (result instanceof Integer) { |
107 evalResult[0] = (Integer) result; | 107 evalResult[0] = (Integer) result; |
110 | 110 |
111 public void onFailure(Node node, VirtualFrame vFrame, Exception ex) { | 111 public void onFailure(Node node, VirtualFrame vFrame, Exception ex) { |
112 fail("Eval test evaluates without exception"); | 112 fail("Eval test evaluates without exception"); |
113 | 113 |
114 } | 114 } |
115 }, "test EvalInstrument"); | 115 }, "test EvalInstrument", null); |
116 | 116 |
117 assertEquals(vm.eval(source13).get(), 13); | 117 assertEquals(vm.eval(source13).get(), 13); |
118 assertEquals(evalCount[0], 1); | 118 assertEquals(evalCount[0], 1); |
119 assertEquals(evalResult[0], 42); | 119 assertEquals(evalResult[0], 42); |
120 | 120 |
122 assertEquals(vm.eval(source13).get(), 13); | 122 assertEquals(vm.eval(source13).get(), 13); |
123 assertEquals(evalCount[0], 2); | 123 assertEquals(evalCount[0], 2); |
124 assertEquals(evalResult[0], 42); | 124 assertEquals(evalResult[0], 42); |
125 | 125 |
126 // Add new eval instrument with no listener, no effect on third execution | 126 // Add new eval instrument with no listener, no effect on third execution |
127 instrumenter.attach(addNodeProbe[0], InstrumentationTestingLanguage.class, source42, null, ""); | 127 instrumenter.attach(addNodeProbe[0], source42, null, "", null); |
128 assertEquals(vm.eval(source13).get(), 13); | 128 assertEquals(vm.eval(source13).get(), 13); |
129 assertEquals(evalCount[0], 3); | 129 assertEquals(evalCount[0], 3); |
130 assertEquals(evalResult[0], 42); | 130 assertEquals(evalResult[0], 42); |
131 | 131 |
132 // Remove original instrument; no further effect from fourth execution | 132 // Remove original instrument; no further effect from fourth execution |