-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic while-loop instrumentation works (only for single cond args)
- Loading branch information
Showing
3 changed files
with
103 additions
and
82 deletions.
There are no files selected for viewing
160 changes: 80 additions & 80 deletions
160
VRL/VRL-Lang/src/test/java/eu/mihosoft/vrl/instrumentation/InstrumentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package eu.mihosoft.vrl.instrumentation; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
|
||
import eu.mihosoft.vrl.lang.model.CodeRange; | ||
import eu.mihosoft.vrl.lang.model.CompilationUnitDeclaration; | ||
import eu.mihosoft.vrl.lang.model.Scope; | ||
import eu.mihosoft.vrl.lang.model.Scope2Code; | ||
import eu.mihosoft.vrl.lang.model.UIBinding; | ||
import eu.mihosoft.vrl.lang.model.Variable; | ||
import groovy.lang.GroovyClassLoader; | ||
import groovy.lang.GroovyShell; | ||
import groovy.lang.Script; | ||
import groovy.util.GroovyScriptEngine; | ||
|
||
import org.codehaus.groovy.control.CompilerConfiguration; | ||
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author Michael Hoffer <[email protected]> | ||
*/ | ||
public class InstrumentationTest { | ||
|
||
@Test | ||
public void testMethodCallInstrumentation() { | ||
CompilerConfiguration conf = new CompilerConfiguration(); | ||
conf.addCompilationCustomizers(new ASTTransformationCustomizer( | ||
new VRLInstrumentationTransformation())); | ||
GroovyShell shell = new GroovyShell(conf); | ||
shell.parse( | ||
"@eu.mihosoft.vrl.instrumentation.VRLInstrumentation\n" | ||
+ "public class A {\n" | ||
+ " public boolean m3(int i) {return i < 3;}\n" | ||
+ " \n" + " public void m2(int p1) {\n" | ||
+ " for(int i = 0; m3(i);i++) {\n" | ||
+ " A.m1(A.m1(1));\n" + " }" | ||
+ " }\n" + " public static int m1(int p1) {\n" | ||
+ " println(\"p1: \" + (p1+1));\n" | ||
+ " return p1+1;\n" + " }\n" | ||
+ " public static void main(String[] args) {" | ||
+ " A a = new A();" + " a.m2(1);" | ||
+ " }" + "}").run(); | ||
assertEquals(1, conf.getCompilationCustomizers().size()); | ||
} | ||
|
||
@Test | ||
public void testVRLVisualizationTransformationDuplicateMethods() { | ||
CompilerConfiguration conf = new CompilerConfiguration(); | ||
conf.addCompilationCustomizers(new ASTTransformationCustomizer( | ||
new VRLVisualizationTransformation())); | ||
GroovyClassLoader loader = new GroovyClassLoader(this.getClass() | ||
.getClassLoader(), conf); | ||
|
||
UIBinding.scopes.clear(); | ||
String classX = "package x.y.z;\npublic class X {\n public int foo(){\n return 0;\n }\n}\n"; | ||
loader.parseClass(classX); | ||
|
||
// get scopes in CompilationUnit -> class X | ||
// then get scopes within class X -> should be a list containing only | ||
// method foo() | ||
Collection<Scope> scopes = UIBinding.scopes.values().iterator().next() | ||
.get(0).getScopes().get(0).getScopes(); | ||
|
||
// assert foo is only added once | ||
assertEquals(1, scopes.size()); | ||
Iterator<Scope> iter = scopes.iterator(); | ||
assertEquals("foo", iter.next().getName()); | ||
} | ||
} | ||
///* | ||
// * To change this license header, choose License Headers in Project Properties. | ||
// * To change this template file, choose Tools | Templates | ||
// * and open the template in the editor. | ||
// */ | ||
//package eu.mihosoft.vrl.instrumentation; | ||
// | ||
//import static org.junit.Assert.*; | ||
// | ||
//import java.io.PrintWriter; | ||
//import java.util.Collection; | ||
//import java.util.Iterator; | ||
// | ||
//import eu.mihosoft.vrl.lang.model.CodeRange; | ||
//import eu.mihosoft.vrl.lang.model.CompilationUnitDeclaration; | ||
//import eu.mihosoft.vrl.lang.model.Scope; | ||
//import eu.mihosoft.vrl.lang.model.Scope2Code; | ||
//import eu.mihosoft.vrl.lang.model.UIBinding; | ||
//import eu.mihosoft.vrl.lang.model.Variable; | ||
//import groovy.lang.GroovyClassLoader; | ||
//import groovy.lang.GroovyShell; | ||
//import groovy.lang.Script; | ||
//import groovy.util.GroovyScriptEngine; | ||
// | ||
//import org.codehaus.groovy.control.CompilerConfiguration; | ||
//import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; | ||
//import org.junit.Test; | ||
// | ||
///** | ||
// * | ||
// * @author Michael Hoffer <[email protected]> | ||
// */ | ||
//public class InstrumentationTest { | ||
// | ||
// @Test | ||
// public void testMethodCallInstrumentation() { | ||
// CompilerConfiguration conf = new CompilerConfiguration(); | ||
// conf.addCompilationCustomizers(new ASTTransformationCustomizer( | ||
// new VRLInstrumentationTransformation())); | ||
// GroovyShell shell = new GroovyShell(conf); | ||
// shell.parse( | ||
// "@eu.mihosoft.vrl.instrumentation.VRLInstrumentation\n" | ||
// + "public class A {\n" | ||
// + " public boolean m3(int i) {return i < 3;}\n" | ||
// + " \n" + " public void m2(int p1) {\n" | ||
// + " for(int i = 0; m3(i);i++) {\n" | ||
// + " A.m1(A.m1(1));\n" + " }" | ||
// + " }\n" + " public static int m1(int p1) {\n" | ||
// + " println(\"p1: \" + (p1+1));\n" | ||
// + " return p1+1;\n" + " }\n" | ||
// + " public static void main(String[] args) {" | ||
// + " A a = new A();" + " a.m2(1);" | ||
// + " }" + "}").run(); | ||
// assertEquals(1, conf.getCompilationCustomizers().size()); | ||
// } | ||
// | ||
// @Test | ||
// public void testVRLVisualizationTransformationDuplicateMethods() { | ||
// CompilerConfiguration conf = new CompilerConfiguration(); | ||
// conf.addCompilationCustomizers(new ASTTransformationCustomizer( | ||
// new VRLVisualizationTransformation())); | ||
// GroovyClassLoader loader = new GroovyClassLoader(this.getClass() | ||
// .getClassLoader(), conf); | ||
// | ||
// UIBinding.scopes.clear(); | ||
// String classX = "package x.y.z;\npublic class X {\n public int foo(){\n return 0;\n }\n}\n"; | ||
// loader.parseClass(classX); | ||
// | ||
// // get scopes in CompilationUnit -> class X | ||
// // then get scopes within class X -> should be a list containing only | ||
// // method foo() | ||
// Collection<Scope> scopes = UIBinding.scopes.values().iterator().next() | ||
// .get(0).getScopes().get(0).getScopes(); | ||
// | ||
// // assert foo is only added once | ||
// assertEquals(1, scopes.size()); | ||
// Iterator<Scope> iter = scopes.iterator(); | ||
// assertEquals("foo", iter.next().getName()); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
VRL/VRL-Lang/src/test/resources/eu/mihosoft/vrl/lang/Instrumentation02.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* global comment*/ | ||
|
||
package my.testpackage; | ||
|
||
/** | ||
* class MyFileClass | ||
*/ | ||
@eu.mihosoft.vrl.instrumentation.VRLVisualization | ||
public class MyFileClass { | ||
|
||
public static void main(String[] args) { | ||
int n = 3; | ||
int i = 0; | ||
|
||
while(i<n) { | ||
println("i: " + i); | ||
i=i+1; | ||
} | ||
} | ||
} |