/// <summary> /// Note that Explore can silently fail (exits with 1), if a second chance AV happens /// </summary> /// <param name="timer"></param> /// <param name="planManager"></param> /// <param name="methodWeigthing"></param> /// <param name="forbidNull"></param> /// <param name="mutateFields"></param> public void Explore(ITimer timer, PlanManager planManager, MethodWeighing methodWeigthing, bool forbidNull, bool mutateFields, bool fairOpt) { int currentPlans = planManager.Plans; int currentRedundantAdds = planManager.RedundantAdds; // Start timing test generation. Timer.QueryPerformanceCounter(ref TimeTracking.generationStartTime); //exercise the fair option if (fairOpt) { Console.WriteLine("Using the fair option ...."); //fairOptLog = new StreamWriter("Randoop.fairopt.log"); //compute the initial working set and the active methods for each class InitializeActiveMemberAndDependency(planManager); for (; ; ) { //field setting if (mutateFields && this.actions.fieldList.Count > 0 && Common.Enviroment.Random.Next(2) == 0) NewFieldSettingPlan(this.actions.RandomField(), planManager, forbidNull); //If the active set is recomputed from scratch //InitializeActiveMemberAndDependency(planManager); //copy the keys Dictionary<Type, bool>.KeyCollection keys = new Dictionary<Type, bool>.KeyCollection(activeTypes); List<Type> activeList = new List<Type>(); foreach (Type t in keys) activeList.Add(t); RandoopPrintFairStats("Randoop.RandomExplore::Explore", "Starting a round of the fair workset algorithm with " + activeTypes.Count + "activeTypes"); foreach (Type t in activeList) { //pick up an active method of the type MemberInfo m; try { m = this.actions.RandomActiveMethodorConstructor(activeMembers, t); } catch (Exception e) { Console.WriteLine("Exception raised from RandomActiveMethodorConstructor is {0}", e.ToString()); continue; } //Console.WriteLine("Picked up method {0}::{1}", m.DeclaringType,m.Name ); int prevBuilderPlanCnt = planManager.builderPlans.NumPlans; //Randoop step ExploreMemberInternal(timer, planManager, forbidNull, m); //need to know if the object creation was succesful, since we know the type //we do it indirectly by looking at the builder plans if (planManager.builderPlans.NumPlans > prevBuilderPlanCnt) { Type retType; if (m is MethodInfo) { retType = (m as MethodInfo).ReturnType; } else if (m is ConstructorInfo) { retType = (m as ConstructorInfo).DeclaringType; } else { throw new RandoopBug("Constructor or Method expected"); } //use the return type of the method/constructor to incrementally activate more methods/classes try { UpdateActiveMethodsAndClasses(retType); } catch (Exception e) // had a nasty bug in the updateActiveMethodsAndClasses, so using try-catch { Console.WriteLine("Exception raised from UpdateActiveMethodsAndClasses is {0}", e.ToString()); } } if (timer.TimeToStop()) { //get the size of # of active members int size = 0; foreach (KeyValuePair<Type, List<MemberInfo>> kv in activeMembers) { List<MemberInfo> l = kv.Value; size = size + l.Count; } //stats printing Console.WriteLine("Finishing the fair exploration...printing activity stats"); Console.WriteLine("Stats: <#ActiveTypes, #ActiveMembers, #BuilderPlans, #typesWithObjs> = <{0},{1},{2},{3}>", activeTypes.Count, size, planManager.builderPlans.NumPlans, typesWithObjects.Count); //fairOptLog.Close(); return; } } } } else { #region Old code for the Randoop exploration for (; ; ) { //field setting if (mutateFields && this.actions.fieldList.Count > 0 && Common.Enviroment.Random.Next(2) == 0) NewFieldSettingPlan(this.actions.RandomField(), planManager, forbidNull); MemberInfo m; if (methodWeigthing == MethodWeighing.RoundRobin) { m = this.actions.RandomMethodOrConstructorRoundRobin(); } else if (methodWeigthing == MethodWeighing.Uniform) { m = this.actions.RandomMethodOrConstructorUniform(); } else throw new RandoopBug("Unrecognized method weighting option."); ExploreMemberInternal(timer, planManager, forbidNull, m); if (timer.TimeToStop()) { // this computation gives us the activity stats for the non-fair option InitializeActiveMemberAndDependency(planManager); //get the size of # of active members int size = 0; foreach (KeyValuePair<Type, List<MemberInfo>> kv in activeMembers) { List<MemberInfo> l = kv.Value; size = size + l.Count; } //stats printing Console.WriteLine("Finishing the non-fair exploration...printing activity stats"); Console.WriteLine("Stats: <#ActiveTypes, #ActiveMembers, #BuilderPlans, #typesWithObjs> = <{0},{1},{2},{3}>", activeTypes.Count, size, planManager.builderPlans.NumPlans, typesWithObjects.Count); //fairOptLog.Close(); return; } } #endregion } }
public void RestoreTimer(ITimer timer) { TimerPool.Restore(timer); }
private void ExploreMemberInternal(ITimer timer, PlanManager planManager, bool forbidNull, MemberInfo m) { Type[] sugg = GetParameterTypeSuggestions(m, planManager); if (m is ConstructorInfo) { NewConstructorPlan((m as ConstructorInfo).DeclaringType, m as ConstructorInfo, planManager, forbidNull, sugg); } else { Util.Assert(m is MethodInfo); NewMethodPlan((m as MethodInfo).DeclaringType, m as MethodInfo, planManager, forbidNull, sugg); } }
public CStateMachine(CCallManager manager) { // store manager reference... _manager = manager; // create call proxy _sigProxy = _manager.Factory.createCallProxy(); // initialize call states _stateIdle = new CIdleState(this); _stateAlerting = new CAlertingState(this); _stateActive = new CActiveState(this); _stateCalling = new CConnectingState(this); _stateReleased = new CReleasedState(this); _stateIncoming = new CIncomingState(this); _stateHolding = new CHoldingState(this); // change state _state = _stateIdle; // initialize data Time = System.DateTime.Now; Duration = System.TimeSpan.Zero; // Initialize timers if (null != _manager) { _noreplyTimer = _manager.Factory.createTimer(); _noreplyTimer.Interval = 15000; // hardcoded to 15s _noreplyTimer.Elapsed = new TimerExpiredCallback(_noreplyTimer_Elapsed); _releasedTimer = _manager.Factory.createTimer(); _releasedTimer.Interval = 5000; // hardcoded to 15s _releasedTimer.Elapsed = new TimerExpiredCallback(_releasedTimer_Elapsed); } }