/** * Execute a test case * * @param test * The test case to execute * @return Result of the execution */ public static ExecutionResult runTest(TestCase test) { ExecutionResult result = new ExecutionResult(test, null); try { TestCaseExecutor executor = getInstance(); logger.debug("Executing test"); result = executor.execute(test); MaxStatementsStoppingCondition.statementsExecuted(result.getExecutedStatements()); } catch (Exception e) { logger.error("TG: Exception caught: ", e); throw new Error(e); } return result; }
@Before public void initializeExecutor() { TestCaseExecutor.getInstance().newObservers(); TestCaseExecutor.initExecutor(); }
/** {@inheritDoc} */ public ExecutionResult runTest(TestCase test) { return TestCaseExecutor.runTest(test); }
public RegressionAssertionGenerator() { super(); TestCaseExecutor.getInstance().newObservers(); TestCaseExecutor.getInstance().addObserver(primitiveObserver); TestCaseExecutor.getInstance().addObserver(comparisonObserver); TestCaseExecutor.getInstance().addObserver(sameObserver); if (!Properties.REGRESSION_DISABLE_SPECIAL_ASSERTIONS) { TestCaseExecutor.getInstance().addObserver(inspectorObserver); } TestCaseExecutor.getInstance().addObserver(fieldObserver); TestCaseExecutor.getInstance().addObserver(nullObserver); }
/** * <p> * Constructor for AssertionGenerator. * </p> */ public AssertionGenerator() { TestCaseExecutor.getInstance().addObserver(primitiveObserver); TestCaseExecutor.getInstance().addObserver(comparisonObserver); TestCaseExecutor.getInstance().addObserver(inspectorObserver); TestCaseExecutor.getInstance().addObserver(fieldObserver); TestCaseExecutor.getInstance().addObserver(nullObserver); TestCaseExecutor.getInstance().addObserver(sameObserver); if(!Properties.isRegression()) TestCaseExecutor.getInstance().addObserver(arrayObserver); TestCaseExecutor.getInstance().addObserver(arrayLengthObserver); TestCaseExecutor.getInstance().addObserver(containsTraceObserver); }
/** * <p> * inline * </p> * * @param test * a {@link org.evosuite.testcase.TestCase} object. */ public void inline(TestCase test) { this.test = test; TestCaseExecutor executor = TestCaseExecutor.getInstance(); executor.addObserver(this); executor.execute(test); executor.removeObserver(this); removeUnusedVariables(test); assert (test.isValid()); }
SymbolicObserver symbolicExecObserver = new SymbolicObserver(env); Set<ExecutionObserver> originalExecutionObservers = TestCaseExecutor.getInstance().getExecutionObservers(); TestCaseExecutor.getInstance().newObservers(); TestCaseExecutor.getInstance().addObserver(symbolicExecObserver); result = TestCaseExecutor.getInstance().execute(defaultTestCase, Properties.CONCOLIC_TIMEOUT); } finally { logger.debug("Cleaning concolic execution"); TestCaseExecutor.getInstance().setExecutionObservers(originalExecutionObservers); TestCaseExecutor.getInstance().setExecutionObservers(originalExecutionObservers);
public static List<TestCase> getFailingTests() { List<TestCase> tests = new ArrayList<TestCase>(); ContractChecker.setActive(false); TestCaseExecutor.getInstance().newObservers(); for (int i = 0; i < violations.size(); i++) { logger.debug("Writing test {}/{}", i, violations.size()); ContractViolation violation = violations.get(i); violation.minimizeTest(); TestCase test = violation.getTestCase(); //violation.addAssertion(test); tests.add(test); } return tests; }
/** * Run the test against this contract and determine whether it reports a * failure * * @param test * a {@link org.evosuite.testcase.TestCase} object. * @return a boolean. */ public boolean fails(TestCase test) { ContractChecker.setActive(false); TestCaseExecutor executor = TestCaseExecutor.getInstance(); SingleContractChecker checker = new SingleContractChecker(this); executor.addObserver(checker); TestCaseExecutor.runTest(test); executor.removeObserver(checker); //ContractChecker.setActive(true); return !checker.isValid(); }
@Test public void testRuntimeException() { String targetClass = SourceExceptions.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.REPLACE_CALLS = true; Properties.CRITERION = new Properties.Criterion[]{Properties.Criterion.LINE, Properties.Criterion.EXCEPTION}; EvoSuite evosuite = new EvoSuite(); String[] command = new String[]{"-generateSuite", "-class", targetClass}; Object result = evosuite.parseCommandLine(command); GeneticAlgorithm<?> ga = getGAFromResult(result); TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual(); Assert.assertNotNull(best); TestCaseExecutor.getInstance().initExecutor(); for(TestChromosome test : best.getTestChromosomes()) { ExecutionResult executionResult = TestCaseExecutor.getInstance().runTest(test.getTestCase()); test.setLastExecutionResult(executionResult); } String code = best.toString(); Assert.assertTrue("Code:\n"+code, code.contains("verifyException(\"com.examples.with.different.packagename.mock.java.lang.SourceExceptions\",")); Assert.assertTrue("Code:\n"+code, code.contains("verifyException(\"com.examples.with.different.packagename.mock.java.lang.SourceExceptions$Foo\",")); } }
@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)); }
/** * Constructor - fitness is specific to a method * * @param goal the coverage goal * @throws IllegalArgumentException */ public InputCoverageTestFitness(InputCoverageGoal goal) throws IllegalArgumentException { if (goal == null) { throw new IllegalArgumentException("goal cannot be null"); } this.goal = goal; // add the observer to TestCaseExecutor if it is not included yet boolean hasObserver = false; TestCaseExecutor executor = TestCaseExecutor.getInstance(); for (ExecutionObserver ob : executor.getExecutionObservers()){ if (ob instanceof InputObserver){ hasObserver = true; break; } } if (!hasObserver){ InputObserver observer = new InputObserver(); executor.addObserver(observer); logger.info("Added observer for input coverage"); } }
ExceptionMapGenerator.initializeExceptionMap(Properties.TARGET_CLASS); TestCaseExecutor.initExecutor(); try { initializeTargetClass(); writeJUnitFailingTests(); TestCaseExecutor.pullDown();
private TestSuiteChromosome generateTests() { // Make sure target class is loaded at this point TestCluster.getInstance(); ContractChecker checker = null; if (Properties.CHECK_CONTRACTS) { checker = new ContractChecker(); TestCaseExecutor.getInstance().addObserver(checker); } TestGenerationStrategy strategy = TestSuiteGeneratorHelper.getTestGenerationStrategy(); TestSuiteChromosome testSuite = strategy.generateTests(); if (Properties.CHECK_CONTRACTS) { TestCaseExecutor.getInstance().removeObserver(checker); } StatisticsSender.executedAndThenSendIndividualToMaster(testSuite); TestSuiteGeneratorHelper.getBytecodeStatistics(); ClientServices.getInstance().getClientNode().publishPermissionStatistics(); writeObjectPool(testSuite); /* * PUTGeneralizer generalizer = new PUTGeneralizer(); for (TestCase test * : tests) { generalizer.generalize(test); // ParameterizedTestCase put * = new ParameterizedTestCase(test); } */ return testSuite; }
Properties.JUNIT_CHECK_ON_SEPARATE_PROCESS = false; TestCaseExecutor.initExecutor(); //needed because it gets pulled down after the search
private boolean hasExceededResources() { if (TestCaseExecutor.getInstance().getNumStalledThreads() >= Properties.MAX_STALLED_THREADS) { logger.info("* Too many stalled threads: " + TestCaseExecutor.getInstance().getNumStalledThreads() + " / " + Properties.MAX_STALLED_THREADS); return true; } Runtime runtime = Runtime.getRuntime(); long freeMem = runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory(); if (freeMem < Properties.MIN_FREE_MEM) { logger.trace("* Running out of memory, calling GC with memory left: " + freeMem + " / " + runtime.maxMemory()); System.gc(); freeMem = runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory(); if (freeMem < Properties.MIN_FREE_MEM) { logger.info("* Running out of memory, giving up: " + freeMem + " / " + runtime.maxMemory() + " - need " + Properties.MIN_FREE_MEM); return true; } else { logger.trace("* Garbage collection recovered sufficient memory: " + freeMem + " / " + runtime.maxMemory()); } } return false; }
private TestCaseExecutor() { executor = Executors.newSingleThreadExecutor(this); newObservers(); }
/** * Execute a test case on a new scope * * @param tc * a {@link org.evosuite.testcase.TestCase} object. * @return a {@link org.evosuite.testcase.execution.ExecutionResult} object. */ public ExecutionResult execute(TestCase tc) { ExecutionResult result = execute(tc, Properties.TIMEOUT); return result; }
resetObservers(); ExecutionObserver.setCurrentTest(tc); MaxTestsStoppingCondition.testExecuted(); while (isInStaticInit()) { logger.info("Run is finished - " + currentThread.isAlive() + ": " + getNumStalledThreads());
/** * <p> * Getter for the field <code>instance</code>. * </p> * * @return a {@link org.evosuite.testcase.execution.TestCaseExecutor} * object. */ public static synchronized TestCaseExecutor getInstance() { if (instance == null) instance = new TestCaseExecutor(); return instance; }