Beispiel #1
0
        /// <summary>
        /// Adds (if not already present) p to either fplanDB or fexceptionThrowingPlanDB,
        /// by executing the plan to determine if it throws exceptions.
        /// </summary>
        /// <param name="v"></param>
        public void AddMaybeExecutingIfNeeded(Plan p, StatsManager stats)
        {
            //foreach (string s in p.Codestring)
            //    Console.WriteLine(s);


            if (builderPlans.Containsplan(p))
            {
                redundantAdds++;
                stats.CreatedNew(CreationResult.Redundant);
            }
            else if (exceptionPlans.Containsplan(p))
            {
                redundantAdds++;
                stats.CreatedNew(CreationResult.Redundant);
            }
            else
            {
                addCounter++;
                if (addCounter % 1000 == 0)
                {
                    Console.Write(".");
                    PrintPercentageExecuted();
                }

                stats.CreatedNew(CreationResult.New);
                ResultTuple execResult;

                TextWriter writer = new StringWriter();
                ////[email protected] changes for debuglog
                //TextWriter writer
                //    = new StreamWriter("..\\..\\TestRandoopBare\\1ab1qkwm.jbd\\debug.log");

                Exception exceptionThrown;
                bool      contractViolated;

                this.testFileWriter.WriteTest(p);

                if (config.executionmode == ExecutionMode.DontExecute)
                {
                    builderPlans.AddPlan(p);
                    stats.ExecutionResult("normal");
                }
                else
                {
                    Util.Assert(config.executionmode == ExecutionMode.Reflection);

                    //TextWriter executionLog = new StreamWriter(config.executionLog);
                    TextWriter executionLog = new StreamWriter(config.executionLog + addCounter.ToString() + ".log"); //[email protected] changes
                    executionLog.WriteLine("LASTPLANID:" + p.uniqueId);

                    long startTime = 0;
                    Timer.QueryPerformanceCounter(ref startTime);

                    bool execSucceeded = p.Execute(out execResult,
                                                   executionLog, writer, out exceptionThrown,
                                                   out contractViolated, this.config.forbidnull,
                                                   config.monkey);

                    long endTime = 0;
                    Timer.QueryPerformanceCounter(ref endTime);
                    TimeTracking.timeSpentExecutingTestedCode += (endTime - startTime);

                    executionLog.Close();
                    //writer.Close(); //[email protected] adds for debuglog

                    /*
                     * New: Now the execution of plan might fail (recursively) if any of the output tuple
                     * objects violate the contract for ToString(), HashCode(), Equals(o)
                     */
                    if (!execSucceeded)
                    {
                        stats.ExecutionResult(exceptionThrown == null ? "other" : exceptionThrown.GetType().FullName);

                        // TODO This should alway be true...
                        if (exceptionThrown != null)
                        {
                            p.exceptionThrown = exceptionThrown;
                            this.testFileWriter.Move(p, exceptionThrown);

                            if (exceptionThrown is AccessViolationException)
                            {
                                Console.WriteLine("SECOND-CHANCE ACCESS VIOLATION EXCEPTION.");
                                System.Environment.Exit(1);
                            }
                        }


                        //string exceptionMessage = writer.ToString(); //no use? [email protected] comments out

                        Util.Assert(p.exceptionThrown != null || contractViolated);

                        if (config.monkey)
                        {
                            builderPlans.AddPlan(p);
                            //exceptionPlans.AddPlan(p); //new: also add it to exceptions for monkey
                        }
                        else if (exceptionThrown != null)
                        {
                            exceptionPlans.AddPlan(p);
                        }
                    }
                    else
                    {
                        stats.ExecutionResult("normal");

                        if (config.outputnormalinputs)
                        {
                            this.testFileWriter.MoveNormalTermination(p);
                        }
                        else
                        {
                            this.testFileWriter.Remove(p);
                        }

                        // If forbidNull, then make inactive any result tuple elements that are null.
                        if (this.config.forbidnull)
                        {
                            Util.Assert(p.NumTupleElements == execResult.tuple.Length);
                            for (int i = 0; i < p.NumTupleElements; i++)
                            {
                                if (execResult.tuple[i] == null)
                                {
                                    p.SetActiveTupleElement(i, false);
                                }
                            }
                            //Util.Assert(!allNull); What is the motivation behind this assertion?
                        }


                        //only allow the receivers to be arguments to future methods
                        if (config.forbidparamobj)
                        {
                            Util.Assert(p.NumTupleElements == execResult.tuple.Length);
                            for (int i = 1; i < p.NumTupleElements; i++)
                            {
                                p.SetActiveTupleElement(i, false);
                            }
                        }

                        builderPlans.AddPlan(p, execResult);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds (if not already present) p to either fplanDB or fexceptionThrowingPlanDB,
        /// by executing the plan to determine if it throws exceptions.
        /// </summary>
        /// <param name="v"></param>
        public void AddMaybeExecutingIfNeeded(Plan plan, StatsManager stats)
        {
            if (builderPlans.Containsplan(plan))
            {
                redundantAdds++;
                stats.CreatedNew(CreationResult.Redundant);
            }
            else if (exceptionPlans.Containsplan(plan))
            {
                redundantAdds++;
                stats.CreatedNew(CreationResult.Redundant);
            }
            else
            {
                addCounter++;
                if (addCounter % 1000 == 0)
                {
                    Console.Write(".");
                }

                stats.CreatedNew(CreationResult.New);
                ResultTuple execResult;

                TextWriter writer = new StringWriter();
                ////[email protected] changes for debuglog
                //TextWriter writer
                //    = new StreamWriter("..\\..\\TestRandoopBare\\1ab1qkwm.jbd\\debug.log");

                Exception exceptionThrown;
                bool      contractViolated;
                bool      preconditionViolated;

                testFileWriter.WriteTest(plan);

                if (config.executionmode == ExecutionMode.DontExecute)
                {
                    builderPlans.AddPlan(plan);
                    stats.ExecutionResult("normal");
                }
                else
                {
                    Util.Assert(config.executionmode == ExecutionMode.Reflection);

                    //TextWriter executionLog = new StreamWriter(config.executionLog);
                    TextWriter executionLog = new StreamWriter(config.executionLog + addCounter.ToString() + ".log"); //[email protected] changes
                    executionLog.WriteLine("LASTPLANID:" + plan.UniqueId);

                    long startTime = 0;
                    Timer.QueryPerformanceCounter(ref startTime);

                    bool execSucceeded = plan.Execute(out execResult,
                                                      executionLog, writer, out preconditionViolated, out exceptionThrown,
                                                      out contractViolated, config.forbidnull,
                                                      config.useRandoopContracts);

                    long endTime = 0;
                    Timer.QueryPerformanceCounter(ref endTime);
                    TimeTracking.timeSpentExecutingTestedCode += (endTime - startTime);

                    executionLog.Close();

                    if (!execSucceeded)
                    {
                        if (preconditionViolated)
                        {
                            stats.ExecutionResult("precondition violated");
                            testFileWriter.Remove(plan);
                        }

                        if (exceptionThrown != null)
                        {
                            stats.ExecutionResult(exceptionThrown.GetType().FullName);
                            plan.exceptionThrown = exceptionThrown;
                            testFileWriter.Move(plan, exceptionThrown);

                            if (exceptionThrown is AccessViolationException)
                            {
                                Logger.Error("SECOND-CHANCE ACCESS VIOLATION EXCEPTION.");
                                Environment.Exit(1);
                            }
                        }


                        //string exceptionMessage = writer.ToString(); //no use? [email protected] comments out

                        Util.Assert(plan.exceptionThrown != null || contractViolated || preconditionViolated);

                        if (config.monkey)
                        {
                            builderPlans.AddPlan(plan);
                        }
                        else if (exceptionThrown != null)
                        {
                            exceptionPlans.AddPlan(plan);
                        }
                    }
                    else
                    {
                        stats.ExecutionResult("normal");

                        if (config.outputnormalinputs)
                        {
                            testFileWriter.MoveNormalTermination(plan);
                        }
                        else
                        {
                            testFileWriter.Remove(plan);
                        }

                        // If forbidNull, then make inactive any result tuple elements that are null.
                        if (config.forbidnull)
                        {
                            Util.Assert(plan.NumTupleElements == execResult.tuple.Length);
                            for (int i = 0; i < plan.NumTupleElements; i++)
                            {
                                if (execResult.tuple[i] == null)
                                {
                                    plan.SetActiveTupleElement(i, false);
                                }
                            }
                            //Util.Assert(!allNull); What is the motivation behind this assertion?
                        }


                        //only allow the receivers to be arguments to future methods
                        if (config.forbidparamobj)
                        {
                            Util.Assert(plan.NumTupleElements == execResult.tuple.Length);
                            for (int i = 1; i < plan.NumTupleElements; i++)
                            {
                                plan.SetActiveTupleElement(i, false);
                            }
                        }

                        builderPlans.AddPlan(plan, execResult);
                    }
                }
            }
        }