Search in sources :

Example 1 with InstrumentingClassLoader

use of org.evosuite.instrumentation.InstrumentingClassLoader 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 InstrumentingClassLoader

use of org.evosuite.instrumentation.InstrumentingClassLoader in project evosuite by EvoSuite.

the class ParentReplacementTest method testNoVFS.

@Test
public void testNoVFS() throws ClassNotFoundException {
    RuntimeSettings.useVFS = false;
    Properties.VIRTUAL_FS = false;
    InstrumentingClassLoader cl = new InstrumentingClassLoader();
    Class<?> clazz = cl.loadClass(ExtendingFile.class.getCanonicalName());
    Class<?> parent = clazz.getSuperclass();
    Assert.assertEquals(File.class.getCanonicalName(), parent.getCanonicalName());
}
Also used : ExtendingFile(com.examples.with.different.packagename.mock.java.io.ExtendingFile) ExtendingFile(com.examples.with.different.packagename.mock.java.io.ExtendingFile) MockFile(org.evosuite.runtime.mock.java.io.MockFile) File(java.io.File) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 3 with InstrumentingClassLoader

use of org.evosuite.instrumentation.InstrumentingClassLoader in project evosuite by EvoSuite.

the class MockRuntimeLoadingTest method testReplacementMethod.

@Test
public void testReplacementMethod() throws Exception {
    RuntimeSettings.mockJVMNonDeterminism = true;
    Properties.REPLACE_CALLS = true;
    InstrumentingClassLoader cl = new InstrumentingClassLoader();
    MockFramework.enable();
    Class<?> clazz = cl.loadClass(MemoryCheck.class.getCanonicalName());
    Object mc = clazz.newInstance();
    // this is hard coded in the mock
    String expected = "500";
    Assert.assertEquals(expected, mc.toString());
}
Also used : MemoryCheck(com.examples.with.different.packagename.mock.java.lang.MemoryCheck) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader)

Example 4 with InstrumentingClassLoader

use of org.evosuite.instrumentation.InstrumentingClassLoader in project evosuite by EvoSuite.

the class InstrumentingClassLoaderTest method testClassWithStaticInitializationCallingGetPackage.

@Test
public void testClassWithStaticInitializationCallingGetPackage() throws ClassNotFoundException {
    InstrumentingClassLoader instrumentingClassLoader = new InstrumentingClassLoader();
    Class<?> stat = Class.forName("com.examples.with.different.packagename.StatInitIssue", true, instrumentingClassLoader);
}
Also used : InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 5 with InstrumentingClassLoader

use of org.evosuite.instrumentation.InstrumentingClassLoader in project evosuite by EvoSuite.

the class TestClassInitialization method checksClassIsLoadedUsingInstrumentingClassLoader.

@Test
public void checksClassIsLoadedUsingInstrumentingClassLoader() throws ClassNotFoundException {
    Properties.CLIENT_ON_THREAD = true;
    final String className = SimpleClass.class.getCanonicalName();
    TestCaseExecutor.initExecutor();
    TestGenerationContext.getInstance().resetContext();
    ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
    InstrumentingClassLoader classLoader = TestGenerationContext.getInstance().getClassLoaderForSUT();
    assertFalse(classLoader.getLoadedClasses().contains(className));
    DefaultTestCase test = buildLoadTargetClassTestCase(className);
    TestCaseExecutor.getInstance().execute(test, Integer.MAX_VALUE);
    assertTrue(classLoader.getLoadedClasses().contains(className));
}
Also used : DefaultTestCase(org.evosuite.testcase.DefaultTestCase) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Aggregations

InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)26 Test (org.junit.Test)23 TestCase (org.evosuite.testcase.TestCase)15 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)13 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)12 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)11 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)5 VariableReference (org.evosuite.testcase.variable.VariableReference)4 GenericClass (org.evosuite.utils.generic.GenericClass)3 ExtendingFile (com.examples.with.different.packagename.mock.java.io.ExtendingFile)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 NonInstrumentingClassLoader (org.evosuite.instrumentation.NonInstrumentingClassLoader)2 MockFile (org.evosuite.runtime.mock.java.io.MockFile)2 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)2 CBranchExample (com.examples.with.different.packagename.cbranch.CBranchExample)1 MemoryCheck (com.examples.with.different.packagename.mock.java.lang.MemoryCheck)1 TypeToken (com.googlecode.gentyref.TypeToken)1 File (java.io.File)1 Assertion (org.evosuite.assertion.Assertion)1