예제 #1
0
        public static void Main(string[] args)
        {
            var options = ParseCommandLine(args);

            if (options == null)
            {
                Environment.Exit((int)TestResult.InvalidParameters);
            }

            if (options.UsePSharp && options.isRefinement)
            {
                Console.WriteLine("Error: Refinement checking isn't yet supported with /psharp flag");
                Environment.Exit((int)TestResult.InvalidParameters);
            }

            if (options.isRefinement)
            {
                var refinementCheck = new RefinementChecking(options);
                if (options.LHSModel == null)
                {
                    refinementCheck.RunCheckerRHS();
                }
                else
                {
                    refinementCheck.RunCheckerLHS();
                }
                return;
            }

            var       asm = Assembly.LoadFrom(options.inputFileName);
            StateImpl s   = (StateImpl)asm.CreateInstance("P.Program.Application",
                                                          false,
                                                          BindingFlags.CreateInstance,
                                                          null,
                                                          new object[] { true },
                                                          null,
                                                          new object[] { });

            if (s == null)
            {
                throw new ArgumentException("Invalid assembly");
            }

            if (options.UsePSharp)
            {
                RunPSharpTester(s);
                return;
            }

            int maxNumOfSchedules = 10000;
            int maxDepth          = 5000;
            int numOfSchedules    = 0;
            int numOfSteps        = 0;
            var randomScheduler   = new Random(DateTime.Now.Millisecond);

            while (numOfSchedules < maxNumOfSchedules)
            {
                var currImpl = (StateImpl)s.Clone();
                if (numOfSchedules % 10 == 0)
                {
                    Console.WriteLine("-----------------------------------------------------");
                    Console.WriteLine("Total Schedules Explored: {0}", numOfSchedules);
                    Console.WriteLine("-----------------------------------------------------");
                }
                numOfSteps = 0;
                while (numOfSteps < maxDepth)
                {
                    if (currImpl.EnabledMachines.Count == 0)
                    {
                        break;
                    }

                    var num        = currImpl.EnabledMachines.Count;
                    var choosenext = randomScheduler.Next(0, num);
                    currImpl.EnabledMachines[choosenext].PrtRunStateMachine();
                    if (currImpl.Exception != null)
                    {
                        if (currImpl.Exception is PrtAssumeFailureException)
                        {
                            break;
                        }
                        else if (currImpl.Exception is PrtException)
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("ERROR: {0}", currImpl.Exception.Message);
                            Environment.Exit(-1);
                        }
                        else
                        {
                            Console.WriteLine(currImpl.errorTrace.ToString());
                            Console.WriteLine("[Internal Exception]: Please report to the P Team");
                            Console.WriteLine(currImpl.Exception.ToString());
                            Environment.Exit(-1);
                        }
                    }

                    numOfSteps++;

                    //print the execution if verbose
                    if (options.verbose)
                    {
                        Console.WriteLine("-----------------------------------------------------");
                        Console.WriteLine("Execution {0}", numOfSchedules);
                        Console.WriteLine(currImpl.errorTrace.ToString());
                    }
                }
                numOfSchedules++;
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0] == "!")     // scratch space for quick testing
                {
                    Environment.Exit(0);
                }
            }

            var options = ParseCommandLine(args);

            if (options == null)
            {
                Environment.Exit((int)TestResult.InvalidParameters);
            }

            if (options.UsePSharp && options.isRefinement)
            {
                Console.WriteLine("Error: Refinement checking isn't yet supported with /psharp flag");
                Environment.Exit((int)TestResult.InvalidParameters);
            }


            if (options.testMCer)
            {
                P.Runtime.TestMCer tester = new TestMCer();
                tester.Testing();
                return;
            }

            if (options.isRefinement)
            {
                var refinementCheck = new RefinementChecking(options);
                if (options.LHSModel == null)
                {
                    refinementCheck.RunCheckerRHS();
                }
                else
                {
                    refinementCheck.RunCheckerLHS();
                }
                return;
            }

            /// --PL: load the assembly (.dll file, a P application) with the given file name
            var asm = Assembly.LoadFrom(options.inputFileName);
            /// --PL: create an instance of P program state
            var s = (StateImpl)asm.CreateInstance("P.Program.Application",
                                                  false,
                                                  BindingFlags.CreateInstance,
                                                  null,
                                                  new object[] { true },
                                                  null,
                                                  new object[] { });

            //StateImpl s = new P.Program.Application(true);

            if (s == null)
            {
                throw new ArgumentException("Invalid assembly");
            }

            DfsExploration.start = s;

            ///-- PL: stopwatch: to measure the elapsed time
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();
            /// run PTester in an interactive
            if (options.interactive)
            {
                DfsExploration.interactiveMode = true;
            }

            try
            {
                if (options.UsePSharp)
                {
                    PSharpExploration.RunPSharpTester(s);
                }
                else if (options.DfsExploration)
                {
                    DfsExploration.Dfs();                  // Normal DFS exploration from s
                }
                else if (options.OSList || options.OSSet)
                {
                    var ret = DfsExploration.OSIterate(); // Verification using OS with list or set abstraction; exploration starts with s,
                    if (ret == 0)
                    {
                        Console.WriteLine("Exiting...");
                    }
                }
                else
                {
                    RandomExploration.Explore(s, options);
                }
                Console.WriteLine("Time elapsed: {0} seconds", stopwatch.Elapsed.TotalSeconds.ToString("F2"));
            }
            catch (P.Runtime.PrtInfiniteRaiseLoop inf)
            {
                Console.WriteLine(inf.ToString());
            }
            catch (PrtMaxEventInstancesExceededException e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                Console.WriteLine("Time elapsed: {0} seconds", stopwatch.Elapsed.TotalSeconds.ToString("F2"));
            }
        }