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();
}
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());
}
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());
}
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);
}
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));
}
Aggregations