|
| 1 | +package fr.inria.lille.repair.nopol; |
| 2 | + |
| 3 | +import fr.inria.lille.commons.synthesis.smt.solver.SolverFactory; |
| 4 | +import fr.inria.lille.repair.TestUtility; |
| 5 | +import fr.inria.lille.repair.common.config.NopolContext; |
| 6 | +import fr.inria.lille.repair.common.patch.Patch; |
| 7 | +import fr.inria.lille.repair.common.synth.StatementType; |
| 8 | +import org.json.JSONObject; |
| 9 | +import org.json.JSONTokener; |
| 10 | +import org.junit.Ignore; |
| 11 | +import org.junit.Test; |
| 12 | +import xxl.java.junit.TestCasesListener; |
| 13 | +import xxl.java.junit.TestSuiteExecution; |
| 14 | + |
| 15 | +import java.io.File; |
| 16 | +import java.net.URL; |
| 17 | +import java.net.URLClassLoader; |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Collection; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import static java.util.Arrays.asList; |
| 23 | +import static org.junit.Assert.assertEquals; |
| 24 | +import static org.junit.Assert.assertTrue; |
| 25 | + |
| 26 | +public class TseEvaluationTest { |
| 27 | + |
| 28 | + public boolean testShouldBeRun() { |
| 29 | + if (System.getenv("NOPOL_EVAL_TSE")==null || !new File("../nopol-experiments").exists()) { |
| 30 | + return false; |
| 31 | + } |
| 32 | + return true; |
| 33 | + } |
| 34 | + |
| 35 | + public void testTSEBug(String bug_id) throws Exception { |
| 36 | + String folder = "unknown"; |
| 37 | + if (bug_id.startsWith("cm")) { |
| 38 | + folder = "math"; |
| 39 | + } |
| 40 | + if (bug_id.startsWith("cl") || bug_id.startsWith("pl")) { |
| 41 | + folder = "lang"; |
| 42 | + } |
| 43 | + |
| 44 | + JSONTokener tokener = new JSONTokener(new File("../nopol-experiments/data/projects/"+folder+"/bugs/" + bug_id + ".json").toURL().openStream()); |
| 45 | + JSONObject root = new JSONObject(tokener); |
| 46 | + |
| 47 | + //JSONArray s = |
| 48 | + NopolContext nopolContext = new NopolContext(); |
| 49 | + String src = "../nopol-experiments/dataset/" + bug_id + "/" + root.getJSONObject("path").getString("source"); |
| 50 | + nopolContext.setProjectSourcePath(new File[]{new File(src)}); |
| 51 | + |
| 52 | + // setting the Java version of the project to repair, required for TSE_CL1 for instance |
| 53 | + if (root.has("java")) { |
| 54 | + nopolContext.setComplianceLevel(Integer.parseInt(root.getJSONObject("java").getString("version").substring(2))); |
| 55 | + } |
| 56 | + |
| 57 | + URL[] cp = new URL[root.getJSONArray("dependencies").length()+2]; |
| 58 | + cp[0] = new File("../nopol-experiments/dataset/"+bug_id+"/"+"target/classes/").toURL(); |
| 59 | + cp[1] = new File("../nopol-experiments/dataset/"+bug_id+"/"+"target/test-classes/").toURL(); |
| 60 | + for (int i = 0; i <root.getJSONArray("dependencies").length(); i++) |
| 61 | + { |
| 62 | + cp[i+2] = new File("../nopol-experiments/data/lib/"+root.getJSONArray("dependencies").getString(i)).toURL(); |
| 63 | + } |
| 64 | + |
| 65 | + if (root.has("tests")) { |
| 66 | + String[] tests = new String[root.getJSONArray("tests").length()]; |
| 67 | + for (int i = 0; i <root.getJSONArray("tests").length(); i++) |
| 68 | + { |
| 69 | + tests[i] = root.getJSONArray("tests").getString(i); |
| 70 | + } ; |
| 71 | + nopolContext.setProjectTests(tests); |
| 72 | + } |
| 73 | + |
| 74 | + nopolContext.setProjectClasspath(cp); |
| 75 | + //nopolContext.setLocalizer(NopolContext.NopolLocalizer.COCOSPOON); |
| 76 | + nopolContext.setType(StatementType.PRECONDITION); |
| 77 | + if ("condition".equals(root.getString("type"))) { |
| 78 | + nopolContext.setType(StatementType.CONDITIONAL); |
| 79 | + } |
| 80 | + SolverFactory.setSolver("z3", TestUtility.solverPath); |
| 81 | + NoPol nopol = new NoPol(nopolContext); |
| 82 | + NopolResult result = nopol.build(); |
| 83 | + |
| 84 | + assertEquals(1, result.getPatches().size()); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void test_cm1() throws Exception { |
| 89 | + if (testShouldBeRun()) testTSEBug("cm1"); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void test_cm2() throws Exception { |
| 94 | + if (testShouldBeRun()) testTSEBug("cm2"); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + public void test_cm3() throws Exception { |
| 99 | + if (testShouldBeRun()) testTSEBug("cm3"); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void test_cm4() throws Exception { |
| 104 | + if (testShouldBeRun()) testTSEBug("cm4"); |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + public void test_cm5() throws Exception { |
| 109 | + // ignored, there is a regression in Gzoltar which crashes with NPE |
| 110 | + // if (testShouldBeRun()) |
| 111 | + // testTSEBug("cm5"); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void test_cm6() throws Exception { |
| 116 | + if (testShouldBeRun()) |
| 117 | + testTSEBug("cm6"); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void test_cm7() throws Exception { |
| 122 | + if (testShouldBeRun()) |
| 123 | + testTSEBug("cm7"); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void test_cm10() throws Exception { |
| 128 | + // note that this one has a "tests" configuration which limits the scope of the search |
| 129 | + if (testShouldBeRun()) testTSEBug("cm10"); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void test_cl1() throws Exception { |
| 134 | + if (testShouldBeRun()) |
| 135 | + testTSEBug("cl1"); |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void test_cl2() throws Exception { |
| 140 | + if (testShouldBeRun()) |
| 141 | + testTSEBug("cl2"); |
| 142 | + } |
| 143 | + |
| 144 | + @Test |
| 145 | + public void test_cl3() throws Exception { |
| 146 | + if (testShouldBeRun()) |
| 147 | + testTSEBug("cl3"); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void test_cl4() throws Exception { |
| 152 | + if (testShouldBeRun()) |
| 153 | + testTSEBug("cl4"); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + public void test_cl5() throws Exception { |
| 158 | + if (testShouldBeRun()) |
| 159 | + testTSEBug("cl5"); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + public void test_cl6() throws Exception { |
| 164 | + // CL6 is a bug that cannot be repaired in the TSE paper |
| 165 | + // in the paper we say timeout |
| 166 | + // we this was a mistake, it's actually an impossible synthesis |
| 167 | + //if (testShouldBeRun()) |
| 168 | + //testTSEBug("cl6"); |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + public void test_pl1() throws Exception { |
| 173 | + if (testShouldBeRun()) testTSEBug("pl1"); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void test_pl2() throws Exception { |
| 178 | + // REGRESSION: it seems nothing is instrumented |
| 179 | + //if (testShouldBeRun()) |
| 180 | + //testTSEBug("pl2"); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + public void test_pl3() throws Exception { |
| 185 | + if (testShouldBeRun()) testTSEBug("pl3"); |
| 186 | + } |
| 187 | + |
| 188 | + @Test |
| 189 | + public void test_pl4() throws Exception { |
| 190 | + // there is only a Kali patch for PL4 |
| 191 | + // and Nopol does not return Kali patches anymore |
| 192 | + //if (testShouldBeRun()) |
| 193 | + // testTSEBug("pl4"); |
| 194 | + } |
| 195 | +} |
0 commit comments