Skip to content

Commit

Permalink
fix for grid5000
Browse files Browse the repository at this point in the history
  • Loading branch information
simonAllier committed Apr 8, 2014
1 parent 9eaf540 commit 20efb2c
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 96 deletions.
2 changes: 1 addition & 1 deletion grid5000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ rm -rf repo/sosie-exp
mkdir repo
sh script/git/init.sh repo

java -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar git repo
java -jar target/Sosies-generator-1.0-SNAPSHOT-jar-with-dependencies.jar git repo

sh runFromGit.sh 100 repo &
2 changes: 1 addition & 1 deletion runFromGit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ for i in `seq 1 $1`
do
for j in `seq 1 $cpu`
do
java -Xmx2000m -Dhttp.proxyHost=proxy.rennes.grid5000.fr -Dhttp.proxyPort=3128 -jar target/Diversify-statements-1.0-SNAPSHOT-jar-with-dependencies.jar $(cat propertiesFile) > out_$i_$j &
java -Xmx2000m -Dhttp.proxyHost=proxy.rennes.grid5000.fr -Dhttp.proxyPort=3128 -jar target/Sosies-generator-1.0-SNAPSHOT-jar-with-dependencies.jar $(cat propertiesFile) > out_$i_$j &
done
wait
sh script/git/push.sh $2/sosie-exp
Expand Down
57 changes: 14 additions & 43 deletions src/main/java/fr/inria/diversify/DiversifyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.*;

import fr.inria.diversify.diversification.*;
import fr.inria.diversify.statistic.CVLMetric;
import fr.inria.diversify.statistic.FailureMatrix;
import fr.inria.diversify.statistic.StatisticDiversification;
import fr.inria.diversify.transformation.TransformationOldParser;
Expand Down Expand Up @@ -240,14 +241,9 @@ protected void computeDiversifyStat(String transDir, String fileName) throws Exc
TransformationParser tf = new TransformationParser(true);
// TransformationOldParser tf = new TransformationOldParser(true);
Collection<Transformation> transformations = tf.parseDir(transDir);
long fail = transformations.stream().filter(t -> t.getStatus() == -1).count();
long sosie = transformations.stream().filter(t -> t.getStatus() == 0).count();
TransformationsWriter write = new TransformationsWriter(transformations, fileName);




// Log.info("nb stmt transformable {}",test());
Log.debug("all transformation type : {}", getAllTransformationType(transformations));
write.writeAllTransformation(null);
StatisticDiversification sd = new StatisticDiversification(transformations);
Expand All @@ -262,11 +258,13 @@ protected void computeDiversifyStat(String transDir, String fileName) throws Exc
for(String type : getAllTransformationType(transformations))
write.writeGoodTransformation(type);

Visu v = new Visu(fileName+"_visu/visu");
v.writeJSON(transformations);

FailureMatrix matrix = new FailureMatrix(transformations,DiversifyProperties.getProperty("allTestFile"));
matrix.printMatrix(fileName+"_matrix.csv");
cvlMetrics();
// Visu v = new Visu(fileName+"_visu/visu");
// v.writeJSON(transformations);

// FailureMatrix matrix = new FailureMatrix(transformations,DiversifyProperties.getProperty("allTestFile"));
// matrix.printMatrix(fileName+"_matrix.csv");
}

