Search in sources :

Example 16 with ExecutionTrace

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

the class TestExecutionTracer method testLesserThan.

@Ignore
@Test
public void testLesserThan() {
    final Integer branchId = 4;
    final String methodName = "lesserThan_IF_CMPGE";
    ExecutionTrace execTrace = execute(methodName, 5, 5);
    Assert.assertEquals(methodName + signature, BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId).getMethodName());
    Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), 1.0);
    Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), 0.0);
    execTrace = execute(methodName, 5, 6);
    Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), 0.0);
    Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), 1.0);
}
Also used : ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with ExecutionTrace

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

the class TestExecutionTracer method testGreaterThan.

@Ignore
@Test
public void testGreaterThan() {
    final Integer branchId = 2;
    final String methodName = "greaterThan_IF_CMPLE";
    ExecutionTrace execTrace = execute(methodName, 5, 5);
    Assert.assertEquals(methodName + signature, BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId).getMethodName());
    Assert.assertEquals(1.0, execTrace.getTrueDistance(branchId), DELTA);
    Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), DELTA);
    execTrace = execute(methodName, 6, 5);
    Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), DELTA);
    Assert.assertEquals(1.0, execTrace.getFalseDistance(branchId), DELTA);
}
Also used : ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with ExecutionTrace

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

the class TestExecutionTracer method testGreaterEqual.

@Ignore
@Test
public void testGreaterEqual() {
    final Integer branchId = 1;
    final String methodName = "greaterEqual_IF_CMPLT";
    ExecutionTrace execTrace = execute(methodName, 5, 5);
    Assert.assertEquals(methodName + signature, BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branchId).getMethodName());
    Assert.assertEquals(0.0, execTrace.getTrueDistance(branchId), DELTA);
    Assert.assertEquals(1.0, execTrace.getFalseDistance(branchId), DELTA);
    execTrace = execute(methodName, 5, 6);
    Assert.assertEquals(1.0, execTrace.getTrueDistance(branchId), DELTA);
    Assert.assertEquals(0.0, execTrace.getFalseDistance(branchId), DELTA);
}
Also used : ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with ExecutionTrace

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

the class TestExecutionTracer method execute.

private ExecutionTrace execute(String methodName, Integer val1, Integer val2) {
    try {
        ExecutionTracer.enable();
        Class<?> targetClass = classTransformer.instrumentClass(fullyQualifiedTargetClass);
        Constructor<?> constructor = targetClass.getConstructor();
        Object target = constructor.newInstance();
        Method method = targetClass.getMethod(methodName, Integer.class, Integer.class);
        method.invoke(target, val1, val2);
        ExecutionTrace execTrace = ExecutionTracer.getExecutionTracer().getTrace();
        ExecutionTracer.getExecutionTracer().clear();
        return execTrace;
    } catch (Exception exc) {
        throw new RuntimeException(exc);
    }
}
Also used : ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) Method(java.lang.reflect.Method)

Example 20 with ExecutionTrace

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

the class ClassReInitializer method reInitializeClassesAfterTestExecution.

/**
 * This method is invoked after a test execution has ended. The classes to
 * be resetted will depend on the value of the reset_a
 *
 * @param executedTestCase
 * @param testCaseResult
 */
public void reInitializeClassesAfterTestExecution(TestCase executedTestCase, ExecutionResult testCaseResult) {
    // first collect the initialized classes during this test execution
    final ExecutionTrace trace = testCaseResult.getTrace();
    List<String> classesInitializedDuringTestExecution = trace.getInitializedClasses();
    this.addInitializedClasses(classesInitializedDuringTestExecution);
    // re-initialized. Therefore, we should return
    if (initializedClasses.isEmpty()) {
        return;
    } else {
        // second, re-initialize classes
        if (reset_all_observed_classes) {
            ClassReInitializeExecutor.getInstance().resetClasses(initializedClasses);
        } else {
            // reset only classes that were "observed" to have some
            // GETSTATIC/PUTSTATIC updating their state during test
            // execution
            List<String> classesToReset = new LinkedList<String>();
            classesToReset.addAll(trace.getClassesWithStaticWrites());
            if (Properties.RESET_STATIC_FIELD_GETS) {
                classesToReset.addAll(trace.getClassesWithStaticReads());
            }
            HashSet<String> moreClassesForReset = getMoreClassesToReset(executedTestCase, testCaseResult);
            classesToReset.addAll(moreClassesForReset);
            // sort classes to reset
            Collections.sort(classesToReset);
            ClassLoader loader = null;
            if (executedTestCase instanceof DefaultTestCase) {
                DefaultTestCase defaultTestCase = (DefaultTestCase) executedTestCase;
                ClassLoader changedClassLoader = defaultTestCase.getChangedClassLoader();
                if (changedClassLoader != null) {
                    loader = changedClassLoader;
                }
            }
            if (loader == null) {
                ClassReInitializeExecutor.getInstance().resetClasses(classesToReset);
            } else {
                ClassReInitializeExecutor.getInstance().resetClasses(classesToReset, loader);
            }
        }
    }
}
Also used : ExecutionTrace(org.evosuite.testcase.execution.ExecutionTrace) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) LinkedList(java.util.LinkedList)

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