Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
simonAllier committed Oct 21, 2013
1 parent d6b2fd3 commit dda84c7
Show file tree
Hide file tree
Showing 23 changed files with 189 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target
.idea
.DS_Store
/output_diversify/
/output_sosie/
/result/
Expand Down
2 changes: 1 addition & 1 deletion grid5000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ git pull
mvn clean package
java -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar git repo

sh runFromGit.sh 100 &
sh script/runFromGit.sh 100 &
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions src/main/java/fr/inria/diversify/sosie/Logger/LogWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ public static void writeError(int id,Thread thread, String className, String met
}
}

public static void writeException(int id,Thread thread, String className, String methodSignature, Object exception) {
FileWriter fileWriter = null;
try {
fileWriter = init(thread);
} catch (IOException e) {
e.printStackTrace();
}
try {
fileWriter.append("$$$\n");
fileWriter.append("ST");
fileWriter.append(separator);
fileWriter.append(id+"");
fileWriter.append(separator);
fileWriter.append(className);
fileWriter.append(separator);
fileWriter.append(methodSignature);

fileWriter.append(separator);
if(exception != null)
fileWriter.append(exception.toString());
else
fileWriter.append("NullException");

}
catch (IOException e) {
e.printStackTrace();
}
}

public static void close() {
for (FileWriter flw : fileWriters.values())
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean isToBeProcessed(CtStatement candidate) {
return
CtIf.class.isAssignableFrom(candidate.getClass())
|| CtLoop.class.isAssignableFrom(candidate.getClass())
|| CtTry.class.isAssignableFrom(candidate.getClass())
|| CtThrow.class.isAssignableFrom(candidate.getClass())
;
}

Expand All @@ -49,8 +49,8 @@ public boolean hasStaticParent(CtElement el) {

public void process(CtStatement statement) {
count++;
if (CtTry.class.isAssignableFrom(statement.getClass())) {
instruCatch((CtTry) statement);
if (CtThrow.class.isAssignableFrom(statement.getClass())) {
instruThrow((CtThrow) statement);
} else {
instruLoopOrIf(statement);
}
Expand Down Expand Up @@ -105,9 +105,23 @@ private void instruLoopOrIf(CtStatement statement) {
}
}

private void instruThrow(CtThrow throwStmt) {
String snippet = "{\nfr.inria.diversify.sosie.logger.LogWriter.writeException(" + count + ",Thread.currentThread(),\"" +
getClass(throwStmt).getQualifiedName() + "\",\"" + getMethod(throwStmt).getSignature() + "\"," +
throwStmt.getThrownExpression() + ");\n";
SourcePosition sp = throwStmt.getPosition();
CompilationUnit compileUnit = sp.getCompilationUnit();
int index = compileUnit.beginOfLineIndex(sp.getSourceStart());
compileUnit.addSourceCodeFragment(new SourceCodeFragment(index, snippet, 0));

snippet = "\n}\n";

index = compileUnit.nextLineIndex(sp.getSourceEnd());
compileUnit.addSourceCodeFragment(new SourceCodeFragment(index, snippet, 0));
}


private void instruCatch(CtTry tryStmt) {
Log.info("instruCath");
Log.info(tryStmt.toString());
List<CtCatch> catchList = tryStmt.getCatchers();
for (CtCatch catchStmt : catchList) {
if(getMethod(tryStmt) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fr.inria.diversify.sosie.logger.processor;

import spoon.processing.AbstractProcessor;
import spoon.reflect.declaration.CtMethod;

/**
* User: Simon
* Date: 10/21/13
* Time: 9:27 AM
*/
public class TestLoggingInstrumenter extends AbstractProcessor<CtMethod> {


@Override
public void process(CtMethod element) {

element.getAnnotation();
//To change body of implemented methods use File | Settings | File Templates.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ protected void same() throws IOException {

protected void diff() throws Exception {
String startPointString = DiversifyProperties.getProperty("startPoint");
int count = 0;
int i =0;
for(File f : (new File(dirSosie).listFiles())) {
i++;
Log.info("i {}",i);
try {
// Log.info("log files {}",f);
File startPoint = new File(f.getAbsolutePath()+"/"+startPointString);
Expand All @@ -75,14 +79,19 @@ protected void diff() throws Exception {
Log.info(f.getName());
Log.info(diff.report());
diff.toDot(f.getName()+".dot");
if(!diff.sameVar()) {
count++;
Log.info("i: "+count);
}
}
else
else
Log.info("same trace");
} catch (Exception e) {
Log.error("error",e);
e.printStackTrace();
}


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected int[][] findDivergence(int syncroRange, int startOriginal, int startSo
*/
protected int[][] findDivergence(int syncroRange, int start1, int start2, PointSequence ps1, PointSequence ps2) {
int bound = Math.min(ps1.size(), ps2.size());
if(bound == 0)
return null;
int[][] divergence = new int[bound][2];
int i = 0;
divergence[i][0] = start1;
Expand Down
78 changes: 41 additions & 37 deletions src/main/java/fr/inria/diversify/sosie/compare/Diff.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public boolean sameTraceAndVar() {
return true;
}

public boolean sameVar() {

for (Set<VariableDiff> vars : diffVar.values())
if (!vars.isEmpty())
return false;

return true;
}

public boolean hasMatch(PointSequence original) {
return match.containsKey(original);
}
Expand All @@ -84,7 +93,6 @@ public String report() {
}

return report;

}

protected int findDiversificationIndex(PointSequence sequence) {
Expand All @@ -98,78 +106,74 @@ public void toDot(String fileName) throws IOException {
FileWriter fw = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fw);


bw.write("digraph G {\n");
for (PointSequence ps : match.keySet())
toDot(bw, ps);
bw.write(toDot(ps));

bw.write("}");
bw.close();
}


protected void toDot(BufferedWriter writer, PointSequence original) throws IOException {
protected String toDot( PointSequence original) throws IOException {
if(match.get(original) == null)
return;
return "";

StringBuilder builder = new StringBuilder();
PointSequence sosie = match.get(original);
int[][] div = divergence.get(original);
int y = 1;
Point precedent = original.get(0);
writer.write(original.toDot() +"\n");
writer.write(original.hashCode() + " -> " +precedent.hashCode()+"\n");
writer.write(precedent.toDot(1, y,getVariableDiffFor(original, 0))+"\n");

int i = 0;
int start1 = 0;
int start2 = 0;
boolean toString = false;

Point precedent = original.get(0);
builder.append(original.toDot() + "\n");
builder.append(original.hashCode() + " -> " + precedent.hashCode() + "\n");
builder.append(precedent.toDot(getVariableDiffFor(original, 0)) + "\n");

while(i < div.length) {
Point next = original.get(start1);
Set<VariableDiff> varD = getVariableDiffFor(original, div[i][0]);
if(!varD.isEmpty())
toString = true;

if(start1 == div[i][0] && start2 == div[i][1]) {
writer.write(precedent.hashCode() + " -> " + next.hashCode()+"\n");
builder.append(precedent.hashCode() + " -> " + next.hashCode()+"\n");
precedent = next;
writer.write(precedent.toDot(1,y,getVariableDiffFor(original, div[i][0]))+"\n");
builder.append(precedent.toDot(varD)+"\n");
start1++;
start2++;
i++;
}
else {
writeDotBranch(writer,precedent, original.get(div[i][0]),start1,div[i][0], original);
writeDotBranch(writer,precedent, original.get(div[i][0]),start2,div[i][1], sosie);
// Point branchNext = precedent;
// int j = start1;
// for(; j < div[i][0]; j++) {
// writer.write(branchNext.hashCode() + " -> " + original.get(j).hashCode()+"\n");
// branchNext = original.get(j);
// writer.write(branchNext.toDot(1, y, new HashSet<VariableDiff>()));
// }
// writer.write(branchNext.hashCode() + " -> " + original.get(div[i][0]).hashCode()+"\n");
// branchNext = precedent;
// j = start2;
// for(; j < div[i][1]; j++) {
// writer.write(branchNext.hashCode() + " -> " + sosie.get(j).hashCode()+"\n");
// branchNext = sosie.get(j);
// writer.write(branchNext.toDot(1,y,new HashSet<VariableDiff>()));
// }
// writer.write(branchNext.hashCode() + " -> " + original.get(div[i][0]).hashCode()+"\n");
precedent = original.get(div[i][0]);
writer.write(precedent.toDot(0,10,getVariableDiffFor(original, div[i][0])));
toString = true;
Point endBranch = original.get(div[i][0]);
writeDotBranch(builder,precedent, endBranch,start1,div[i][0], original);
writeDotBranch(builder,precedent, endBranch,start2,div[i][1], sosie);
precedent = endBranch;
builder.append(precedent.toDot(varD));
i++;
start1 = div[i][0];
start2 = div[i][1];
}
}
if(toString)
return builder.toString();
return "";
}

protected void writeDotBranch(BufferedWriter writer, Point branchNext, Point endBranch, int i, int borne, PointSequence ps) throws IOException {
protected void writeDotBranch(StringBuilder builder, Point branchNext, Point endBranch, int i, int borne, PointSequence ps) throws IOException {
for(; i < borne; i++) {
writer.write(branchNext.hashCode() + " -> " + ps.get(i).hashCode()+"\n");
builder.append(branchNext.hashCode() + " -> " + ps.get(i).hashCode() + "\n");
branchNext = ps.get(i);
writer.write(branchNext.toDot(1, 0, new HashSet<VariableDiff>()));
builder.append(branchNext.toDot(new HashSet<VariableDiff>()));
}
writer.write(branchNext.hashCode() + " -> " + endBranch.hashCode()+"\n");
builder.append(branchNext.hashCode() + " -> " + endBranch.hashCode() + "\n");
}


protected Set<VariableDiff> getVariableDiffFor(PointSequence ps, int index) {
Set<VariableDiff> set = new HashSet<VariableDiff>();
for (VariableDiff varD : diffVar.get(ps)) {
Expand All @@ -178,4 +182,4 @@ protected Set<VariableDiff> getVariableDiffFor(PointSequence ps, int index) {
}
return set;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected void buildFrom(String string) {
}

@Override
public String toDot(int x, int y, Set<VariableDiff> varDiff) {
return null; //To change body of implemented methods use File | Settings | File Templates.
public String toDot(Set<VariableDiff> varDiff) {
return null;
}

public boolean sameValue(Point sPoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void buildFrom(String string) {
}

@Override
public String toDot(int x, int y,Set<VariableDiff> varsDiff) {
public String toDot(Set<VariableDiff> varsDiff) {
String dot = hashCode() + " ";
dot += "[\n label =";
if(varsDiff.isEmpty())
Expand All @@ -62,7 +62,7 @@ public String toDot(int x, int y,Set<VariableDiff> varsDiff) {
dot += "\\n"+vf.toDot();
dot += "\"\n,color=\"red\",";
}
dot += "\npos=\"" + x + "," + y + "!\"\n];";
dot += "\n];";
return dot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public int getId() {
return id;
}

public abstract String toDot(int x, int y, Set<VariableDiff> varDiff);
public abstract String toDot(Set<VariableDiff> varDiff);
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public void parseFile(File file) throws IOException {
addPoint(tmp);
}



protected void addPoint(String stringPoint) {
if(stringPoint.startsWith("ST"))
if(stringPoint.startsWith("----------------------------------ST"))
cacthPoints.add(new CatchPoint(stringPoint));
else
conditionalPoints.add(new ConditionalPoint(stringPoint));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public void run() {
invoker.setOutputHandler(psh);
invoker.setErrorHandler(psh);
try {
Log.debug("invoke maven");
invoker.execute(request);
if(clojureTest)
parseClojureResult(os.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ protected CodeFragment findCodeFragment(JSONObject jsonObject) throws Exception
}
if (cf == null) {
//TODO exception
// System.out.println(jsonObject.get("Position"));
// System.out.println(jsonObject.get("SourceCode"));
throw new Exception();
}
return cf;
Expand Down
Loading

0 comments on commit dda84c7

Please sign in to comment.