Search in sources :

Example 6 with ExecutionTrace

use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.

the class BranchNoveltyFunction method getDistance.

@Override
public double getDistance(TestChromosome individual1, TestChromosome individual2) {
    ExecutionResult result1 = getExecutionResult(individual1);
    ExecutionResult result2 = getExecutionResult(individual2);
    ExecutionTrace trace1 = result1.getTrace();
    ExecutionTrace trace2 = result2.getTrace();
    double difference = 0.0;
    for (Integer branch : branches) {
        if (trace1.hasTrueDistance(branch) && trace2.hasTrueDistance(branch)) {
            double distance1 = trace1.getTrueDistance(branch);
            double distance2 = trace2.getTrueDistance(branch);
            difference += Math.abs(distance1 - distance2);
        } else if (trace1.hasTrueDistance(branch) || trace2.hasTrueDistance(branch)) {
            difference += 1.0;
        }
    }
    Set<String> methods1 = trace1.getCoveredBranchlessMethods();
    Set<String> methods2 = trace2.getCoveredBranchlessMethods();
    for (String branchlessMethod : branchlessMethods) {
        if (methods1.contains(branchlessMethod) != methods2.contains(branchlessMethod)) {
            difference += 1.0;
        }
    }
    difference /= (branches.size() + branchlessMethods.size());
    return difference;
}
Also used : ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult)

Example 7 with ExecutionTrace

use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.

the class DSETestCaseLocalSearch method getCoveredBranches.

/**
 * Returns the set of covered branches by this test
 *
 * @param test
 * @return
 */
private static Set<Branch> getCoveredBranches(TestChromosome test) {
    final Set<Branch> testCoveredBranches = new HashSet<Branch>();
    ExecutionTrace trace = test.getLastExecutionResult().getTrace();
    {
        Set<Integer> coveredTrueBranchIndexesInTrace = trace.getCoveredTrueBranches();
        for (Integer branchIndex : coveredTrueBranchIndexesInTrace) {
            Branch b = new Branch(branchIndex, true);
            testCoveredBranches.add(b);
        }
    }
    {
        Set<Integer> coveredFalseBranchIndexesInTrace = trace.getCoveredFalseBranches();
        for (Integer branchIndex : coveredFalseBranchIndexesInTrace) {
            Branch b = new Branch(branchIndex, false);
            testCoveredBranches.add(b);
        }
    }
    return testCoveredBranches;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) HashSet(java.util.HashSet)

Example 8 with ExecutionTrace

use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.

the class DeprecatedTestSuiteDSE method getCoveredBranches.

/**
 * Returns the set of covered branches by this test
 *
 * @param test
 * @return
 */
private static Set<Branch> getCoveredBranches(TestChromosome test) {
    final Set<Branch> testCoveredBranches = new HashSet<Branch>();
    ExecutionTrace trace = test.getLastExecutionResult().getTrace();
    {
        Set<Integer> coveredTrueBranchIndexesInTrace = trace.getCoveredTrueBranches();
        for (Integer branchIndex : coveredTrueBranchIndexesInTrace) {
            Branch b = new Branch(branchIndex, true);
            testCoveredBranches.add(b);
        }
    }
    {
        Set<Integer> coveredFalseBranchIndexesInTrace = trace.getCoveredFalseBranches();
        for (Integer branchIndex : coveredFalseBranchIndexesInTrace) {
            Branch b = new Branch(branchIndex, false);
            testCoveredBranches.add(b);
        }
    }
    return testCoveredBranches;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) HashSet(java.util.HashSet)

Example 9 with ExecutionTrace

use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.

the class InstrumentingClassLoaderTest method testDirectInstrumentation.

@Ignore
@Test
public void testDirectInstrumentation() throws Exception {
    Class<?> originalClass = ClassLoaderTestSubject.class;
    Properties.TARGET_CLASS = originalClass.getName();
    Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
    ClassLoaderTestSubject original = new ClassLoaderTestSubject();
    ExecutionTracer.enable();
    ExecutionTracer.getExecutionTracer().clear();
    original.assess(6);
    ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
    Assert.assertTrue(execTrace.getTrueDistances().isEmpty());
    Assert.assertTrue(execTrace.getFalseDistances().isEmpty());
    TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
    Class<?> changedClass = instrumentingClassLoader.loadClass(ClassLoaderTestSubject.class.getName());
    Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
    Assert.assertTrue(changedClass.hashCode() != originalClass.hashCode());
    Assert.assertFalse(changedClass.equals(originalClass));
    Object changed = changedClass.getConstructor().newInstance();
    try {
        @SuppressWarnings("unused") ClassLoaderTestSubject casted = (ClassLoaderTestSubject) changed;
        Assert.fail();
    } catch (ClassCastException exc) {
    // expected
    }
    ExecutionTracer.getExecutionTracer().clear();
    TestUtil.invokeMethod(changed, "assess", Integer.valueOf(6));
    execTrace = ExecutionTracer.getExecutionTracer().getTrace();
    Assert.assertFalse(execTrace.getTrueDistances().isEmpty());
    Assert.assertFalse(execTrace.getFalseDistances().isEmpty());
    ExecutionTracer.getExecutionTracer().clear();
}
Also used : TestabilityTransformationClassLoader(org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader) ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with ExecutionTrace

use of org.evosuite.testcase.execution.ExecutionTrace in project evosuite by EvoSuite.

the class InstrumentingClassLoaderTest method testDependingInstrumentation.

/*
	 * Tests the child-first/parent-last property of the classloader.
	 */
@Ignore
@Test
public void testDependingInstrumentation() throws Exception {
    Class<?> originalClass = DependentClassLoaderTestSubject.class;
    Properties.TARGET_CLASS = originalClass.getName();
    Properties.PROJECT_PREFIX = originalClass.getPackage().getName();
    Properties.TARGET_CLASS_PREFIX = Properties.PROJECT_PREFIX;
    TestabilityTransformationClassLoader instrumentingClassLoader = new TestabilityTransformationClassLoader();
    Class<?> changedClass = instrumentingClassLoader.loadClass(ClassLoaderTestSubject.class.getName());
    Assert.assertEquals(instrumentingClassLoader, changedClass.getClassLoader());
    Object changed = changedClass.getConstructor().newInstance();
    ExecutionTracer.enable();
    ExecutionTracer.getExecutionTracer().clear();
    TestUtil.invokeMethod(changed, "trySomethingElse");
    ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
    execTrace = ExecutionTracer.getExecutionTracer().getTrace();
    Assert.assertFalse(execTrace.getTrueDistances().isEmpty());
    Assert.assertFalse(execTrace.getFalseDistances().isEmpty());
    ExecutionTracer.getExecutionTracer().clear();
}
Also used : TestabilityTransformationClassLoader(org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader) ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ExecutionTrace (org.evosuite.testcase.execution.ExecutionTrace)20 Ignore (org.junit.Ignore)6 Test (org.junit.Test)6 TestChromosome (org.evosuite.testcase.TestChromosome)4 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)4 HashSet (java.util.HashSet)3 Set (java.util.Set)2 TestabilityTransformationClassLoader (org.evosuite.instrumentation.testability.TestabilityTransformationClassLoader)2 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)2 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 Branch (org.evosuite.coverage.branch.Branch)1 BranchPool (org.evosuite.coverage.branch.BranchPool)1 Mutation (org.evosuite.coverage.mutation.Mutation)1 RhoCoverageFactory (org.evosuite.coverage.rho.RhoCoverageFactory)1