Search in sources :

Example 1 with TestClusterGenerator

use of org.evosuite.setup.TestClusterGenerator in project evosuite by EvoSuite.

the class TestGenerationContext method resetContext.

public void resetContext() {
    logger.info("*** Resetting context");
    // A fresh context needs a fresh class loader to make sure we can
    // re-instrument classes
    classLoader = new InstrumentingClassLoader();
    if (!DBManager.getInstance().isWasAccessed()) {
        DBManager.getInstance().setSutClassLoader(classLoader);
    }
    TestCaseExecutor.pullDown();
    ExecutionTracer.getExecutionTracer().clear();
    // TODO: BranchPool should not be static
    BranchPool.getInstance(classLoader).reset();
    RemoveFinalClassAdapter.reset();
    LinePool.reset();
    MutationPool.clear();
    // TODO: Clear only pool of current classloader?
    GraphPool.clearAll();
    DefUsePool.clear();
    // TODO: This is not nice
    for (ClassLoader cl : CFGMethodAdapter.methods.keySet()) CFGMethodAdapter.methods.get(cl).clear();
    // TODO: Clear only pool of current classloader?
    BytecodeInstructionPool.clearAll();
    // TODO: After this, the test cluster is empty until
    // DependencyAnalysis.analyse is called
    TestCluster.reset();
    CastClassManager.getInstance().clear();
    ConcreteClassAnalyzer.getInstance().clear();
    // This counts the current level of recursion during test generation
    org.evosuite.testcase.TestFactory.getInstance().reset();
    MaxStatementsStoppingCondition.setNumExecutedStatements(0);
    GlobalTimeStoppingCondition.forceReset();
    MutationTimeoutStoppingCondition.resetStatic();
    // Forget the old SUT
    Properties.resetTargetClass();
    TestCaseExecutor.initExecutor();
    Archive.getArchiveInstance().reset();
    // Constant pool
    ConstantPoolManager.getInstance().reset();
    ObjectPoolManager.getInstance().reset();
    CarvingManager.getInstance().clear();
    // TODO: Why are we doing this?
    if (Properties.INSTRUMENT_CONTEXT || ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.DEFUSE) || ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.IBRANCH)) {
        // Properties.Criterion.CBRANCH)) {
        try {
            testClusterGenerator = new TestClusterGenerator(DependencyAnalysis.getInheritanceTree());
            testClusterGenerator.generateCluster(DependencyAnalysis.getCallGraph());
        } catch (RuntimeException e) {
            logger.error(e.getMessage(), e);
        } catch (ClassNotFoundException e) {
            logger.error(e.getMessage(), e);
        }
    }
    if (Properties.CHECK_CONTRACTS) {
        FailingTestSet.changeClassLoader(classLoader);
    }
    ContractChecker.setActive(true);
    SystemInUtil.resetSingleton();
    JOptionPaneInputs.resetSingleton();
    Runtime.resetSingleton();
    MethodCallReplacementCache.resetSingleton();
    Injector.reset();
    DSEStats.clear();
    // keep the list of initialized classes (clear them when needed in
    // the system test cases)
    final List<String> initializedClasses = ClassReInitializer.getInstance().getInitializedClasses();
    ClassReInitializer.resetSingleton();
    ClassReInitializer.getInstance().addInitializedClasses(initializedClasses);
    InspectorManager.resetSingleton();
    ModifiedTargetStaticFields.resetSingleton();
}
Also used : InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader)

Example 2 with TestClusterGenerator

use of org.evosuite.setup.TestClusterGenerator in project evosuite by EvoSuite.

the class TestFinalPrimitiveFieldIsNotAddedToCluster method test.

/**
 * As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
 * of static fields in the target class, the purpose of this test case is to
 * check that the TestClusterGenerator indeed does not include these fields.
 *
 * @throws ClassNotFoundException
 * @throws RuntimeException
 */
@Test
public void test() throws ClassNotFoundException, RuntimeException {
    Properties.TARGET_CLASS = FinalPrimitiveField.class.getCanonicalName();
    Properties.RESET_STATIC_FINAL_FIELDS = true;
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
    DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
    InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
    TestClusterGenerator gen = new TestClusterGenerator(tree);
    assertNotNull(gen);
    TestCluster cluster = TestCluster.getInstance();
    List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
    assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) InheritanceTree(org.evosuite.setup.InheritanceTree) TestCluster(org.evosuite.setup.TestCluster) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) FinalPrimitiveField(com.examples.with.different.packagename.clinit.FinalPrimitiveField) Test(org.junit.Test)

Example 3 with TestClusterGenerator

use of org.evosuite.setup.TestClusterGenerator in project evosuite by EvoSuite.

the class TestFinalReferenceFieldIsNotAddedToCluster method test.

/**
 * As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
 * of static fields in the target class, the purpose of this test case is to
 * check that the TestClusterGenerator indeed does not include these fields.
 *
 * @throws ClassNotFoundException
 * @throws RuntimeException
 */
@Test
public void test() throws ClassNotFoundException, RuntimeException {
    Properties.TARGET_CLASS = FinalReferenceField.class.getCanonicalName();
    Properties.RESET_STATIC_FINAL_FIELDS = true;
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
    DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
    InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
    TestClusterGenerator gen = new TestClusterGenerator(tree);
    assertNotNull(gen);
    TestCluster cluster = TestCluster.getInstance();
    List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
    assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) FinalReferenceField(com.examples.with.different.packagename.clinit.FinalReferenceField) InheritanceTree(org.evosuite.setup.InheritanceTree) TestCluster(org.evosuite.setup.TestCluster) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) Test(org.junit.Test)

Aggregations

TestClusterGenerator (org.evosuite.setup.TestClusterGenerator)3 InheritanceTree (org.evosuite.setup.InheritanceTree)2 TestCluster (org.evosuite.setup.TestCluster)2 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)2 Test (org.junit.Test)2 FinalPrimitiveField (com.examples.with.different.packagename.clinit.FinalPrimitiveField)1 FinalReferenceField (com.examples.with.different.packagename.clinit.FinalReferenceField)1 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)1