Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java @ 22230:3f2052afcb6d
Truffle/Instrumentation: rename the methods in the Instrument listener classes to use the "on" convention, e.g. onEnter(), add Javadoc
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Sun, 20 Sep 2015 16:48:50 -0700 |
parents | a0fa69e3e60e |
children | 526de3af756d |
rev | line source |
---|---|
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
1 /* |
19247
128586040207
Truffle/Instrumentation: TruffleEventReceiver renamed to TruffleEventListener
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
4 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
5 * The Universal Permissive License (UPL), Version 1.0 |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
6 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
7 * Subject to the condition set forth below, permission is hereby granted to any |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
8 * person obtaining a copy of this software, associated documentation and/or |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
9 * data (collectively the "Software"), free of charge and under any and all |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
10 * copyright rights in the Software, and any and all patent rights owned or |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
11 * freely licensable by each licensor hereunder covering either (i) the |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
12 * unmodified Software as contributed to or provided by such licensor, or (ii) |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
13 * the Larger Works (as defined below), to deal in both |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
14 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
15 * (a) the Software, and |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
16 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
17 * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
18 * one is included with the Software each a "Larger Work" to which the Software |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
19 * is contributed by such licensors), |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
20 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
21 * without restriction, including without limitation the rights to copy, create |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
22 * derivative works of, display, perform, and distribute the Software and make, |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
23 * use, sell, offer for sale, import, export, have made, and have sold the |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
24 * Software and the Larger Work(s), and to sublicense the foregoing rights on |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
25 * either these or other terms. |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
26 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
27 * This license is subject to the following condition: |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
28 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
29 * The above copyright notice and either this complete permission notice or at a |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
30 * minimum a reference to the UPL must be included in all copies or substantial |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
31 * portions of the Software. |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22025
diff
changeset
|
32 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
39 * SOFTWARE. |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
40 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
41 package com.oracle.truffle.sl.test.instrument; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
42 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
43 import java.io.BufferedReader; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
44 import java.io.ByteArrayOutputStream; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
45 import java.io.FileNotFoundException; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
46 import java.io.IOException; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
47 import java.io.PrintWriter; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
48 import java.io.StringReader; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
49 import java.lang.reflect.Field; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
50 import java.nio.charset.Charset; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
51 import java.nio.file.FileSystems; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
52 import java.nio.file.FileVisitResult; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
53 import java.nio.file.Files; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
54 import java.nio.file.Path; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
55 import java.nio.file.SimpleFileVisitor; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
56 import java.nio.file.attribute.BasicFileAttributes; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
57 import java.util.ArrayList; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
58 import java.util.List; |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
59 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
60 import org.junit.Assert; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
61 import org.junit.internal.TextListener; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
62 import org.junit.runner.Description; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
63 import org.junit.runner.JUnitCore; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
64 import org.junit.runner.Result; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
65 import org.junit.runner.manipulation.Filter; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
66 import org.junit.runner.manipulation.NoTestsRemainException; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
67 import org.junit.runner.notification.Failure; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
68 import org.junit.runner.notification.RunNotifier; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
69 import org.junit.runners.ParentRunner; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
70 import org.junit.runners.model.InitializationError; |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
71 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
72 import com.oracle.truffle.api.instrument.ASTProber; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
73 import com.oracle.truffle.api.instrument.Instrumenter; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
74 import com.oracle.truffle.api.instrument.Probe; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
75 import com.oracle.truffle.api.instrument.StandardSyntaxTag; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
76 import com.oracle.truffle.api.instrument.impl.DefaultSimpleInstrumentListener; |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22065
diff
changeset
|
77 import com.oracle.truffle.api.source.Source; |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
78 import com.oracle.truffle.api.vm.TruffleVM; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
79 import com.oracle.truffle.sl.nodes.instrument.SLStandardASTProber; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
80 import com.oracle.truffle.sl.nodes.local.SLWriteLocalVariableNode; |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
81 import com.oracle.truffle.sl.test.SLTestRunner; |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
82 import com.oracle.truffle.sl.test.instrument.SLInstrumentTestRunner.InstrumentTestCase; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
83 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
84 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
85 * This class builds and executes the tests for instrumenting SL. Although much of this class is |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
86 * written with future automation in mind, at the moment the tests that are created are hard-coded |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
87 * according to the file name of the test. To be automated, an automatic way of generating both the |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
88 * node visitor and the node prober is necessary. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
89 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
90 * Testing is done via JUnit via comparing execution outputs with expected outputs. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
91 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
92 public final class SLInstrumentTestRunner extends ParentRunner<InstrumentTestCase> { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
93 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
94 private static final String SOURCE_SUFFIX = ".sl"; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
95 private static final String INPUT_SUFFIX = ".input"; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
96 private static final String OUTPUT_SUFFIX = ".output"; |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
97 private static final String ASSIGNMENT_VALUE_SUFFIX = "_assnCount"; |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
98 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
99 private static final String LF = System.getProperty("line.separator"); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
100 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
101 static final class InstrumentTestCase { |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
102 protected final Description name; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
103 protected final Path path; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
104 protected final String baseName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
105 protected final String sourceName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
106 protected final String testInput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
107 protected final String expectedOutput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
108 protected String actualOutput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
109 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
110 protected InstrumentTestCase(Class<?> testClass, String baseName, String sourceName, Path path, String testInput, String expectedOutput) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
111 this.name = Description.createTestDescription(testClass, baseName); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
112 this.baseName = baseName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
113 this.sourceName = sourceName; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
114 this.path = path; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
115 this.testInput = testInput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
116 this.expectedOutput = expectedOutput; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
117 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
118 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
119 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
120 private final List<InstrumentTestCase> testCases; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
121 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
122 public SLInstrumentTestRunner(Class<?> testClass) throws InitializationError, SecurityException, IllegalArgumentException { |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
123 super(testClass); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
124 try { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
125 testCases = createTests(testClass); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
126 } catch (IOException e) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
127 throw new InitializationError(e); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
128 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
129 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
130 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
131 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
132 protected List<InstrumentTestCase> getChildren() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
133 return testCases; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
134 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
135 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
136 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
137 protected Description describeChild(InstrumentTestCase child) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
138 return child.name; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
139 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
140 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
141 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
142 * Tests are created based on the files that exist in the directory specified in the passed in |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
143 * annotation. Each test must have a source file and an expected output file. Optionally, each |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
144 * test can also include an input file. Source files have an ".sl" extension. Expected output |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
145 * have a ".output" extension. Input files have an ".input" extension. All these files must |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
146 * share the same base name to be correctly grouped. For example: "test1_assnCount.sl", |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
147 * "test1_assnCount.output" and "test1_assnCount.input" would all be used to create a single |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
148 * test called "test1_assnCount". |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
149 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
150 * This method iterates over the files in the directory and creates a new InstrumentTestCase for |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
151 * each group of related files. Each file is also expected to end with an identified at the end |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
152 * of the base name to indicate what visitor needs to be attached. Currently, visitors are hard |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
153 * coded to work on specific lines, so the code here is not currently generalizable. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
154 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
155 * @param c The annotation containing the directory with tests |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
156 * @return A list of {@link InstrumentTestCase}s to run. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
157 * @throws IOException If the directory is invalid. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
158 * @throws InitializationError If no directory is provided. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
159 * |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
160 * @see #runChild(InstrumentTestCase, RunNotifier) |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
161 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
162 protected static List<InstrumentTestCase> createTests(final Class<?> c) throws IOException, InitializationError { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
163 SLInstrumentTestSuite suite = c.getAnnotation(SLInstrumentTestSuite.class); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
164 if (suite == null) { |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
165 throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLInstrumentTestSuite.class.getSimpleName(), c.getName(), |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
166 SLInstrumentTestRunner.class.getSimpleName())); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
167 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
168 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
169 String[] paths = suite.value(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
170 |
22024
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
171 Path root = SLTestRunner.getRootViaResourceURL(c, paths); |
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
172 if (root == null) { |
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
173 for (String path : paths) { |
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
174 root = FileSystems.getDefault().getPath(path); |
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
175 if (Files.exists(root)) { |
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
176 break; |
216e0683bbf1
made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents:
21951
diff
changeset
|
177 } |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
178 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
179 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
180 if (root == null && paths.length > 0) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
181 throw new FileNotFoundException(paths[0]); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
182 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
183 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
184 final Path rootPath = root; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
185 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
186 final List<InstrumentTestCase> testCases = new ArrayList<>(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
187 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
188 // Scaffolding in place for future automation |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
189 Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
190 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
191 public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
192 String sourceName = sourceFile.getFileName().toString(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
193 if (sourceName.endsWith(SOURCE_SUFFIX)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
194 String baseName = sourceName.substring(0, sourceName.length() - SOURCE_SUFFIX.length()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
195 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
196 Path inputFile = sourceFile.resolveSibling(baseName + INPUT_SUFFIX); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
197 String testInput = ""; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
198 if (Files.exists(inputFile)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
199 testInput = readAllLines(inputFile); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
200 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
201 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
202 Path outputFile = sourceFile.resolveSibling(baseName + OUTPUT_SUFFIX); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
203 String expectedOutput = ""; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
204 if (Files.exists(outputFile)) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
205 expectedOutput = readAllLines(outputFile); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
206 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
207 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
208 testCases.add(new InstrumentTestCase(c, baseName, sourceName, sourceFile, testInput, expectedOutput)); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
209 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
210 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
211 return FileVisitResult.CONTINUE; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
212 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
213 }); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
214 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
215 return testCases; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
216 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
217 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
218 private static String readAllLines(Path file) throws IOException { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
219 // fix line feeds for non unix os |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
220 StringBuilder outFile = new StringBuilder(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
221 for (String line : Files.readAllLines(file, Charset.defaultCharset())) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
222 outFile.append(line).append(LF); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
223 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
224 return outFile.toString(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
225 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
226 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
227 /** |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
228 * Executes the passed in test case. Instrumentation is added according to the name of the file |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
229 * as explained in {@link #createTests(Class)}. Note that this code is not generalizable. |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
230 */ |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
231 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
232 protected void runChild(InstrumentTestCase testCase, RunNotifier notifier) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
233 // TODO Current tests are hard-coded, automate this eventually |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
234 notifier.fireTestStarted(testCase.name); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
235 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
236 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20889
diff
changeset
|
237 PrintWriter printer = new PrintWriter(out); |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
238 final ASTProber prober = new SLStandardASTProber(); |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
239 |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
240 try { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
241 // We use the name of the file to determine what visitor to attach to it. |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
242 if (testCase.baseName.endsWith(ASSIGNMENT_VALUE_SUFFIX)) { |
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
243 // Set up the execution context for Simple and register our two listeners |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
244 TruffleVM vm = TruffleVM.newVM().stdIn(new BufferedReader(new StringReader(testCase.testInput))).stdOut(printer).build(); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
245 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
246 final Field field = TruffleVM.class.getDeclaredField("instrumenter"); |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
247 field.setAccessible(true); |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
248 final Instrumenter instrumenter = (Instrumenter) field.get(vm); |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
249 instrumenter.registerASTProber(prober); |
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
250 |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
251 final String src = readAllLines(testCase.path); |
22104
cf19259edf87
TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22065
diff
changeset
|
252 vm.eval(Source.fromText(src, testCase.path.toString()).withMimeType("application/x-sl")); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
253 |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
254 // Attach an instrument to every probe tagged as an assignment |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
255 for (Probe probe : instrumenter.findProbesTaggedAs(StandardSyntaxTag.ASSIGNMENT)) { |
19247
128586040207
Truffle/Instrumentation: TruffleEventReceiver renamed to TruffleEventListener
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
256 SLPrintAssigmentValueListener slPrintAssigmentValueListener = new SLPrintAssigmentValueListener(printer); |
22225
a0fa69e3e60e
Truffle/Instrumentation: remove static Instrument factory methods, now supported by Instrumenter
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22219
diff
changeset
|
257 instrumenter.attach(probe, slPrintAssigmentValueListener, "SL print assignment value"); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
258 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
259 |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
260 TruffleVM.Symbol main = vm.findGlobalSymbol("main"); |
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
261 main.invoke(null); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
262 } else { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
263 notifier.fireTestFailure(new Failure(testCase.name, new UnsupportedOperationException("No instrumentation found."))); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
264 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
265 |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20889
diff
changeset
|
266 printer.flush(); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
267 String actualOutput = new String(out.toByteArray()); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
268 Assert.assertEquals(testCase.expectedOutput, actualOutput); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
269 } catch (Throwable ex) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
270 notifier.fireTestFailure(new Failure(testCase.name, ex)); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
271 } finally { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
272 notifier.fireTestFinished(testCase.name); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
273 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
274 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
275 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
276 |
22214
3aad794eec0e
Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22104
diff
changeset
|
277 public static void runInMain(Class<?> testClass, String[] args) throws InitializationError, NoTestsRemainException, SecurityException, IllegalArgumentException { |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
278 JUnitCore core = new JUnitCore(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
279 core.addListener(new TextListener(System.out)); |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16776
diff
changeset
|
280 SLInstrumentTestRunner suite = new SLInstrumentTestRunner(testClass); |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
281 if (args.length > 0) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
282 suite.filter(new NameFilter(args[0])); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
283 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
284 Result r = core.run(suite); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
285 if (!r.wasSuccessful()) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
286 System.exit(1); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
287 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
288 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
289 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
290 private static final class NameFilter extends Filter { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
291 private final String pattern; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
292 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
293 private NameFilter(String pattern) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
294 this.pattern = pattern.toLowerCase(); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
295 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
296 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
297 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
298 public boolean shouldRun(Description description) { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
299 return description.getMethodName().toLowerCase().contains(pattern); |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
300 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
301 |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
302 @Override |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
303 public String describe() { |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
304 return "Filter contains " + pattern; |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
305 } |
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
306 } |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
307 |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
308 /** |
19818
907128d02b31
Truffle/Instrumentation: For clients of Instrumentation, replace the TruffleEventListener interface with two: InstrumentListener, and ASTInstrumentListener. The former is simple, completely Truffle-safe (can't affect Truffle execution), and designed for simple tools. The latter is similar to the previous interface.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19247
diff
changeset
|
309 * This sample listener provides prints the value of an assignment (after the assignment is |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20889
diff
changeset
|
310 * complete) to the {@link PrintWriter} specified in the constructor. This listener can only be |
19818
907128d02b31
Truffle/Instrumentation: For clients of Instrumentation, replace the TruffleEventListener interface with two: InstrumentListener, and ASTInstrumentListener. The former is simple, completely Truffle-safe (can't affect Truffle execution), and designed for simple tools. The latter is similar to the previous interface.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19247
diff
changeset
|
311 * attached at {@link SLWriteLocalVariableNode}, but provides no guards to protect it from being |
907128d02b31
Truffle/Instrumentation: For clients of Instrumentation, replace the TruffleEventListener interface with two: InstrumentListener, and ASTInstrumentListener. The former is simple, completely Truffle-safe (can't affect Truffle execution), and designed for simple tools. The latter is similar to the previous interface.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19247
diff
changeset
|
312 * attached elsewhere. |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
313 */ |
20889
73b1844b5b14
Truffle/Instrumentation: rename InstrumentListener to SimpleInstrumentListener
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19818
diff
changeset
|
314 public final class SLPrintAssigmentValueListener extends DefaultSimpleInstrumentListener { |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
315 |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20889
diff
changeset
|
316 private PrintWriter output; |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
317 |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
20889
diff
changeset
|
318 public SLPrintAssigmentValueListener(PrintWriter output) { |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
319 this.output = output; |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
320 } |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
321 |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
322 @Override |
22230
3f2052afcb6d
Truffle/Instrumentation: rename the methods in the Instrument listener classes to use the "on" convention, e.g. onEnter(), add Javadoc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22225
diff
changeset
|
323 public void onReturnValue(Probe probe, Object result) { |
18485
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
324 output.println(result); |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
325 } |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
326 } |
e3c95cbbb50c
Truffle Instrumentation: major API revision, based around the Probe and Instrument classes; add Instrumentable API for language implementors, with most details automated; reimplemented to handle AST splitting automatically; more JUnit tests.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18411
diff
changeset
|
327 |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
diff
changeset
|
328 } |