/** * Try to kill (and then join) the SUT threads. Killing the SUT threads is * important, because some spawn threads could just wait on objects/locks, * and so make the test case executions always last TIMEOUT ms. */ public void killAndJoinClientThreads() throws IllegalStateException { threadStopper.killAndJoinClientThreads(); }
/** * <p> * After the test case is executed, if any SUT thread is still running, we * will wait for their termination. To identify which thread belong to SUT, * before test case execution we should check which are the threads that are * running. * </p> * <p> * WARNING: The sandbox might prevent accessing thread informations, so best * to call this method from outside this class * </p> */ public void storeCurrentThreads() { threadStopper.storeCurrentThreads(); }
/** * <p> * Constructor for TestRunnable. * </p> * * @param tc * a {@link org.evosuite.testcase.TestCase} object. * @param scope * a {@link org.evosuite.testcase.execution.Scope} object. * @param observers * a {@link java.util.Set} object. */ public TestRunnable(TestCase tc, Scope scope, Set<ExecutionObserver> observers) { test = tc; this.scope = scope; this.observers = observers; runFinished = false; KillSwitch killSwitch = new KillSwitch() { @Override public void setKillSwitch(boolean kill) { ExecutionTracer.setKillSwitch(kill); } }; Set<String> threadsToIgnore = new LinkedHashSet<>(); threadsToIgnore.add(TestCaseExecutor.TEST_EXECUTION_THREAD); threadsToIgnore.addAll(Arrays.asList(Properties.IGNORE_THREADS)); threadStopper = new ThreadStopper(killSwitch, threadsToIgnore, Properties.TIMEOUT); }
@Test public void testTimer() throws InterruptedException{ ThreadStopper stopper = new ThreadStopper(KillSwitchHandler.getInstance(), 1000); stopper.storeCurrentThreads(); stopper.startRecordingTime(); stopper.killAndJoinClientThreads(); Assert.assertTrue(isThreadRunning(TimerClass.NAME)); stopper.storeCurrentThreads(); stopper.startRecordingTime(); stopper.killAndJoinClientThreads(); Assert.assertFalse(isThreadRunning(TimerClass.NAME));
@Before public void initTestCase(){ threadStopper.storeCurrentThreads(); threadStopper.startRecordingTime(); org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); org.evosuite.runtime.GuiSupport.setHeadless(); org.evosuite.runtime.Runtime.getInstance().resetRuntime(); org.evosuite.runtime.agent.InstrumentingAgent.activate(); }
threadStopper.startRecordingTime(); result.setExecutionTime(System.currentTimeMillis() - threadStopper.getStartTime()); result.setExecutedStatements(num.get()); result.setThrownExceptions(exceptionsThrown);
@After public void doneWithTestCase(){ threadStopper.killAndJoinClientThreads(); org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); org.evosuite.runtime.classhandling.JDKClassResetter.reset(); org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); }