comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTest.java @ 20885:e7ece52e1ff3

Truffle/Instrumentation: remove two helper classes not adding enough value.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Fri, 10 Apr 2015 16:55:38 -0700
parents 2e3cc2a27711
children 73b1844b5b14
comparison
equal deleted inserted replaced
20173:c6ba61a3d05a 20885:e7ece52e1ff3
155 assertEquals(e.getFailure().getReason(), Reason.WRAPPER_NODE); 155 assertEquals(e.getFailure().getReason(), Reason.WRAPPER_NODE);
156 } 156 }
157 157
158 // Check that the "probed" AST still executes correctly 158 // Check that the "probed" AST still executes correctly
159 assertEquals(13, callTarget1.call()); 159 assertEquals(13, callTarget1.call());
160
161 } 160 }
162 161
163 @Test 162 @Test
164 public void testListeners() { 163 public void testListeners() {
165 164
180 // They should all be removed when the check is finished. 179 // They should all be removed when the check is finished.
181 checkCounters(probe, callTarget, rootNode, new TestInstrumentCounter(), new TestInstrumentCounter(), new TestInstrumentCounter()); 180 checkCounters(probe, callTarget, rootNode, new TestInstrumentCounter(), new TestInstrumentCounter(), new TestInstrumentCounter());
182 181
183 // Now try with the more complex flavor of listener 182 // Now try with the more complex flavor of listener
184 checkCounters(probe, callTarget, rootNode, new TestASTInstrumentCounter(), new TestASTInstrumentCounter(), new TestASTInstrumentCounter()); 183 checkCounters(probe, callTarget, rootNode, new TestASTInstrumentCounter(), new TestASTInstrumentCounter(), new TestASTInstrumentCounter());
185
186 } 184 }
187 185
188 private static void checkCounters(Probe probe, CallTarget callTarget, RootNode rootNode, TestCounter counterA, TestCounter counterB, TestCounter counterC) { 186 private static void checkCounters(Probe probe, CallTarget callTarget, RootNode rootNode, TestCounter counterA, TestCounter counterB, TestCounter counterC) {
189 187
190 // Attach a counting instrument to the probe 188 // Attach a counting instrument to the probe
278 assertEquals(counterA.leaveCount(), 1); 276 assertEquals(counterA.leaveCount(), 1);
279 assertEquals(counterB.enterCount(), 8); 277 assertEquals(counterB.enterCount(), 8);
280 assertEquals(counterB.leaveCount(), 8); 278 assertEquals(counterB.leaveCount(), 8);
281 assertEquals(counterC.enterCount(), 2); 279 assertEquals(counterC.enterCount(), 2);
282 assertEquals(counterC.leaveCount(), 2); 280 assertEquals(counterC.leaveCount(), 2);
283
284 } 281 }
285 282
286 @Test 283 @Test
287 public void testTagging() { 284 public void testTagging() {
288
289 // Applies appropriate tags 285 // Applies appropriate tags
290 final TestASTProber astProber = new TestASTProber(); 286 final TestASTProber astProber = new TestASTProber();
291 Probe.registerASTProber(astProber); 287 Probe.registerASTProber(astProber);
292 288
293 // Listens for probes and tags being added 289 // Listens for probes and tags being added
339 // There are two value nodes in the AST, but only one addition node 335 // There are two value nodes in the AST, but only one addition node
340 assertEquals(additionCounter.count, 1); 336 assertEquals(additionCounter.count, 1);
341 assertEquals(valueCounter.count, 2); 337 assertEquals(valueCounter.count, 2);
342 338
343 Probe.unregisterASTProber(astProber); 339 Probe.unregisterASTProber(astProber);
344
345 } 340 }
346 341
347 private interface TestCounter { 342 private interface TestCounter {
348 343
349 int enterCount(); 344 int enterCount();
351 int leaveCount(); 346 int leaveCount();
352 347
353 void attach(Probe probe); 348 void attach(Probe probe);
354 349
355 void dispose(); 350 void dispose();
356
357 } 351 }
358 352
359 /** 353 /**
360 * A counter for the number of times execution enters and leaves a probed AST node, using the 354 * A counter for the number of times execution enters and leaves a probed AST node.
361 * simplest kind of listener.
362 */ 355 */
363 private class TestInstrumentCounter implements TestCounter { 356 private class TestInstrumentCounter implements TestCounter {
364 357
365 public int enterCount = 0; 358 public int enterCount = 0;
366 public int leaveCount = 0; 359 public int leaveCount = 0;
367 public final Instrument instrument; 360 public final Instrument instrument;
368 361
369 public TestInstrumentCounter() { 362 public TestInstrumentCounter() {
370 this.instrument = Instrument.create(new SimpleInstrumentListener() { 363 this.instrument = Instrument.create(new InstrumentListener() {
371 364
372 @Override
373 public void enter(Probe probe) { 365 public void enter(Probe probe) {
374 enterCount++; 366 enterCount++;
375 } 367 }
376 368
377 @Override 369 public void returnVoid(Probe probe) {
378 public void returnAny(Probe probe) {
379 leaveCount++; 370 leaveCount++;
380 } 371 }
381 372
373 public void returnValue(Probe probe, Object result) {
374 leaveCount++;
375 }
376
377 public void returnExceptional(Probe probe, Exception exception) {
378 leaveCount++;
379 }
380
382 }, "Instrumentation Test Counter"); 381 }, "Instrumentation Test Counter");
383 382 }
384 } 383
385 384 @Override
386 public int enterCount() { 385 public int enterCount() {
387 return enterCount; 386 return enterCount;
388 } 387 }
389 388
389 @Override
390 public int leaveCount() { 390 public int leaveCount() {
391 return leaveCount; 391 return leaveCount;
392 } 392 }
393 393
394 @Override
394 public void attach(Probe probe) { 395 public void attach(Probe probe) {
395 probe.attach(instrument); 396 probe.attach(instrument);
396 } 397 }
397 398
399 @Override
398 public void dispose() { 400 public void dispose() {
399 instrument.dispose(); 401 instrument.dispose();
400 } 402 }
401 } 403 }
402 404
403 /** 405 /**
404 * A counter for the number of times execution enters and leaves a probed AST node, using the 406 * A counter for the number of times execution enters and leaves a probed AST node.
405 * simplest kind of listener.
406 */ 407 */
407 private class TestASTInstrumentCounter implements TestCounter { 408 private class TestASTInstrumentCounter implements TestCounter {
408 409
409 public int enterCount = 0; 410 public int enterCount = 0;
410 public int leaveCount = 0; 411 public int leaveCount = 0;
411 public final Instrument instrument; 412 public final Instrument instrument;
412 413
413 public TestASTInstrumentCounter() { 414 public TestASTInstrumentCounter() {
414 this.instrument = Instrument.create(new SimpleASTInstrumentListener() { 415 this.instrument = Instrument.create(new ASTInstrumentListener() {
415 416
416 @Override
417 public void enter(Probe probe, Node node, VirtualFrame vFrame) { 417 public void enter(Probe probe, Node node, VirtualFrame vFrame) {
418 enterCount++; 418 enterCount++;
419 } 419 }
420 420
421 @Override 421 public void returnVoid(Probe probe, Node node, VirtualFrame vFrame) {
422 public void returnAny(Probe probe, Node node, VirtualFrame vFrame) {
423 leaveCount++; 422 leaveCount++;
424 } 423 }
425 424
425 public void returnValue(Probe probe, Node node, VirtualFrame vFrame, Object result) {
426 leaveCount++;
427 }
428
429 public void returnExceptional(Probe probe, Node node, VirtualFrame vFrame, Exception exception) {
430 leaveCount++;
431 }
432
426 }, "Instrumentation Test Counter"); 433 }, "Instrumentation Test Counter");
427 434 }
428 } 435
429 436 @Override
430 public int enterCount() { 437 public int enterCount() {
431 return enterCount; 438 return enterCount;
432 } 439 }
433 440
441 @Override
434 public int leaveCount() { 442 public int leaveCount() {
435 return leaveCount; 443 return leaveCount;
436 } 444 }
437 445
446 @Override
438 public void attach(Probe probe) { 447 public void attach(Probe probe) {
439 probe.attach(instrument); 448 probe.attach(instrument);
440 } 449 }
441 450
451 @Override
442 public void dispose() { 452 public void dispose() {
443 instrument.dispose(); 453 instrument.dispose();
444 } 454 }
445 } 455 }
446 456
481 491
482 @Override 492 @Override
483 public void enter(Probe probe) { 493 public void enter(Probe probe) {
484 counter++; 494 counter++;
485 } 495 }
486
487 } 496 }
488 497
489 /** 498 /**
490 * Counts the number of "enter" events at probed nodes using the AST listener. 499 * Counts the number of "enter" events at probed nodes using the AST listener.
491 */ 500 */
495 504
496 @Override 505 @Override
497 public void enter(Probe probe, Node node, VirtualFrame vFrame) { 506 public void enter(Probe probe, Node node, VirtualFrame vFrame) {
498 counter++; 507 counter++;
499 } 508 }
500
501 } 509 }
502 510
503 /** 511 /**
504 * A counter that can count executions at multiple nodes; it attaches a separate instrument at 512 * A counter that can count executions at multiple nodes; it attaches a separate instrument at
505 * each Probe, but keeps a total count. 513 * each Probe, but keeps a total count.
537 @Override 545 @Override
538 public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) { 546 public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) {
539 tagCount++; 547 tagCount++;
540 } 548 }
541 } 549 }
542
543 } 550 }