コード例 #1
0
        public bool TimeToStop()
        {
            if (!startedCountDown)
            {
                throw new RandoopBug("countdown hasn't started.");
            }

            long currentTime = 0;

            Timer.QueryPerformanceCounter(ref currentTime);
            double timeElapsed = ((double)(currentTime - startTime) / (double)(Timer.fperfTimerFrequency));

            if (timeElapsed >= timeLimit)
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public static bool ExecuteReflectionCall(CodeToExecute call, TextWriter writer, out Exception exceptionThrown)
        {
            long startTime = 0;

            Timer.QueryPerformanceCounter(ref startTime);

            if (usingRandoopDebugListener)
            {
                fdebugListener.Reset();
            }
            bool invocationOk = true;

            exceptionThrown = null;

            try
            {
                //new PermissionSet(null).PermitOnly();
                call();
                //CodeAccessPermission.RevertAll();
                //CodeAccessPermission.RevertPermitOnly();
            }
            catch (TargetInvocationException e)
            {
                exceptionThrown = e.InnerException;
                Util.Assert(exceptionThrown != null);
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("Execution failed.");
            }
            catch (SecurityException e)
            {
                exceptionThrown = e;
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("Execution failed.");
            }
            catch (Exception e)
            {
                exceptionThrown = e;
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("execution failed.");
            }

            if (usingRandoopDebugListener && fdebugListener.FailWasCalled)
            {
                invocationOk    = false;
                exceptionThrown = new AssertionViolation("An assertion was violated: "
                                                         + fdebugListener.FailureMessage);
            }

            long endTime = 0;

            Timer.QueryPerformanceCounter(ref endTime);

            try
            {
                ;
            }
            catch (SecurityException e)
            {
                exceptionThrown = e;
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("Execution failed.");
            }
            SecondsSpentInCalls += ((double)(endTime - startTime)) / ((double)(Timer.PerfTimerFrequency));

            if (!invocationOk)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Creates a timer that will count down from the given number of seconds.
 /// </summary>
 /// <param name="TimeToCountDownFrom">Time to count down from, in seconds.</param>
 public Timer(double timeToCountDownFrom)
 {
     this.timeLimit = timeToCountDownFrom;
     Timer.QueryPerformanceCounter(ref this.startTime);
     this.startedCountDown = true;
 }
コード例 #4
0
        public static bool ExecuteReflectionCall(CodeToExecute call, TextWriter writer, out Exception exceptionThrown)
        {
            long startTime = 0;

            Timer.QueryPerformanceCounter(ref startTime);

            if (usingRandoopDebugListener)
            {
                fdebugListener.Reset();
            }
            bool invocationOk = true;

            exceptionThrown = null;

            //[email protected] for substituting MessageBox.Show() - start
            ////MethodInfo call_info = call.Method;
            //var dynMeth = new DynamicMethod("Test", null, null, typeof(void));
            //ILGenerator gen = dynMeth.GetILGenerator();
            //ConstructorInfo ci = typeof(System.Windows.Forms.MessageBox).GetConstructor(new Type[0]);
            //gen.Emit(OpCodes.Newobj, ci);
            //[email protected] for substituting MessageBox.Show() - end

            try
            {
                //new PermissionSet(null).PermitOnly();
                //writer.WriteLine("call execution begins."); //[email protected] added for debug
                call();
                //CodeAccessPermission.RevertAll();
                //CodeAccessPermission.RevertPermitOnly();
            }
            catch (TargetInvocationException e)
            {
                exceptionThrown = e.InnerException;
                Util.Assert(exceptionThrown != null);
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("Execution failed.");
            }
            catch (SecurityException e)
            {
                exceptionThrown = e;
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("Execution failed.");
            }
            catch (Exception e)
            {
                exceptionThrown = e;
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("execution failed.");
            }

            if (usingRandoopDebugListener && fdebugListener.FailWasCalled)
            {
                invocationOk    = false;
                exceptionThrown = new AssertionViolation("An assertion was violated: "
                                                         + fdebugListener.FailureMessage);
            }

            long endTime = 0;

            Timer.QueryPerformanceCounter(ref endTime);

            try
            {
                ;
            }
            catch (SecurityException e)
            {
                exceptionThrown = e;
                writer.WriteLine("e : " + e);
                invocationOk = false;
                writer.WriteLine("Execution failed.");
            }
            SecondsSpentInCalls += ((double)(endTime - startTime)) / ((double)(Timer.PerfTimerFrequency));

            if (!invocationOk)
            {
                return(false);
            }

            return(true);
        }