Commit da9ee432 authored by František Haas's avatar František Haas

fixed disl.py server killing

removed old tests
parent 62408d43
......@@ -387,30 +387,4 @@
</batchtest>
</junit>
</target>
<target name="check-test-property">
<condition property="test.set">
<isset property="test.name" />
</condition>
</target>
<target name="report-missing-property" depends="check-test-property" unless="test.set">
<fail message="Property test.name is not set. Set it using -Dtest.name=value" />
</target>
<property name="test.path" value="ch/usi/dag/disl/test/${test.name}" />
<target name="package-test" depends="report-missing-property,prepare-all" description="create instrumentation package for specified test">
<mkdir dir="${build}" />
<jar jarfile="${build}/${instr.jar.name}" basedir="${bin}" includes="${test.path}/**" excludes="${test.path}/TargetClass*.class ${test.path}/MANIFEST.MF" manifest="${src.test}/${test.path}/MANIFEST.MF">
</jar>
</target>
<!-- unsafe for missing dependencies -->
<target name="unsafe-package-test" description="create instrumentation package for specified test">
<mkdir dir="${build}" />
<jar jarfile="${build}/disl-instr-${test.name}.jar" basedir="${bin}" includes="${test.path}/**" excludes="${test.path}/TargetClass*.class ${test.path}/MANIFEST.MF" manifest="${src.test}/${test.path}/MANIFEST.MF">
</jar>
</target>
</project>
......@@ -371,9 +371,10 @@ def parse_arguments(parser):
######################################################################
def try_kill(pid_file_name):
try:
with open(pid_file_name, "r") as pid_file:
pid = pid_file.readline()
kill = Popen(["kill", pid], stdout=PIPE, shell=False)
with open(os.devnull, "w") as devnull:
with open(pid_file_name, "r") as pid_file:
pid = pid_file.readline()
kill = Popen(["kill", pid], stdout=devnull, stderr=devnull, shell=False)
except IOError:
pass
......@@ -493,6 +494,9 @@ def run_client(args, parser):
client = run(c_cmd, args.c_out, args.c_err)
client.wait()
# let server and evaluation finish
time.sleep(1)
try_kill(".server.pid")
try_kill(".evaluation.pid")
......
#!/bin/bash
# set default lib path
if [ -z "${DISL_LIB_P}" ]; then
DISL_LIB_P=./build
fi
# test number of arguments
if [ $# -lt 2 ]; then
echo "Usage: `basename $0` instr-lib java-params"
exit 1
fi
# determine libs depending on the OS
OS=`uname`
if [ "${OS}" = "Darwin" ]; then
C_AGENT="${DISL_LIB_P}/libdislagent.jnilib"
RE_AGENT="${DISL_LIB_P}/libdislreagent.jnilib"
else
C_AGENT="${DISL_LIB_P}/libdislagent.so"
RE_AGENT="${DISL_LIB_P}/libdislreagent.so"
fi
# get instrumentation library and shift parameters
INSTR_LIB=$1
shift
# start the client
${JAVA_HOME:+$JAVA_HOME/jre/bin/}java \
-agentpath:${C_AGENT} -agentpath:${RE_AGENT} \
-javaagent:${DISL_LIB_P}/disl-agent.jar \
-Xbootclasspath/a:${DISL_LIB_P}/disl-agent.jar:${INSTR_LIB}:${DISL_LIB_P}/dislre-dispatch.jar \
"$@"
#!/bin/sh
# set default lib path
if [ -z "${DISL_LIB_P}" ]; then
DISL_LIB_P=./build
fi
# test number of arguments
if [ $# -lt 1 ]; then
echo "Usage: `basename $0` instr-lib [java-params]"
exit 1
fi
# get instrumentation library and shift parameters
INSTR_LIB=$1
shift
# start the remote execution server
# options available:
# -Ddebug=true \
# -Ddislreserver.port="portNum" \
${JAVA_HOME:+$JAVA_HOME/jre/bin/}java \
-Xms1G -Xmx2G \
-cp ${INSTR_LIB}:${DISL_LIB_P}/dislre-server.jar \
ch.usi.dag.dislreserver.DiSLREServer \
"$@" &
# print pid to the server file
if [ -n "${RE_SERVER_FILE}" ]; then
echo $! > ${RE_SERVER_FILE}
fi
#!/bin/sh
# set default lib path
if [ -z "${DISL_LIB_P}" ]; then
DISL_LIB_P=./build
fi
# test number of arguments
if [ $# -lt 1 ]; then
echo "Usage: `basename $0` instr-lib [java-params]"
exit 1
fi
# get instrumentation library and shift parameters
INSTR_LIB=$1
shift
# start the instrumentation server
# options available:
# -Ddebug=true \
# -Ddisl.classes="list of disl classes (: - separator)"
# -Ddisl.noexcepthandler=true \
# -Ddisl.exclusionList="path" \
# -Ddislserver.instrumented="path" \
# -Ddislserver.uninstrumented="path" \
# -Ddislserver.port="portNum" \
# -Ddislserver.timestat=true \
# -Ddislserver.continuous=true \
# -Ddislserver.disablebypass=true \
${JAVA_HOME:+$JAVA_HOME/jre/bin/}java \
-cp ${INSTR_LIB}:${DISL_LIB_P}/disl-server.jar \
ch.usi.dag.dislserver.DiSLServer \
"$@" &
# print pid to the server file
if [ -n "${SERVER_FILE}" ]; then
echo $! > ${SERVER_FILE}
fi
#!/bin/bash
TARGET_BASE="ch.usi.dag.disl.test"
TARGET_MAIN="TargetClass"
if [ $# -lt 1 ]; then
echo "Usage: `basename $0` <test-name>"
echo "<test-name> is a package under $TARGET_BASE containing $TARGET_MAIN"
exit 1
fi
kill_server () {
if [ -f "$1" ]; then
local PID=$(< "$1")
[ -n "$PID" ] && kill -KILL $PID 2> /dev/null
rm -f "$1"
fi
}
#
# Compile the test package to make sure we have up-to-date jars.
# Bail out now if the compilation fails.
#
ant package-test -Dtest.name=$1 > /dev/null || exit 2
#
# Configure server PID files and mop-up any leftover
# instrumentation or remote/analysis servers.
#
export SERVER_FILE=.server.pid
kill_server $SERVER_FILE
export RE_SERVER_FILE=.re_server.pid
kill_server $RE_SERVER_FILE
#
# Launch the instrumentation and analysis servers and give them time to start.
# Then run the client with the class representing the observed program.
#
# Include the library containing the instrumentation in their class path.
#
INSTR_LIB=build/disl-instr.jar
./runServer.sh ${INSTR_LIB}
./runREServer.sh ${INSTR_LIB}
sleep 3
./runClient.sh ${INSTR_LIB} -cp bin/ "$TARGET_BASE.$1.$TARGET_MAIN"
#
# Give the servers some time to shut down themselves, before mopping up.
#
sleep 1
kill_server $SERVER_FILE
kill_server $RE_SERVER_FILE
#!/bin/sh
TESTS=`ls src-test/ch/usi/dag/disl/test/`
for TEST in ${TESTS}
do
echo "*** Starting test ${TEST} ***" | tee -a run-all.log
./runTest.sh ${TEST} pkg 2>&1 | tee -a run-all.log
done
package ch.usi.dag.disl.test.after;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.AfterThrowing;
import ch.usi.dag.disl.marker.BodyMarker;
public class DiSLClass {
@After(marker = BodyMarker.class, scope = "TargetClass.print(boolean)", order = 0)
public static void after() {
System.out.println("disl: after");
}
@AfterThrowing(marker = BodyMarker.class, scope = "TargetClass.print(boolean)", order = 1)
public static void afterThrowning() {
System.out.println("disl: afterThrowning");
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.after.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.after;
public class TargetClass {
public void print(boolean flag) {
try {
System.out.println("app: try-clause");
if (flag) {
String float_one = "1.0";
int int_one = Integer.valueOf(float_one);
System.out.println("app: " + int_one + "This should not be printed!");
}
System.out.println("app: normal return");
} finally {
System.out.println("app: finally-clause");
}
}
public static void main(String[] args) {
TargetClass t = new TargetClass();
System.out.println("app: call print(false)");
t.print(false);
System.out.println("app: call print(true)");
t.print(true);
}
}
app: call print(false)
app: try-clause
app: normal return
app: finally-clause
disl: after
app: call print(true)
app: try-clause
app: finally-clause
disl: after
disl: afterThrowning
package ch.usi.dag.disl.test.after2;
import java.util.Stack;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.annotation.ThreadLocal;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.staticcontext.uid.UniqueMethodId;
import ch.usi.dag.disl.test.after2.runtime.Analysis;
public class DiSLClass {
@ThreadLocal
static Stack<Integer> stackTL;
@Before(marker = BodyMarker.class, order = 0, scope = "*.*", guard = NotInitNorClinit.class)
public static void onMethodEntryObjectArgs(UniqueMethodId id) {
Stack<Integer> thisStack;
if((thisStack = stackTL) == null) {
thisStack = (stackTL = new Stack<Integer>());
}
thisStack.push(id.get());
}
@After(marker = BodyMarker.class, order = 0, scope = "*.*", guard = NotInitNorClinit.class)
public static void onMethodExit(UniqueMethodId id) {
Analysis.onExit(stackTL, id.get());
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.after2.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.after2;
import ch.usi.dag.disl.annotation.GuardMethod;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class NotInitNorClinit {
@GuardMethod
public static boolean isApplicable(MethodStaticContext msc) {
return (msc.thisMethodName().endsWith("init>")) ? false : true;
}
}
package ch.usi.dag.disl.test.after2;
public class TargetClass {
public static void main(String[] args) {
// NOTE: this test is better to use on large project and not this simple class
System.out.println("TargetClass.test");
}
}
package ch.usi.dag.disl.test.after2.runtime;
import java.util.Stack;
public class Analysis {
public static void onExit(Stack<Integer> stack, int methodUID) {
int topOfTheStack = stack.pop();
if(topOfTheStack != methodUID) {
System.err.println("=================================================");
System.err.println("[ERROR] Inconsistent stack!");
System.err.println("After method: " + methodUID);
int size = stack.size();
System.err.println("Stack[" + size + "]: " + topOfTheStack);
for(int i = size - 1; i >= 0; i--) {
System.err.println("Stack[" + i + "]: " + stack.elementAt(i));
}
System.err.println("=================================================");
System.exit(-1);
}
}
}
package ch.usi.dag.disl.test.after3;
import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.annotation.AfterThrowing;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class DiSLClass {
@AfterThrowing(marker = BodyMarker.class, scope = "TargetClass.e*", order = 0)
public static void throwing(MethodStaticContext sc) {
System.out.println("Throwing! for " + sc.thisMethodName());
}
@AfterReturning(marker = BodyMarker.class, scope = "TargetClass.e*", order = 0)
public static void returning(MethodStaticContext sc) {
System.out.println("Returning! for " + sc.thisMethodName());
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.after3.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.after3;
public class TargetClass {
public static void main(String[] args) {
System.out.println("hi");
try {
ethrowing1();
} catch (Exception e) {
e.printStackTrace();
}
try {
ereturning1();
} catch (Exception e) {
e.printStackTrace();
}
try {
ethrowing2();
} catch (Exception e) {
e.printStackTrace();
}
try {
ereturning2();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void ethrowing1() throws Exception {
try {
if ("a".equals("a")) {
throw new Exception();
}
return;
} catch (Exception e) {
throw e;
}
}
public static void ereturning1() throws Exception {
try {
if ("a".equals("a")) {
// throw new Exception();
}
return;
} catch (Exception e) {
throw e;
}
}
public static void ethrowing2() throws Exception {
throw new Exception();
}
public static void ereturning2() throws Exception {
// throw new Exception();
}
}
Throwing! for ethrowing1
Returning! for ereturning1
Throwing! for ethrowing2
Returning! for ereturning2
package ch.usi.dag.disl.test.after4;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.AfterThrowing;
import ch.usi.dag.disl.dynamiccontext.DynamicContext;
import ch.usi.dag.disl.marker.BodyMarker;
public class DiSLClass {
@After(marker = BodyMarker.class, scope = "TargetClass.print(boolean)", order = 0)
public static void after(DynamicContext dc) {
System.out.println("after " + dc.getException());
}
@AfterThrowing(marker = BodyMarker.class, scope = "TargetClass.print(boolean)", order = 1)
public static void afterThrowning(DynamicContext dc) {
System.out.println("afterThrowning " + dc.getException());
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.after4.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.after4;
public class TargetClass {
public void print(boolean flag) {
try {
System.out.println("try-clause");
if (flag) {
String float_one = "1.0";
int int_one = Integer.valueOf(float_one);
System.out.println(int_one + "This should not be printed!");
}
System.out.println("normal return");
} finally {
System.out.println("finally-clause");
}
}
public static void main(String[] args) {
TargetClass t = new TargetClass();
System.out.println("=========call print(false)=========");
t.print(false);
System.out.println("=========call print(true) =========");
t.print(true);
}
}
=========call print(false)=========
try-clause
normal return
finally-clause
after null
=========call print(true) =========
try-clause
finally-clause
after java.lang.NumberFormatException: For input string: "1.0"
afterThrowning java.lang.NumberFormatException: For input string: "1.0"
package ch.usi.dag.disl.test.afterinit;
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.AfterInitBodyMarker;
public class DiSLClass {
@Before(marker = AfterInitBodyMarker.class, scope = "*TargetClass2.<init>")
public static void after() {
System.out.println("Before");
}
@After(marker = AfterInitBodyMarker.class, scope = "*TargetClass2.<init>")
public static void afterThrowning() {
System.out.println("After");
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.afterinit.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.afterinit;
public class TargetClass {
public TargetClass() {
System.out.println("Constructing TargetClass");
}
static class TargetClass2 extends TargetClass {
public TargetClass2() {
System.out.println("Constructing TargetClass2");
System.out.println("Construction end");
}
public void method() {
}
}
public static void main(String[] args) {
TargetClass2 t = new TargetClass2();
t.method();
}
}
Constructing TargetClass
Before
Constructing TargetClass2
Construction end
After
package ch.usi.dag.disl.test.args;
import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.processorcontext.ArgumentProcessorContext;
import ch.usi.dag.disl.processorcontext.ArgumentProcessorMode;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class DiSLClass {
@AfterReturning(marker = BodyMarker.class, scope = "TargetClass.*")
public static void postcondition(MethodStaticContext sc, ArgumentProcessorContext pc) {
System.out.println("args for " + sc.thisMethodFullName() + " " + sc.thisMethodDescriptor());
Object[] args = pc.getArgs(ArgumentProcessorMode.METHOD_ARGS);
for(int i = 0 ; i < args.length; ++i) {
System.out.println(" arg[" + i + "] " + args[i]);
}
}
}
Manifest-Version: 1.0
DiSL-Classes: ch.usi.dag.disl.test.args.DiSLClass
\ No newline at end of file
package ch.usi.dag.disl.test.args;
public class TargetClass {
public void method1() {
System.out.println("This is the body of TargetClass.method1");
}
public void method2(int i, long l, float d) {
System.out.println("This is the body of TargetClass.method2");
}
public void method3(Object obj, String string) {
System.out.println("This is the body of TargetClass.method3");
}
public void method3(long l, double d, Object obj) {
System.out.println("This is the body of TargetClass.method3-1");
}
public void method4(String[] sa, int[] ia) {
System.out.println("This is the body of TargetClass.method