Skip to content

Commit

Permalink
feat: add support for max patches needed by repairnator (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed Jul 29, 2019
1 parent b49e455 commit 03c148c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Expand Up @@ -588,4 +588,18 @@ public String toString() {
", json=" + json +
'}';
}


// Dynamoth generates at most 10 patches
private int maxPatches = 10;
public int getMaxPatches() {
return maxPatches;
}
public void setMaxPatches(int v) {
if (v>1 && isOnlyOneSynthesisResult()) {
throw new IllegalStateException("for more than one patches, isOnlyOneSynthesisResult() should false");
}
this.maxPatches = v;
}

}
4 changes: 2 additions & 2 deletions nopol/src/main/java/fr/inria/lille/repair/nopol/NoPol.java
Expand Up @@ -94,7 +94,6 @@ public class NoPol {
private NopolResult nopolResult;



public NoPol(NopolContext nopolContext) {
this.startTime = System.currentTimeMillis();
this.nopolContext = nopolContext;
Expand Down Expand Up @@ -297,14 +296,15 @@ private List<Patch> runNopolProcessor(List<TestResult> tests, SourceLocation sou
// Final check: we recompile the patch and run all tests again
List<Patch> finalPatches = new ArrayList<>();
if (tmpPatches.size() > 0) {
for (int i = 0; i < tmpPatches.size(); i++) {
for (int i = 0; i < tmpPatches.size() && i < nopolContext.getMaxPatches(); i++) {
Patch patch = tmpPatches.get(i);
if (nopolContext.isSkipRegressionStep() || isOk(patch, tests, synth.getProcessor())) {
finalPatches.add(patch);
} else {
logger.debug("Could not find a valid patch in {}", sourceLocation);
}
}
logger.debug("Skipped {} patches for sake of performance", tmpPatches.size() - nopolContext.getMaxPatches());
}

return finalPatches;
Expand Down
Expand Up @@ -142,6 +142,7 @@ public List<Patch> findAngelicValuesAndBuildPatch(URL[] classpath, List<TestResu
Candidates run = synthesizer.run(remainingTime);
if (run.size() > 0) {
List<Patch> patches = new ArrayList<>();
testsOutput.debug("Collected {} potential patches", patches.size());
for (Expression expression : run) {
patches.add(new ExpressionPatch(expression, sourceLocation, type));
}
Expand Down
14 changes: 14 additions & 0 deletions nopol/src/test/java/fr/inria/lille/repair/nopol/NopolTest.java
Expand Up @@ -271,4 +271,18 @@ public void testIgnoreTestCouldCreateOtherPatches() {
assertEquals(1, result2.getPatches().size());
TestUtility.assertAgainstKnownPatches(result2.getPatches().get(0), "a == 2", "(b - a) == 2", "2 == (b - a)", "1 < (b - a)");
}

@Test
public void testDynamoth() {
NopolContext nopolContext = TestUtility.configForExample(executionType, 2);
nopolContext.setType(RepairType.CONDITIONAL);
nopolContext.setSynthesis(NopolContext.NopolSynthesis.DYNAMOTH);
nopolContext.setOnlyOneSynthesisResult(false);
NoPol nopol;

// contract: Dynamoth stops after the default max values of patches
nopol = new NoPol(nopolContext);
assertEquals(10, nopol.build().getPatches().size());
}

}

0 comments on commit 03c148c

Please sign in to comment.