private long getLeftTimeBeforeEnd() { long timeSinceStart = System.currentTimeMillis() - clientStartTime; long totalTimeLimit = 1000 * calculateForHowLongClientWillRunInSeconds(); return totalTimeLimit - timeSinceStart; }
private boolean isTimeoutReached() { return !TimeController.getInstance().isThereStillTimeInThisPhase(); }
public synchronized boolean isThereStillTimeInThisPhase(long ms){ if(state.equals(ClientState.NOT_STARTED)){ return true; } //all time values are in milliseconds long left = getLeftTimeBeforeEnd(); if(ms > left){ return false; } /* * OK, there is enough time, but have we spent too long * in the current phase? */ if(currentPhaseHasTimeout()){ long timeoutInMs = getCurrentPhaseTimeout(); long timeSincePhaseStarted = System.currentTimeMillis() - currentPhaseStartTime; long phaseLeft = timeoutInMs - timeSincePhaseStarted + timeLeftFromPreviousPhases; logger.debug("Time left for current phase {}: {}", state, phaseLeft); if(ms > phaseLeft){ return false; } } return true; }
public static void resetSingleton(){ getInstance().init(); }
private static int checkAllTestsIfTime(List<TestCase> testCases, long delta) { if (TimeController.getInstance().hasTimeToExecuteATestCase() && TimeController.getInstance().isThereStillTimeInThisPhase(delta)) { return JUnitAnalyzer.handleTestsThatAreUnstable(testCases); } return 0; }
/** * Add assertions to all tests in a test suite * * @param suite */ public void addAssertions(TestSuiteChromosome suite) { setupClassLoader(suite); for(TestChromosome test : suite.getTestChromosomes()) { if(!TimeController.getInstance().hasTimeToExecuteATestCase()) break; addAssertions(test.getTestCase()); } }
int time = TimeController.getInstance().calculateForHowLongClientWillRunInSeconds(); handler.waitForResult(time * 1000); try {
TimeController.getInstance().getPhasePercentage() >= Properties.REFLECTION_START_PERCENT && Randomness.nextDouble() < Properties.P_REFLECTION_ON_PRIVATE){ return insertRandomReflectionCallOnObject(test, var, position, 0);
if (! TimeController.getInstance().isThereStillTimeInThisPhase()) { logger.warn("Reached maximum time to generate assertions, aborting assertion generation"); break; if(!timeIsShort && TimeController.getInstance().getPhasePercentage() > Properties.ASSERTION_MINIMIZATION_FALLBACK_TIME) { if(numTest < Properties.ASSERTION_MINIMIZATION_FALLBACK * suite.size()) { logger.warn("Assertion minimization is taking too long ({}% of time used, but only {}/{} tests minimized), falling back to using all assertions", TimeController.getInstance().getPhasePercentage(), numTest, suite.size()); timeIsShort = true;
@Override public void changeState(ClientState state, ClientStateInformation information) { if (this.state != state){ logger.info(ClientProcess.getPrettyPrintIdentifier() + "Client changing state from " + this.state + " to " + state); } this.state = state; TimeController.getInstance().updateState(state); try { masterNode.evosuite_informChangeOfStateInClient(clientRmiIdentifier, state,information); } catch (RemoteException e) { logger.error("Cannot inform master of change of state", e); } if (this.state.equals(ClientState.DONE)) { doneLatch.countDown(); } if (this.state.equals(ClientState.FINISHED)) { finishedLatch.countDown(); } }
/** * Calculate the percentage of progress in which we currently are in the phase. * * @return a value in [0,1] if the current phase has a timeout, otherwise a negative value */ public double getPhasePercentage(){ if(currentPhaseHasTimeout()){ long timeoutInMs = getCurrentPhaseTimeout(); long timeSincePhaseStarted = System.currentTimeMillis() - currentPhaseStartTime; double ratio = (double) timeSincePhaseStarted / (double) timeoutInMs; assert ratio >= 0; // but could become >1 due to timer return Math.min(ratio,1); } else { return -1; } }
private int calculateNumberOfIntervals() { long interval = Properties.TIMELINE_INTERVAL; /* * We cannot just look at the obtained history, because the search might * have finished earlier, eg if 100% coverage */ long totalTime = TimeController.getSearchBudgetInSeconds() * 1000l; int numberOfIntervals = (int) (totalTime / interval); return numberOfIntervals; } }
private void init() { state = ClientState.NOT_STARTED; clientStartTime = 0; timeLeftFromPreviousPhases = 0; initializePhaseTimeouts(); }
/** * Main and only constructor */ protected TimeController(){ init(); }
if(!TimeController.getInstance().hasTimeToExecuteATestCase()) { break;
if (!TimeController.getInstance().isThereStillTimeInThisPhase()) { Properties.USE_SEPARATE_CLASSLOADER = junitSeparateClassLoader; return; Iterator<TestCase> iter = testCases.iterator(); while (iter.hasNext()) { if (!TimeController.getInstance().hasTimeToExecuteATestCase()) { break; if (!TimeController.getInstance().isThereStillTimeInThisPhase()) { logger.warn("JUnit checking timed out");
int time = TimeController.getInstance().calculateForHowLongClientWillRunInSeconds(); handler.waitForResult(time * 1000);
VariableReference ret = null; if( canUseFunctionalMocks && TimeController.getInstance().getPhasePercentage() >= Properties.FUNCTIONAL_MOCKING_PERCENT && Randomness.nextDouble() < Properties.P_FUNCTIONAL_MOCKING && FunctionalMockStatement.canBeFunctionalMocked(type)) {
public int calculateForHowLongClientWillRunInSeconds() { int time = Properties.EXTRA_TIMEOUT; time += Properties.INITIALIZATION_TIMEOUT; time += getSearchBudgetInSeconds(); if (Properties.MINIMIZE) { time += Properties.MINIMIZATION_TIMEOUT; } if (Properties.ASSERTIONS) { time += Properties.ASSERTION_TIMEOUT; } if(Properties.TEST_FACTORY == TestFactory.JUNIT) { time += Properties.CARVING_TIMEOUT; } if(Properties.JUNIT_TESTS){ time += Properties.WRITE_JUNIT_TIMEOUT; if(Properties.JUNIT_CHECK) { time += Properties.JUNIT_CHECK_TIMEOUT; } } return time; }
private boolean isTimeoutReached() { return !TimeController.getInstance().isThereStillTimeInThisPhase(); }