protected Set<String> getAllTransformationType(Collection<Transformation> transformations) {
Expand All @@ -277,46 +275,19 @@ protected Set<String> getAllTransformationType(Collection<Transformation> transf
}



// protected void computeOtherStat() throws InterruptedException {
// Util stat = new Util(codeFragments);
// try {
// System.out.println("number of not possible code fragment replace/add: " + stat.numberOfNotDiversification());
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// System.out.println("number of possible code fragment replace: "+ stat.getAllReplace().size());
// System.out.println("number of possible code fragment add: " + stat.getAllAdd().size());
// System.out.println("number of possible code fragment delete: " + stat.getAllDelete().size());
// }
//
// protected void computeCodeFragmentStatistic(String output) {
// StatisticCodeFragment stat = new StatisticCodeFragment(codeFragments);
// try {
// stat.writeStatistic(output);
// } catch (IOException e) {
// Log.error("computeCodeFragmentStatistic ", e);
// }
// }
protected void initLogLevel() {
int level = Integer.parseInt(DiversifyProperties.getProperty("logLevel"));
Log.set(level);
}


// protected int test() throws IOException {
// ICoverageReport rg = initCoverageReport();
// Util util = new Util(codeFragments);
// int count = 0;
// int count2 = 0;
// for(CodeFragment cf :codeFragments) {
// count2++;
// if(util.findStupidCandidate(cf, rg).size() != 0)
// count++;
// Log.debug("stmt {} {}", count2,count);
// }
// return count;
// }
protected void cvlMetrics() throws IOException {
CVLMetric cvl = new CVLMetric();
Log.info("object existence: {}",cvl.nbObjectExistence());
Log.info("object substitution: {}",cvl.nbObjectSubstitution());
Log.info("link existence: {}",cvl.nbLinkExistence());
Log.info("link substitution: {}",cvl.nbLinkSubstitution());
}

protected void sosieOnMultiProject() throws Exception {
// TestSosie d = new TestSosie(initTransformationQuery(), DiversifyProperties.getProperty("project"));
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fr/inria/diversify/statistic/CVLMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
public class CVLMetric {


public long nbObjectExistence() {
return DiversifyEnvironment.getAllElement(CtElement.class).size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@

import fr.inria.diversify.codeFragment.VariableVisitor;
import fr.inria.diversify.util.Log;
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtLocalVariable;
import spoon.reflect.code.CtReturn;
import spoon.reflect.code.CtStatement;
import org.json.JSONException;
import org.json.JSONObject;
import spoon.reflect.code.*;
import spoon.reflect.cu.CompilationUnit;
import spoon.reflect.cu.SourceCodeFragment;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.factory.Factory;


import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;

/**
* Created by Simon on 02/04/14.
*/
public class ShuffleStmtTransformation extends SpoonTransformation<CtBlock, CtElement> {
protected CtBlock newOrder;
List<CtStatement> newOrderStmt = new ArrayList<>();


public ShuffleStmtTransformation() {
name = "shuffleStmt";
type = "foo";
}

@Override
public void addSourceCode() throws Exception {
logInfo();

if(newOrder == null)
if(newOrderStmt == null)
buildNewOrder();

Log.debug("new order\n: {}",newOrder);
Log.debug("new order\n: {}",newOrderStmt);

SourcePosition sp = transformationPoint.getStatement(0).getPosition();
CompilationUnit compileUnit = sp.getCompilationUnit();
Expand All @@ -40,9 +45,9 @@ public void addSourceCode() throws Exception {
compileUnit.addSourceCodeFragment(new SourceCodeFragment(compileUnit.beginOfLineIndex(sp.getSourceStart()), "/**", 0));


String stmtsString = (String) newOrder.getStatements().stream()
String stmtsString = newOrderStmt.stream()
.map(stmt -> stmt.toString())
.collect(Collectors.joining(";\n"));
.collect(Collectors.joining(";\n")).toString();

sp = transformationPoint.getLastStatement().getPosition();
compileUnit = sp.getCompilationUnit();
Expand All @@ -51,8 +56,7 @@ public void addSourceCode() throws Exception {
}


protected void buildNewOrder() {
List<CtStatement> newOrderStmt = new ArrayList<>();
public void buildNewOrder() {
List<CtStatement> stmts = new ArrayList<CtStatement>(transformationPoint.getStatements());
Set<String> localVar = getLocalVariableName(transformationPoint.getStatements());

Expand All @@ -61,11 +65,19 @@ protected void buildNewOrder() {
.findAny().orElse(null);
stmts.remove(ret);

CtStatement superStmt = stmts.stream()
.filter(stmt -> stmt instanceof CtSuperAccess)
.findAny().orElse(null);
stmts.remove(superStmt);

if(superStmt != null)
newOrderStmt.add(superStmt);

Random r = new Random();
while (stmts.size() > 0) {
int randomIndex = r.nextInt(stmts.size());
CtStatement stmt = stmts.get(randomIndex);
int index = getStmtIndex(stmt, newOrderStmt, localVar);
int index = getStmtIndex(stmt, localVar);
if(index != -1) {
newOrderStmt.add(index, stmt);
stmts.remove(randomIndex);
Expand All @@ -74,13 +86,9 @@ protected void buildNewOrder() {

if(ret != null)
newOrderStmt.add(ret);

Factory factory = transformationPoint.getFactory();
newOrder = factory.Core().createBlock();
newOrder.setStatements(newOrderStmt);
}

protected int getStmtIndex(CtStatement stmt , List<CtStatement> newOrderStmt, Set<String> localVar) {
protected int getStmtIndex(CtStatement stmt , Set<String> localVar) {
VariableVisitor query = new VariableVisitor(false);
stmt.accept(query);

Expand All @@ -94,7 +102,6 @@ protected int getStmtIndex(CtStatement stmt , List<CtStatement> newOrderStmt, Se
if(localVarUsed.isEmpty())
return 0;


for(int i = 0; i <= newOrderStmt.size(); i++) {
Set<String> currentLocalVar = getLocalVariableName(stmts);
if (currentLocalVar.containsAll(localVarUsed))
Expand All @@ -114,4 +121,28 @@ protected Set<String> getLocalVariableName(List<CtStatement> stmts) {
.collect(Collectors.toSet());

}

public int[] newOrderIndex() {
int size = newOrderStmt.size();
int[] newOrderIndex = new int[size];

for(int i = 0; i < size; i++) {
int index = 0;
for(Object stmt : transformationPoint.getStatements()) {
if(newOrderStmt.get(i).toString().equals(stmt.toString())){
newOrderIndex[i] = index;
break;
}
index++;
}
}
return newOrderIndex;
}

public JSONObject toJSONObject() throws JSONException {
JSONObject object = super.toJSONObject();
object.put("newStmtOrder", Arrays.toString(newOrderIndex()));

return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Collection<Transformation> parseDir(String dir) throws IOException, JSONE
transformations.addAll(parseFile(f));
}
Log.debug("number of transformation file: {}",countFile);
Log.debug("number of transformation : {}",count);
Log.debug("number of transformation : {}",transformations.size());
Log.debug("number of parse error : {}",countError);

return transformations;
Expand Down Expand Up @@ -109,11 +109,36 @@ protected Transformation parseTransformation(JSONObject jsonObject) throws Excep
trans = parseASTDelete(jsonObject);

trans.setFailures(new ArrayList<String>());
trans.setName(type);

if(type.equals("notContextAdd"))
trans.setName("addRandom");
if(type.equals("notContextReplace"))
trans.setName("replaceRandom");

if(type.equals("notMappingVariableAdd"))
trans.setName("addReaction");
if(type.equals("notMappingVariableReplace"))
trans.setName("replaceReaction");

if(type.equals("notContextMappingVariableNameAdd"))
trans.setName("addittgenstein");
if(type.equals("notContextMappingVariableNameReplace"))
trans.setName("replaceWittgenstein");

if(type.equals("add"))
trans.setName("add");
if(type.equals("replace"))
trans.setName("replace");
if(type.equals("delete"))
trans.setName("delete");


boolean compile = jsonObject.getBoolean("setCompile");
int failure = jsonObject.getInt("Failures");
if(!compile)
trans.setStatus(-2);
else if(failure > 0)
trans.setStatus(-1);
else
trans.setStatus(failure);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected Transformation parseCvl(JSONObject jsonObject) throws Exception {
trans = parseObjectSubstitution(jsonObject);


trans.setTransformationPoint(getObject(jsonObject.getString("objectPosition"), jsonObject.getString("nodeType")));
trans.setTransformationPoint(getObject(jsonObject.getString("transformationPoint"), jsonObject.getString("nodeType")));
return trans;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ protected CVLTransformation parseObjectExistence(JSONObject jsonObject) {

protected CVLTransformation parseObjectSubstitution(JSONObject jsonObject) throws Exception {
ObjectSubstitution os = new ObjectSubstitution();
os.setTransplant(getObject(jsonObject.getString("transplantPosition"), jsonObject.getString("nodeType")));
os.setTransplant(getObject(jsonObject.getString("transplant"), jsonObject.getString("nodeType")));
return os;
}

Expand All @@ -215,7 +215,7 @@ protected CVLTransformation parseLinkSubstitution(JSONObject jsonObject) throws
String nodeType = jsonObject.getString("nodeType");
if(nodeType.equals("CtClassImpl")) {
String clName = jsonObject.getString("classOrInterfaceExistence");
CtClass cl = (CtClass) getObject(jsonObject.getString("objectPosition"), jsonObject.getString("nodeType"));
CtClass cl = (CtClass) getObject(jsonObject.getString("transformationPoint"), jsonObject.getString("nodeType"));
List<CtTypeReference> set = new ArrayList<CtTypeReference>();

if(cl.getSuperclass() != null)
Expand All @@ -229,7 +229,7 @@ protected CVLTransformation parseLinkSubstitution(JSONObject jsonObject) throws
}
}

ls.setTransplant(getObject(jsonObject.getString("transplantPosition"), nodeType));
ls.setTransplant(getObject(jsonObject.getString("transplant"), nodeType));
return ls;
}

Expand All @@ -239,7 +239,7 @@ protected CVLTransformation parseLinkExistence(JSONObject jsonObject) throws Exc
String nodeType = jsonObject.getString("nodeType");
if(nodeType.equals("CtClassImpl")) {
String clName = jsonObject.getString("classOrInterfaceExistence");
CtClass cl = (CtClass) getObject(jsonObject.getString("objectPosition"), jsonObject.getString("nodeType"));
CtClass cl = (CtClass) getObject(jsonObject.getString("transformationPoint"), jsonObject.getString("nodeType"));
List<CtTypeReference> set = new ArrayList<CtTypeReference>();

if(cl.getSuperclass() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public Transformation getTransformation() throws Exception {
Random r = new Random();
int i = r.nextInt(8);
switch (i) {
case 0: return getObjectExistence();
case 1: return getObjectSubstitution();
case 2: case 3: return getLinkExistence();
case 4: case 5: case 6: case 7: return getLinkSubstitution();
case 0: return getLinkExistence();
case 1: return getLinkSubstitution();
case 2: case 3: return getObjectExistence();
case 4: case 5: case 6: case 7: return getObjectSubstitution();
}
return null;
}
Expand Down
10 changes: 0 additions & 10 deletions utils/jbehave/5Replace.properties

This file was deleted.

10 changes: 0 additions & 10 deletions utils/jbehave/deleteReplace.properties

This file was deleted.

0 comments on commit 20efb2c

Please sign in to comment.