Commit 62408d43 authored by František Haas's avatar František Haas

completed dispatch tests

added evaluation server to disl.py
added dispatch example
parent ff824b3e
......@@ -84,6 +84,14 @@ values of local variables, object instance in member methods, method arguments
or current exceptions.
--------------------------------------------------------------------------------
-- dispatch
--------------------------------------------------------------------------------
This example shows how to evaluate instrumented code on evaluation jvm. For
more details try running this example directly using disl.py and supplying
'c_out' and 'e_out' options.
================================================================================
= HOW TO RUN THE EXAMPLE
================================================================================
......
lib.path=../../../build
dislserver.path=${lib.path}/disl-server.jar
dislre.server.path=${lib.path}/dislre-server.jar
dislre.dispatch.path=${lib.path}/dislre-dispatch.jar
asm.lib=asm-debug-all-4.0.jar
asm.path=${lib.path}/${asm.lib}
......
<project name="disl-example" default="run" basedir=".">
<target name="clean">
<ant antfile="dispatch/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="dynamic/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="guard/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="marker/build.xml" target="clean" useNativeBasedir="true" />
......@@ -9,6 +10,7 @@
</target>
<target name="run">
<ant antfile="dispatch/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="dynamic/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="guard/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="marker/build.xml" target="run" useNativeBasedir="true" />
......
......@@ -30,31 +30,65 @@ def disl_home():
return os.getenv("DISL_HOME")
######################################################################
# LIB_SUFFIX
######################################################################
def lib_suffix():
if platform.system() == "Darwin":
return ".jnilib"
else:
return ".so"
######################################################################
# GENERAL_PARSER
######################################################################
def general_parser(parser):
group = parser.add_argument_group("GENERAL")
# positional variant of i for simplicity
# both cannot be set at once
group.add_argument("instr",
parser.add_argument("instr",
default=None,
nargs="?",
help="path to jar containing disl instrumentation code, same as '-i'")
group.add_argument("-i",
# positional variant of c_app for simplicity
# both cannot be set at once
parser.add_argument("app",
default=None,
nargs="*",
help="client jar or class and its arguments, same as '-c_app'")
parser.add_argument("-d",
default=disl_home(),
dest="disl_home",
help="disl home directory")
parser.add_argument("-cs",
action="store_true",
default=True,
help="set to start client and server")
parser.add_argument("-cse",
action="store_true",
default=False,
help="set to start client, server and remote evaluation")
parser.add_argument("-i",
dest="instrumentation",
default=None,
metavar="PATH",
help="path to jar containing disl instrumentation code, same as 'instr'")
group.add_argument("-t",
parser.add_argument("-t",
dest="test_dir",
default=None,
metavar="PATH",
help="directory to run in, default=current")
#parser.add_argument("-p",
# action="store_true",
# default=False,
# dest="print_namespace",
# help="show all set options and default values")
return
......@@ -62,21 +96,8 @@ def general_parser(parser):
# CLIENT_PARSER
######################################################################
def client_parser(parser):
parser.add_argument("-c",
action="store_true",
default=False,
dest="client",
help="set to start the server")
group = parser.add_argument_group("CLIENT")
# positional variant of c_app for simplicity
# both cannot be set at once
group.add_argument("app",
default=None,
nargs="*",
help="client jar or class and its arguments, same as '-c_app'")
group.add_argument("-c_opts",
action="append",
default=[],
......@@ -91,21 +112,9 @@ def client_parser(parser):
nargs="+",
help="client jar or class and its arguments, same as 'app'")
if platform.system() == "Darwin":
group.add_argument("-c_cagent",
default=VARIABLE_DISL_HOME+"/build/libdislagent.jnilib",
metavar="PATH",
help="path to c-agent library")
else:
group.add_argument("-c_cagent",
default=VARIABLE_DISL_HOME+"/build/libdislagent.so",
metavar="PATH",
help="path to c-agent library")
group.add_argument("-c_jagent",
default=VARIABLE_DISL_HOME+"/build/disl-agent.jar",
metavar="PATH",
help="path to java-agent library")
#############################
# additional arguments follow
#############################
group.add_argument("-c_out",
default=None,
......@@ -124,12 +133,6 @@ def client_parser(parser):
# SERVER_PARSER
######################################################################
def server_parser(parser):
parser.add_argument("-s",
action="store_true",
default=False,
dest="server",
help="set to start the to be instrumented client application")
group = parser.add_argument_group("SERVER")
group.add_argument("-s_opts",
......@@ -139,17 +142,26 @@ def server_parser(parser):
nargs="+",
help="java options of the server")
group.add_argument('-s_jar',
default=VARIABLE_DISL_HOME+"/build/disl-server.jar",
metavar="PATH",
help="path to disl server jar")
group.add_argument("-s_args",
action="append",
default=[],
metavar="A",
nargs="+",
help="arguments to the server application")
group.add_argument("-s_out",
default=None,
metavar="PATH",
help="file to save server stdout to")
group.add_argument("-s_err",
default=None,
metavar="PATH",
help="file to save server stderr to")
#############################
# additional arguments follow
#############################
group.add_argument("-s_debug",
action="store_true",
......@@ -188,12 +200,6 @@ def server_parser(parser):
# EVALUATION_PARSER
######################################################################
def evaluation_parser(parser):
parser.add_argument("-e",
action="store_true",
default=False,
dest="evaluation",
help="set to start the remote instrumentation evaluation server")
group = parser.add_argument_group("EVALUATION")
group.add_argument("-e_opts",
......@@ -209,6 +215,20 @@ def evaluation_parser(parser):
nargs="+",
metavar="A",
help="arguments to the evaluation server application")
group.add_argument("-e_out",
default=None,
metavar="PATH",
help="file to save evaluation stdout to")
group.add_argument("-e_err",
default=None,
metavar="PATH",
help="file to save evaluation stderr to")
#############################
# additional arguments follow
#############################
group.add_argument("-e_debug",
action="store_true",
......@@ -234,9 +254,8 @@ def documentation_parser(parser):
This script is a DiSL client application, server and evaluation server starter.
By default a client application that will be instrumented and the server that
will instrument the application will be started. To specify what should be
started switch '-c', -'s and '-e' options. If any of these is switched then
default values are ignored and only specified module is started.
will instrument the application will be started. To start remote evaluation
server too. Specify '-cse' option.
To pass option like arguments (starting with dash) one must either use equal
sign or positional variant of the argument if it's present. For example
......@@ -253,9 +272,9 @@ variable.
EXAMPLES:
To execute the example application run following:
./disl.py -s -c -i=instr/build/disl-instr.jar -c_app=-jar c_app=app/build/example-app.jar
or
./disl.py -- instr/build/disl-instr.jar -jar app/build/example-app.jar
or
./disl.py -cs -i=instr/build/disl-instr.jar -c_app=-jar c_app=app/build/example-app.jar
"""
######################################################################
......@@ -263,18 +282,6 @@ or
######################################################################
def make_parser():
parser = argparse.ArgumentParser()
parser.add_argument("-p",
action="store_true",
default=False,
dest="print_namespace",
help="show all set options and default values")
parser.add_argument("-d",
default=disl_home(),
dest="disl_home",
help="disl home directory")
general_parser(parser)
client_parser(parser)
server_parser(parser)
......@@ -313,16 +320,6 @@ def flatten_all(object):
def parse_arguments(parser):
args = parser.parse_args()
# substite ${DISL_HOME}
if args.c_cagent.startswith(VARIABLE_DISL_HOME):
args.c_cagent = args.c_cagent.replace(VARIABLE_DISL_HOME, args.disl_home)
if args.c_jagent.startswith(VARIABLE_DISL_HOME):
args.c_jagent = args.c_jagent.replace(VARIABLE_DISL_HOME, args.disl_home)
if args.s_jar.startswith(VARIABLE_DISL_HOME):
args.s_jar = args.s_jar.replace(VARIABLE_DISL_HOME, args.disl_home)
args.c_opts = flatten_all(args.c_opts)
args.c_app = flatten_all(args.c_app)
args.app = flatten_all(args.app)
......@@ -360,52 +357,104 @@ def parse_arguments(parser):
parser.error("-c_app and app set both")
if args.app is not None:
args.c_app = args.app
# by default run client and server
if args.client is False and args.server is False and args.evaluation is False:
args.client = True
args.server = True
if args.print_namespace:
for key in args.__dict__:
value = args.__dict__[key]
print key + "=" + str(value)
#if args.print_namespace:
# for key in args.__dict__:
# value = args.__dict__[key]
# print key + "=" + str(value)
return args
######################################################################
# RUN_SERVER
# TRY_KILL
######################################################################
def run_server(args, parser):
if args.instrumentation is None:
parser.error("argument instr (-i) is required to run the client")
def try_kill(pid_file_name):
try:
with open(".server.pid", "r") as pid_file:
with open(pid_file_name, "r") as pid_file:
pid = pid_file.readline()
kill = Popen(["kill", pid], stdout=PIPE, shell=False)
except IOError:
pass
######################################################################
# TRY_REMOVE_FILE
######################################################################
def try_remove_file(file_name):
if os.path.isfile(file_name):
os.remove(file_name)
######################################################################
# RUN
######################################################################
def run(cmd, out, err):
out_f = None
err_f = None
if out is not None:
out_f = open(out, "w")
if err is not None:
err_f = open(err, "w")
process = Popen(cmd, stdout=out_f, stderr=err_f, shell=False)
return process
######################################################################
# RUN_SERVER
######################################################################
def run_server(args, parser):
if args.instrumentation is None:
parser.error("argument instr (-i) is required to run the client")
try_kill(".server.pid")
s_jar = args.disl_home+"/build/disl-server.jar"
s_class = "ch.usi.dag.dislserver.DiSLServer"
s_cmd = ["java"]
s_cmd+= args.s_opts
s_cmd+= ["-cp", args.instrumentation + ":" + args.s_jar]
s_cmd+= ["-cp", args.instrumentation + ":" + s_jar]
s_cmd+= [s_class]
s_cmd+= args.s_args
#print s_cmd
server = Popen(s_cmd, shell=False)
server = run(s_cmd, args.s_out, args.s_err)
with open(".server.pid", "w") as pid_file:
pid_file.write(str(server.pid))
return
time.sleep(3)
######################################################################
# RUN_EVALUATION
######################################################################
def run_evaluation(args, parser):
if args.instrumentation is None:
parser.error("argument instr (-i) is required to run the client")
try_kill(".evaluation.pid")
e_jar = args.disl_home+"/build/dislre-server.jar"
e_class = "ch.usi.dag.dislreserver.DiSLREServer"
e_cmd = ["java"]
e_cmd+= args.s_opts
e_cmd+= ["-Xms1G", "-Xmx2G"]
e_cmd+= ["-cp", args.instrumentation + ":" + e_jar]
e_cmd+= [e_class]
e_cmd+= args.e_args
#print e_cmd
evaluation = run(e_cmd, args.e_out, args.e_err)
with open(".evaluation.pid", "w") as pid_file:
pid_file.write(str(evaluation.pid))
return
......@@ -419,34 +468,36 @@ def run_client(args, parser):
if args.instrumentation is None:
parser.error("argument instr (-i) is required to run the client")
cagent = args.disl_home+"/build/libdislagent"+lib_suffix()
eagent = args.disl_home+"/build/libdislreagent"+lib_suffix()
jagent = args.disl_home+"/build/disl-agent.jar"
dispatch = args.disl_home+"/build/dislre-dispatch.jar"
c_cmd = ["java"]
c_cmd+= args.c_opts
c_cmd+= ["-agentpath:"+args.c_cagent]
c_cmd+= ["-javaagent:"+args.c_jagent]
c_cmd+= ["-Xbootclasspath/a:"+args.c_jagent+":"+args.instrumentation]
c_cmd+= ["-agentpath:"+cagent]
if args.cse == True:
c_cmd+= ["-agentpath:"+eagent]
c_cmd+= ["-javaagent:"+jagent]
if args.cse == True:
c_cmd+= ["-Xbootclasspath/a:"+jagent+":"+args.instrumentation+":"+dispatch]
else:
c_cmd+= ["-Xbootclasspath/a:"+jagent+":"+args.instrumentation]
c_cmd+= args.c_app
#print c_cmd
c_out_f = None
c_err_f = None
if args.c_out is not None:
c_out_f = open(args.c_out, "w")
if args.c_err is not None:
c_err_f = open(args.c_err, "w")
client = Popen(c_cmd, stdout=c_out_f, stderr=c_err_f, shell=False)
client = run(c_cmd, args.c_out, args.c_err)
client.wait()
try:
with open(".server.pid", "r") as pid_file:
pid = pid_file.readline()
kill = Popen(["kill", pid], stdout=PIPE, shell=False)
except IOError:
pass
os.remove(".server.pid")
try_kill(".server.pid")
try_kill(".evaluation.pid")
try_remove_file(".server.pid")
try_remove_file(".evaluation.pid")
return
......@@ -461,10 +512,14 @@ def main():
if args.test_dir is not None:
os.chdir(args.test_dir)
if args.server == True:
if args.cs == True:
run_server(args, parser)
if args.cse == True:
run_evaluation(args, parser)
if args.client == True:
if args.cs == True or args.cse == True:
time.sleep(3)
run_client(args, parser)
return
......
<project name="example-app" default="package" basedir=".">
<target name="compile">
<mkdir dir="bin" />
<javac srcdir="src" destdir="bin" debug="true" includeAntRuntime="false">
</javac>
</target>
<target name="package" depends="compile">
<mkdir dir="build" />
<jar basedir="bin" destfile="build/example-app.jar">
<manifest>
<attribute name="Main-Class" value="Main" />
</manifest>
</jar>
</target>
<target name="clean">
<delete dir="bin" />
<delete dir="build" />
</target>
</project>
public class Main {
public void empty() {
}
public static void main(String[] args) {
System.out.println("app: main");
Main m = new Main();
m.empty();
}
}
<project name="disl-example" default="prepare-all" basedir=".">
<target name="prepare-all">
<ant antfile="app/build.xml" target="package" useNativeBasedir="true" />
<ant antfile="instr/build.xml" target="package" useNativeBasedir="true" />
</target>
<target name="clean">
<ant antfile="app/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="instr/build.xml" target="clean" useNativeBasedir="true" />
</target>
<target name="run" depends="prepare-all">
<exec executable="../disl.py">
<arg value="-cse" />
<!-- <arg value="-c_out=client.out" /> -->
<!-- <arg value="-e_out=evaluation.out" /> -->
<arg value="--" />
<arg value="instr/build/disl-instr.jar" />
<arg value="-jar" />
<arg value="app/build/example-app.jar" />
</exec>
</target>
</project>
<project name="example-disl" default="package" basedir=".">
<property file="../../build.properties" />
<path id="buildpath">
<pathelement location="${asm.path}" />
<pathelement location="${dislserver.path}" />
<pathelement location="${dislre.server.path}" />
<pathelement location="${dislre.dispatch.path}" />
</path>
<target name="compile">
<mkdir dir="bin" />
<javac srcdir="src" destdir="bin" debug="true" includeAntRuntime="false">
<classpath refid="buildpath" />
</javac>
</target>
<target name="package" depends="compile" description="create instrumentation package">
<mkdir dir="build"/>
<jar jarfile="build/${instr.jar.name}"
basedir="bin"
excludes="MANIFEST.MF"
manifest="src/MANIFEST.MF">
</jar>
</target>
<target name="clean">
<delete dir="bin" />
<delete dir="build" />
</target>
</project>
import ch.usi.dag.dislreserver.remoteanalysis.RemoteAnalysis;
import ch.usi.dag.dislreserver.shadow.ShadowClass;
import ch.usi.dag.dislreserver.shadow.ShadowObject;
import ch.usi.dag.dislreserver.shadow.ShadowString;
import ch.usi.dag.dislreserver.shadow.ShadowThread;
// NOTE that this class is not static anymore
public class CodeExecuted extends RemoteAnalysis {
long totalExecutedBytecodes = 0;
public void bytecodesExecuted(final int count) {
totalExecutedBytecodes += count;
}
// FIXME
//public void testingBasic(final boolean b, final byte by, final char c, final short s, final int i, final long l,
// final float f, final double d) {
public void testingBasic(final boolean b, final byte by, final char c, final short s, final int i, final long l) {
if(b != true) {
throw new RuntimeException("Incorect transfer of boolean");
}
if(by != (byte) 125) {
throw new RuntimeException("Incorect transfer of byte");
}
if(c != 's') {