Skip to content

Commit

Permalink
[refactor] renaming entity
Browse files Browse the repository at this point in the history
  • Loading branch information
martinezmatias committed Sep 12, 2018
1 parent 009ae37 commit 6b253cc
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 18 deletions.
Expand Up @@ -43,7 +43,7 @@
* @author Matias Martinez
*
*/
public class EvalSimpleTOSBTApproach extends ExhaustiveIngredientBasedEngine {
public class EvalSimpleValueTOSBTApproach extends ExhaustiveIngredientBasedEngine {

public int MAX_HOLES_PER_MODIFICATION_POINT;
public int MAX_GENERATIONS = ConfigurationProperties.getPropertyInt("maxGeneration");
Expand All @@ -58,7 +58,7 @@ public class EvalSimpleTOSBTApproach extends ExhaustiveIngredientBasedEngine {

protected HoleOrder holeOrderEngine = null;

public EvalSimpleTOSBTApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade)
public EvalSimpleValueTOSBTApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade)
throws JSAPException {
super(mutatorExecutor, projFacade);
targetElementProcessors.add(new CtExpressionIngredientSpaceProcessor());
Expand Down
@@ -1,6 +1,7 @@
package fr.inria.astor.approaches.tos.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.martiansoftware.jsap.JSAPException;
Expand Down Expand Up @@ -32,7 +33,7 @@
* @author Matias Martinez
*
*/
public class EvalTOSBTApproach extends EvalSimpleTOSBTApproach {
public class EvalTOSBTApproach extends EvalSimpleValueTOSBTApproach {

public EvalTOSBTApproach(MutationSupporter mutatorExecutor, ProjectRepairFacade projFacade) throws JSAPException {
super(mutatorExecutor, projFacade);
Expand Down Expand Up @@ -70,14 +71,15 @@ public boolean analyzeModificationPoint(ProgramVariant parentVariant, Modificati

MapCounter<String> typesOfCandidatesCombined = getTypesOfExpressions(evaluatedExpressions);

log.debug("types Of Candidates: " + typesOfCandidatesCombined.sorted());
log.info("types Of Candidates: " + typesOfCandidatesCombined.sorted());

log.info("Start clustering");
// Key: test name, value list of clusters, each cluster is a list of
// evaluated expressions
MapList<String, List<EvaluatedExpression>> cluster = clusterCandidatesByValue(evaluatedExpressions);

List<CtCodeElement> holesFromMP = calculateHolesSorted(iModifPoint);
log.debug("Total holes: " + holesFromMP.size());
log.info("For MP " + iModifPoint.identified + ", total holes: " + holesFromMP.size());
int maxMinutes = ConfigurationProperties.getPropertyInt("maxtime");

int nrholefrommpi = 0;
Expand All @@ -100,6 +102,10 @@ public boolean analyzeModificationPoint(ProgramVariant parentVariant, Modificati
"\n\n---hole-> `" + iHole + "`, return type " + aholeExpression.getType().box().getQualifiedName()
+ "--hole type: " + iHole.getClass().getCanonicalName());

int[] sizesofClusters = cluster.values().stream().mapToInt(i -> i.size()).toArray();

log.info("number of clusters " + Arrays.toString(sizesofClusters));

// Simplification
int nrtestfromholei = 0;
for (String i_testName : cluster.keySet()) {
Expand Down Expand Up @@ -130,7 +136,7 @@ public boolean analyzeModificationPoint(ProgramVariant parentVariant, Modificati
continue;
}

log.debug(String.format("Analyzing value %d/%d of test %d from hole %d", valuefromtesti,
log.info(String.format("--Analyzing value %d/%d of test %d from hole %d", valuefromtesti,
clustersOfTest.size(), nrtestfromholei, nrholefrommpi));

currentStat.increment(GeneralStatEnum.NR_GENERATIONS);
Expand Down Expand Up @@ -188,6 +194,17 @@ private MapCounter<String> getTypesOfExpressions(Candidates candidatesnew) {
}

private String returnExpressionType(Expression expression) {

if (expression.getValue() == null) {
log.debug("Value of expression " + expression + " is null");
return null;
}

if (expression.getValue().getType() == null) {
log.debug("Type of expression value " + expression.getValue() + " is null");
return null;
}

String type = expression.getValue().getType().toString().replace("class ", "");

if ("com.sun.tools.jdi.ObjectReferenceImpl".equals(type)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/configuration.properties
Expand Up @@ -193,7 +193,7 @@ resetmodel=true
#
parsesourcefromoriginal=false
#
max_synthesis_step=2000
max_synthesis_step=10000
#
synthesis_depth=3
#
Expand Down
103 changes: 92 additions & 11 deletions src/test/java/fr/inria/astor/test/repair/approaches/EvalTOSBTTest.java
Expand Up @@ -12,7 +12,7 @@
import org.junit.Ignore;
import org.junit.Test;

import fr.inria.astor.approaches.tos.core.EvalSimpleTOSBTApproach;
import fr.inria.astor.approaches.tos.core.EvalSimpleValueTOSBTApproach;
import fr.inria.astor.approaches.tos.core.EvalTOSBTApproach;
import fr.inria.astor.approaches.tos.core.UpdateParentDiffOrderFromJSON;
import fr.inria.astor.core.entities.ModificationPoint;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void testBT_Math85_SingleValue() throws Exception {

CommandSummary command = MathCommandsTests.getMath85Command();
command.command.put("-mode", "custom");
command.command.put("-customengine", EvalSimpleTOSBTApproach.class.getCanonicalName());
command.command.put("-customengine", EvalSimpleValueTOSBTApproach.class.getCanonicalName());
command.command.put("-maxgen", "0");
command.command.put("-loglevel", "DEBUG");
command.command.put("-scope", "local");
Expand All @@ -60,8 +60,8 @@ public void testBT_Math85_SingleValue() throws Exception {
AstorMain main = new AstorMain();
main.execute(command.flat());

assertTrue(main.getEngine() instanceof EvalSimpleTOSBTApproach);
EvalSimpleTOSBTApproach approach = (EvalSimpleTOSBTApproach) main.getEngine();
assertTrue(main.getEngine() instanceof EvalSimpleValueTOSBTApproach);
EvalSimpleValueTOSBTApproach approach = (EvalSimpleValueTOSBTApproach) main.getEngine();
// Retrieve the buggy if condition.
ModificationPoint mp198 = approach.getVariants().get(0).getModificationPoints().stream()
.filter(e -> (e.getCodeElement().getPosition().getLine() == 198 && e.getCodeElement().getPosition()
Expand Down Expand Up @@ -198,7 +198,7 @@ public void testBT_Math85_1_Evolve_Cluster_MultiExecution() throws Exception {
public void testBT_Math_70_1() throws Exception {
CommandSummary command = MathCommandsTests.getMath70Command();
command.command.put("-mode", "custom");
command.command.put("-customengine", EvalSimpleTOSBTApproach.class.getCanonicalName());
command.command.put("-customengine", EvalSimpleValueTOSBTApproach.class.getCanonicalName());
command.command.put("-maxgen", "100");
command.command.put("-loglevel", "DEBUG");
command.command.put("-scope", "local");
Expand Down Expand Up @@ -272,7 +272,7 @@ public void testBT_Math85_SingleValue_SingleChange() throws Exception {

CommandSummary command = MathCommandsTests.getMath85Command();
command.command.put("-mode", "custom");
command.command.put("-customengine", EvalSimpleTOSBTApproach.class.getCanonicalName());
command.command.put("-customengine", EvalSimpleValueTOSBTApproach.class.getCanonicalName());
command.command.put("-maxgen", "0");
command.command.put("-loglevel", "DEBUG");
command.command.put("-scope", "local");
Expand All @@ -284,8 +284,8 @@ public void testBT_Math85_SingleValue_SingleChange() throws Exception {
AstorMain main = new AstorMain();
main.execute(command.flat());

assertTrue(main.getEngine() instanceof EvalSimpleTOSBTApproach);
EvalSimpleTOSBTApproach approach = (EvalSimpleTOSBTApproach) main.getEngine();
assertTrue(main.getEngine() instanceof EvalSimpleValueTOSBTApproach);
EvalSimpleValueTOSBTApproach approach = (EvalSimpleValueTOSBTApproach) main.getEngine();
// Retrieve the buggy if condition.
ModificationPoint mp198 = approach.getVariants().get(0).getModificationPoints().stream()
.filter(e -> (e.getCodeElement().getPosition().getLine() == 198 && e.getCodeElement().getPosition()
Expand Down Expand Up @@ -314,7 +314,7 @@ public void testBT_Math85_SingleValue_UpdateParent() throws Exception {

CommandSummary command = MathCommandsTests.getMath85Command();
command.command.put("-mode", "custom");
command.command.put("-customengine", EvalSimpleTOSBTApproach.class.getCanonicalName());
command.command.put("-customengine", EvalSimpleValueTOSBTApproach.class.getCanonicalName());
command.command.put("-maxgen", "0");
command.command.put("-loglevel", "DEBUG");
command.command.put("-scope", "local");
Expand All @@ -328,8 +328,8 @@ public void testBT_Math85_SingleValue_UpdateParent() throws Exception {
AstorMain main = new AstorMain();
main.execute(command.flat());

assertTrue(main.getEngine() instanceof EvalSimpleTOSBTApproach);
EvalSimpleTOSBTApproach approach = (EvalSimpleTOSBTApproach) main.getEngine();
assertTrue(main.getEngine() instanceof EvalSimpleValueTOSBTApproach);
EvalSimpleValueTOSBTApproach approach = (EvalSimpleValueTOSBTApproach) main.getEngine();

assertTrue(approach.getHoleOrderEngine() instanceof UpdateParentDiffOrderFromJSON);

Expand Down Expand Up @@ -608,6 +608,36 @@ public void testBT_Math74_Cluster_UpdateParent_Repair() throws Exception {
// double hNew = t;
}

@Test
public void testBT_Math74_Evolve() throws Exception {
int maxSolutions = 4;
File filef = new File("src/test/resources/changes_analisis_frequency.json");
assertTrue(filef.exists());

CommandSummary command = MathCommandsTests.getMath74Command();
command.command.put("-mode", "custom");
command.command.put("-maxgen", "100000");
command.command.put("-loglevel", "INFO");
command.command.put("-scope", "local");
command.command.put("-stopfirst", "true");
command.command.put("-flthreshold", "0.24");
command.command.put("-parameters",

"clustercollectedvalues:true:disablelog:false:maxnumbersolutions:" + maxSolutions
+ ":maxsolutionsperhole:1:sortholes:true:pathjsonfrequency:" + filef.getAbsolutePath()
+ ":holeorder:" + UpdateParentDiffOrderFromJSON.class.getName() + ":customengine:"
+ EvalTOSBTApproach.class.getCanonicalName());

AstorMain main = new AstorMain();
main.execute(command.flat());

assertTrue(main.getEngine() instanceof EvalTOSBTApproach);
EvalTOSBTApproach approach = (EvalTOSBTApproach) main.getEngine();

assertEquals(AstorOutputStatus.STOP_BY_PATCH_FOUND, approach.getOutputStatus());

}

@Test
public void testBT_Math85_Cluster_Evolve_bug_stuck() throws Exception {

Expand Down Expand Up @@ -942,6 +972,57 @@ public void testBT_Math32_notcollected_closed() throws Exception {

}

@Test
public void testBT_Math32_NPE_returnExpressionType() throws Exception {
int maxSolutions = 4;
File filef = new File("src/test/resources/changes_analisis_frequency.json");
assertTrue(filef.exists());

CommandSummary command = MathCommandsTests.getMath32Command();
command.command.put("-mode", "custom");
command.command.put("-maxgen", "0");
command.command.put("-loglevel", "DEBUG");
command.command.put("-scope", "local");
command.command.put("-stopfirst", "true");
command.command.put("-flthreshold", "0.1");
command.command.put("-saveall", "false");
command.command.put("-parameters",

"disablelog:true:maxnumbersolutions:" + maxSolutions
+ ":maxsolutionsperhole:1:sortholes:true:pathjsonfrequency:" + filef.getAbsolutePath()
+ ":holeorder:" + UpdateParentDiffOrderFromJSON.class.getName() + ":customengine:"
+ EvalTOSBTApproach.class.getCanonicalName() + ":skipfitnessinitialpopulation:true");
// clustercollectedvalues:true:
AstorMain main = new AstorMain();
main.execute(command.flat());

assertTrue(main.getEngine() instanceof EvalTOSBTApproach);
EvalTOSBTApproach approach = (EvalTOSBTApproach) main.getEngine();
//
ModificationPoint mp4 = approach.getVariants().get(0).getModificationPoints().stream()
.filter(e -> e.getCtClass().getSimpleName().equals("PolygonsSet")
&& e.getCodeElement().getPosition().getLine() == 330)
.findFirst().get();

System.out.println("Mp 4: \n" + mp4.getCodeElement().toString());

assertEquals("return null", mp4.getCodeElement().toString());

assertEquals(3, mp4.identified);

approach.getVariants().get(0).getModificationPoints().clear();
approach.getVariants().get(0).getModificationPoints().add(mp4);

assertEquals(1, approach.getVariants().get(0).getModificationPoints().size());

approach.MAX_GENERATIONS = 1000;
approach.startEvolution();
approach.atEnd();
assertTrue(main.getEngine().getSolutions().isEmpty());
assertEquals(AstorOutputStatus.EXHAUSTIVE_NAVIGATED, approach.getOutputStatus());

}

@Test
public void testBT_Math42_connection_close() throws Exception {
int maxSolutions = 4;
Expand Down

0 comments on commit 6b253cc

Please sign in to comment.