Search in sources :

Example 1 with SystemExitException

use of org.evosuite.runtime.System.SystemExitException in project evosuite by EvoSuite.

the class TestRunnable method executeStatements.

/**
 * Iterate over all statements in the test case, and execute them one at a time
 *
 * @param result
 * @param out
 * @param num
 * @throws TimeoutException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws VMError
 * @throws EvosuiteError
 */
private void executeStatements(ExecutionResult result, PrintStream out, AtomicInteger num) throws TimeoutException, InvocationTargetException, IllegalAccessException, InstantiationException, VMError, EvosuiteError {
    for (Statement s : test) {
        if (Thread.currentThread().isInterrupted() || Thread.interrupted()) {
            logger.info("Thread interrupted at statement " + num + ": " + s.getCode());
            throw new TimeoutException();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Executing statement " + s.getCode());
        }
        ExecutionTracer.statementExecuted();
        informObservers_before(s);
        /*
			 * Here actually execute a statement of the SUT
			 */
        Throwable exceptionThrown = s.execute(scope, out);
        if (exceptionThrown != null) {
            // -------------------------------------------------------
            if (exceptionThrown instanceof VMError) {
                throw (VMError) exceptionThrown;
            }
            if (exceptionThrown instanceof EvosuiteError) {
                throw (EvosuiteError) exceptionThrown;
            }
            /*
				 * This is implemented in this way due to ExecutionResult.hasTimeout()
				 */
            if (exceptionThrown instanceof TestCaseExecutor.TimeoutExceeded) {
                logger.debug("Test timed out!");
                exceptionsThrown.put(test.size(), exceptionThrown);
                result.setThrownExceptions(exceptionsThrown);
                result.reportNewThrownException(test.size(), exceptionThrown);
                result.setTrace(ExecutionTracer.getExecutionTracer().getTrace());
                break;
            }
            // keep track if the exception and where it was thrown
            exceptionsThrown.put(num.get(), exceptionThrown);
            // --------------------------------------------------------
            if (ExecutionTracer.getExecutionTracer().getLastException() == exceptionThrown) {
                result.explicitExceptions.put(num.get(), true);
            } else {
                result.explicitExceptions.put(num.get(), false);
            }
            // --------------------------------------------------------
            printDebugInfo(s, exceptionThrown);
            /*
				 * If an exception is thrown, we stop the execution of the test case, because the internal state could be corrupted, and not
				 * possible to verify the behavior of any following function call. Predicate should be true by default
				 */
            if (Properties.BREAK_ON_EXCEPTION || exceptionThrown instanceof SystemExitException) {
                informObservers_after(s, exceptionThrown);
                break;
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Done statement " + s.getCode());
        }
        informObservers_after(s, exceptionThrown);
        num.incrementAndGet();
    }
    // end of loop
    informObservers_finished(result);
// TODO
}
Also used : Statement(org.evosuite.testcase.statements.Statement) SystemExitException(org.evosuite.runtime.System.SystemExitException) TimeoutException(java.util.concurrent.TimeoutException) VMError(org.evosuite.dse.VMError)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)1 VMError (org.evosuite.dse.VMError)1 SystemExitException (org.evosuite.runtime.System.SystemExitException)1 Statement (org.evosuite.testcase.statements.Statement)1