Esempio n. 1
0
 private Map<SourceLocation, List<TestResult>> getTestListPerStatement() {
   Map<SourceLocation, List<TestResult>> results = new HashMap<>();
   List<TestResult> testResults = gZoltar.getGzoltar().getTestResults();
   for (int i = 0; i < testResults.size(); i++) {
     TestResult testResult = testResults.get(i);
     List<ComponentCount> components = testResult.getCoveredComponents();
     for (int j = 0; j < components.size(); j++) {
       Statement component = (Statement) components.get(j).getComponent();
       SourceLocation sourceLocation =
           new SourceLocation(
               component.getMethod().getParent().getLabel(), component.getLineNumber());
       if (!results.containsKey(sourceLocation)) {
         results.put(sourceLocation, new ArrayList<TestResult>());
       }
       results.get(sourceLocation).add(testResult);
     }
   }
   return results;
 }
Esempio n. 2
0
  /*
   * First algorithm of Nopol,
   * build the initial model
   * apply only one modification
   * build
   * try to find patch
   */
  private List<Patch> solveWithMultipleBuild(
      Collection<Statement> statements,
      Map<SourceLocation, List<TestResult>> testListPerStatement) {
    List<Patch> patches = new ArrayList<>();

    for (Iterator<Statement> iterator = statements.iterator();
        iterator.hasNext()
            &&
            // limit the execution time
            System.currentTimeMillis() - startTime
                <= TimeUnit.MINUTES.toMillis(Config.INSTANCE.getMaxTime()); ) {
      Statement statement = iterator.next();
      if (((StatementExt) statement).getEf() == 0) {
        continue;
      }
      /*if(((StatementExt)statement).getNf() != 0) {
      	continue;
      }*/
      try {
        if (isInTest(statement)) continue;
        NoPol.currentStatement = statement;
        logger.debug("Analysing {}", statement);
        SourceLocation sourceLocation =
            new SourceLocation(
                statement.getMethod().getParent().getName(), statement.getLineNumber());
        Synthesizer synth =
            new SynthesizerFactory(sourceFiles, spooner, type).getFor(sourceLocation);

        if (synth == Synthesizer.NO_OP_SYNTHESIZER) {
          continue;
        }

        List<TestResult> tests = testListPerStatement.get(sourceLocation);

        Set<String> failingClassTest = new HashSet<>();
        for (int i = 0; i < tests.size(); i++) {
          TestResult testResult = tests.get(i);
          if (!testResult.wasSuccessful()) {
            failingClassTest.add(testResult.getName().split("#")[0]);
          }
        }
        Collection<TestCase> failingTest =
            failingTests(failingClassTest.toArray(new String[0]), new URLClassLoader(classpath));

        if (failingTest.isEmpty()) {
          continue;
        }
        Patch patch =
            synth.buildPatch(classpath, tests, failingTest, Config.INSTANCE.getMaxTimeBuildPatch());
        if (isOk(patch, gZoltar.getGzoltar().getTestResults(), synth.getProcessor())) {
          patches.add(patch);
          if (isSinglePatch()) {
            break;
          }
        } else {
          logger.debug("Could not find a patch in {}", statement);
        }
      } catch (RuntimeException re) {
        re.printStackTrace();
      }
    }
    return patches;
  }