@Override public ExecutionResult getLastExecutionResult() { return theTest.getLastExecutionResult(); }
public ExecutionResult getLastRegressionExecutionResult() { return theSameTestForTheOtherClassLoader.getLastExecutionResult(); }
private int getNumExceptions(TestChromosome chromosome) { ExecutionResult result = chromosome.getLastExecutionResult(); if (result != null) return result.getNumberOfThrownExceptions(); else return 0; }
@Override public int compare(TestChromosome tc1, TestChromosome tc2) { ExecutionResult result1 = tc1.getLastExecutionResult(); ExecutionResult result2 = tc2.getLastExecutionResult(); long diff = result1.getExecutionTime() - result2.getExecutionTime(); if (diff == 0) return 0; else if (diff < 0) return -1; else return 1; }
private void backup(TestChromosome test, StringPrimitiveStatement p) { oldValue = new String(p.getValue()); oldResult = test.getLastExecutionResult(); oldChanged = test.isChanged(); }
private void backup(TestChromosome test, StringPrimitiveStatement p) { oldValue = new String(p.getValue()); oldResult = test.getLastExecutionResult(); oldChanged = test.isChanged(); }
private void addToArchive(F target, T solution) { this.uncovered.remove(target); this.covered.put(target, solution); this.removeNonCoveredTargetOfAMethod(target); this.hasBeenUpdated = true; ExecutionResult result = solution.getLastExecutionResult(); if (result != null && (result.hasTimeout() || result.hasTestException())) { AtMostOnceLogger.warn(logger, "A solution with a timeout/exception result has been added to the archive. The covered goal was " + target.toString()); } }
private ExecutionResult getExecutionResult(TestChromosome individual) { ExecutionResult origResult = individual.getLastExecutionResult(); if(origResult == null||individual.isChanged()) { origResult = runTest(individual.getTestCase()); individual.setLastExecutionResult(origResult); individual.setChanged(false); } return individual.getLastExecutionResult(); }
/** * Returns the set of predicate indexes whose true branches were covered by * the suite * * @param suite * @return */ private static Set<Integer> getCoveredTrueBranches(TestSuiteChromosome suite) { Set<Integer> covered = new LinkedHashSet<Integer>(); for (TestChromosome testChromosome : suite.getTestChromosomes()) { ExecutionResult lastResult = testChromosome.getLastExecutionResult(); if (lastResult != null) { covered.addAll(lastResult.getTrace().getCoveredTrueBranches()); } } return covered; }
/** * Returns the set of the predicate indexes whose false branch were covered * by the test suite * * @param suite * @return the set of predicate indexes whose false branch were covered */ private static Set<Integer> getCoveredFalseBranches(TestSuiteChromosome suite) { Set<Integer> covered = new LinkedHashSet<Integer>(); for (TestChromosome testChromosome : suite.getTestChromosomes()) { ExecutionResult lastResult = testChromosome.getLastExecutionResult(); if (lastResult != null) { covered.addAll(lastResult.getTrace().getCoveredFalseBranches()); } } return covered; }
/** * Execute a test case * * @param test * The test case to execute * @return Result of the execution */ protected ExecutionResult runTest(TestChromosome test) { if (!test.isChanged() && test.getLastExecutionResult() != null) return test.getLastExecutionResult(); try { ExecutionResult result = TestCaseExecutor.getInstance().execute(test.getTestCase()); return result; } catch (Exception e) { logger.error("TG: Exception caught: ", e); throw new EvosuiteError(e); } } }
/** * {@inheritDoc} */ @Override protected void calculateFitness(T c) { this.fitnessFunctions.forEach(fitnessFunction -> fitnessFunction.getFitness(c)); // if one of the coverage criterion is Criterion.EXCEPTION, then we have to analyse the results // of the execution to look for generated exceptions if (ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.EXCEPTION)) { TestChromosome testChromosome = (TestChromosome) c; ExceptionCoverageSuiteFitness.calculateExceptionInfo( Arrays.asList(testChromosome.getLastExecutionResult()), new HashMap<>(), new HashMap<>(), new HashMap<>(), new ExceptionCoverageSuiteFitness()); } this.notifyEvaluation(c); // update the time needed to reach the max coverage this.budgetMonitor.checkMaxCoverage(this.getNumberOfCoveredGoals()); }
@Override public void fitnessEvaluation(Chromosome individual) { if(individual instanceof TestSuiteChromosome) { TestSuiteChromosome suite = (TestSuiteChromosome)individual; for(TestChromosome testChromosome : suite.getTestChromosomes()) { ExecutionResult lastResult = testChromosome.getLastExecutionResult(); if(lastResult != null) { for(Integer branchId : lastResult.getTrace().getCoveredTrueBranches()) { if(!coveredTrueBranches.containsKey(branchId)) { coveredTrueBranches.put(branchId, testChromosome.getTestCase()); } } for(Integer branchId : lastResult.getTrace().getCoveredFalseBranches()) { if(!coveredFalseBranches.containsKey(branchId)) { coveredFalseBranches.put(branchId, testChromosome.getTestCase()); } } } } } }
/** {@inheritDoc} */ @Override public double getFitness(TestChromosome individual) { logger.trace("Executing test case on original"); ExecutionResult origResult = individual.getLastExecutionResult(); if (origResult == null || individual.isChanged()) { origResult = runTest(individual.test); individual.setLastExecutionResult(origResult); individual.setChanged(false); } double fitness = getFitness(individual, origResult); updateIndividual(this, individual, fitness); return fitness; }
private boolean iterate(long delta, LocalSearchObjective<TestChromosome> objective, TestChromosome test, NumericalPrimitiveStatement<T> p, int statement) { boolean improvement = false; T oldValue = p.getValue(); ExecutionResult oldResult = test.getLastExecutionResult(); p.increment(delta); logger.info("Trying increment " + delta + " of " + p.getCode()); while (objective.hasImproved(test)) { oldValue = p.getValue(); oldResult = test.getLastExecutionResult(); improvement = true; delta = 2 * delta; p.increment(delta); logger.info("Trying increment " + delta + " of " + p.getCode()); } logger.info("No improvement on " + p.getCode()); p.setValue(oldValue); test.setLastExecutionResult(oldResult); test.setChanged(false); logger.info("Final value of this iteration: " + p.getValue()); return improvement; }
/** * {@inheritDoc} */ @Override public void updateArchive(F target, T solution, double fitnessValue) { super.updateArchive(target, solution, fitnessValue); assert this.archive.containsKey(target); ExecutionResult executionResult = solution.getLastExecutionResult(); // remove all statements after an exception if (!executionResult.noThrownExceptions()) { solution.getTestCase().chop(executionResult.getFirstPositionOfThrownException() + 1); } boolean isNewCoveredTarget = this.archive.get(target) .addSolution(1.0 - FitnessFunction.normalize(fitnessValue), solution); if (isNewCoveredTarget) { this.removeNonCoveredTargetOfAMethod(target); this.hasBeenUpdated = true; } }
private int getLastMutatableStatement() { ExecutionResult result = getLastExecutionResult(); if (result != null && !result.noThrownExceptions()) { int pos = result.getFirstPositionOfThrownException(); // It may happen that pos > size() after statements have been deleted if (pos >= test.size()) return test.size() - 1; else return pos; } else { return test.size() - 1; } }
/** * <p> * isCovered * </p> * * @param tc * a {@link org.evosuite.testcase.TestChromosome} object. * @return a boolean. */ public boolean isCovered(TestChromosome tc) { if(tc.getTestCase().isGoalCovered(this)){ return true; } ExecutionResult result = tc.getLastExecutionResult(); if (result == null || tc.isChanged()) { result = runTest(tc.test); tc.setLastExecutionResult(result); tc.setChanged(false); } return isCovered(tc, result); }
/** {@inheritDoc} */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) { EnumPrimitiveStatement p = (EnumPrimitiveStatement) test.getTestCase().getStatement(statement); ExecutionResult oldResult = test.getLastExecutionResult(); oldValue = p.getValue(); for (Object value : p.getEnumValues()) { p.setValue(value); if (!objective.hasImproved(test)) { // Restore original p.setValue(oldValue); test.setLastExecutionResult(oldResult); test.setChanged(false); } else { logger.debug("Finished local search with result " + p.getCode()); return true; } } return false; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) { PrimitiveStatement<Boolean> p = (PrimitiveStatement<Boolean>) test.getTestCase().getStatement(statement); ExecutionResult oldResult = test.getLastExecutionResult(); oldValue = p.getValue(); p.setValue(!oldValue); if (!objective.hasImproved(test)) { // Restore original p.setValue(oldValue); test.setLastExecutionResult(oldResult); test.setChanged(false); return false; } else { return true; } }