-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on instrumentation for exceptions
- Loading branch information
Showing
5 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
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
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
83 changes: 83 additions & 0 deletions
83
.../main/java/org/evomaster/clientJava/instrumentation/visitor/SuccessCallMethodVisitor.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.evomaster.clientJava.instrumentation.visitor; | ||
|
||
import org.evomaster.clientJava.instrumentation.ClassName; | ||
import org.evomaster.clientJava.instrumentation.Constants; | ||
import org.evomaster.clientJava.instrumentation.staticState.ExecutionTracer; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Opcodes; | ||
|
||
/** | ||
* Add test objectives to make sure methods are called without | ||
* throwing an exception. | ||
* | ||
* TODO: should also handle the cases of accessing arrays out | ||
* of bounds. | ||
*/ | ||
public class SuccessCallMethodVisitor extends MethodVisitor { | ||
|
||
private final String className; | ||
private final String methodName; | ||
|
||
private int currentLine; | ||
private int currentIndex; | ||
|
||
public SuccessCallMethodVisitor(MethodVisitor mv, | ||
String className, | ||
String methodName, | ||
String descriptor) { | ||
super(Constants.ASM, mv); | ||
|
||
this.className = className; | ||
this.methodName = methodName; | ||
currentLine = 0; | ||
} | ||
|
||
@Override | ||
public void visitLineNumber(int line, Label start) { | ||
currentLine = line; | ||
currentIndex = 0; //reset it for current line | ||
} | ||
|
||
@Override | ||
public void visitMethodInsn(int opcode, String owner, String name, | ||
String desc, boolean itf) { | ||
|
||
//don't instrument static initializers | ||
if(methodName.equals(Constants.CLASS_INIT_METHOD)){ | ||
super.visitMethodInsn(opcode, owner, name, desc, itf); | ||
return; | ||
} | ||
|
||
int index = currentIndex++; | ||
|
||
addInstrumentation(index, false); | ||
super.visitMethodInsn(opcode, owner, name, desc, itf); | ||
addInstrumentation(index, true); | ||
} | ||
|
||
|
||
private void addInstrumentation(int index, boolean covered){ | ||
|
||
this.visitLdcInsn(className); | ||
this.visitLdcInsn(currentLine); | ||
this.visitLdcInsn(index); | ||
this.visitLdcInsn(covered); | ||
|
||
mv.visitMethodInsn( | ||
Opcodes.INVOKESTATIC, | ||
ClassName.get(ExecutionTracer.class).getBytecodeName(), | ||
ExecutionTracer.EXECUTING_METHOD_METHOD_NAME, | ||
ExecutionTracer.EXECUTING_METHOD_DESCRIPTOR, | ||
ExecutionTracer.class.isInterface()); | ||
} | ||
|
||
@Override | ||
public void visitMaxs(int maxStack, int maxLocals) { | ||
/* | ||
We pushed 4 values on stack before a method call, | ||
so we need to increase maxStack by at least 3 | ||
*/ | ||
super.visitMaxs(maxStack + 4, maxLocals); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...entation/src/test/java/com/foo/somedifferentpackage/examples/exceptions/ThrownExcImp.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.foo.somedifferentpackage.examples.exceptions; | ||
|
||
public class ThrownExcImp { | ||
|
||
public String directReturn(Object obj){ | ||
return obj.toString(); | ||
} | ||
|
||
public String directInTry(Object obj){ | ||
try{ | ||
return obj.toString(); | ||
} catch (Exception e){ | ||
throw e; | ||
} | ||
} | ||
|
||
public String doubleCall(Object x, Object y){ | ||
return x.toString() + y.toString(); | ||
} | ||
|
||
public String callOnArray(Object[] array, int index){ | ||
return array[index].toString(); | ||
} | ||
} |
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,3 +1,7 @@ | ||
Links related to deploy to Maven Central: | ||
- https://maven.apache.org/guides/mini/guide-central-repository-upload.html | ||
- http://central.sonatype.org/pages/ossrh-guide.html | ||
- http://central.sonatype.org/pages/ossrh-guide.html | ||
|
||
Useful links: | ||
- Kotlin: https://kotlinlang.org/docs/kotlin-docs.pdf | ||
- ASM: http://download.forge.objectweb.org/asm/asm4-guide.pdf |