/// <summary>
        /// Checks for parsing errors.
        /// </summary>
        protected override void CheckForParsingErrors()
        {
            var configuration = base.Configuration as DynamicAnalysisConfiguration;

            if (configuration.AssemblyToBeAnalyzed.Equals(""))
            {
                ErrorReporter.ReportAndExit("Please give a valid path to a P# program's dll.");
            }

            if (configuration.SchedulingStrategy != SchedulingStrategy.Random &&
                configuration.SchedulingStrategy != SchedulingStrategy.DFS &&
                configuration.SchedulingStrategy != SchedulingStrategy.IDDFS &&
                configuration.SchedulingStrategy != SchedulingStrategy.MaceMC)
            {
                ErrorReporter.ReportAndExit("Please give a valid scheduling strategy " +
                                            "'/sch:[x]', where [x] is 'random', 'dfs' or 'iddfs'.");
            }

            if (configuration.SafetyPrefixBound > 0 &&
                configuration.SafetyPrefixBound >= configuration.DepthBound)
            {
                ErrorReporter.ReportAndExit("Please give a safety prefix bound that is less than the " +
                                            "max depth bound.");
            }

            if (configuration.SchedulingStrategy.Equals("iddfs") && configuration.DepthBound == 0)
            {
                ErrorReporter.ReportAndExit("The Iterative Deepening DFS scheduler ('iddfs') must have a " +
                                            "max depth bound. Please give a depth bound using '/db:[x]', where [x] > 0.");
            }
        }
        /// <summary>
        /// Parse the given option.
        /// </summary>
        /// <param name="option">Option</param>
        protected override void ParseOption(string option)
        {
            var configuration = base.Configuration as LanguageServicesConfiguration;

            if (option.ToLower().StartsWith("/t:") && option.Length > 3)
            {
                if (option.ToLower().Substring(3).Equals("execution"))
                {
                    configuration.CompilationTargets.Clear();
                    configuration.CompilationTargets.Add(CompilationTarget.Execution);
                }
                else if (option.ToLower().Substring(3).Equals("testing"))
                {
                    configuration.CompilationTargets.Clear();
                    configuration.CompilationTargets.Add(CompilationTarget.Testing);
                }
                else if (option.ToLower().Substring(3).Equals("distribution"))
                {
                    configuration.CompilationTargets.Clear();
                    configuration.CompilationTargets.Add(CompilationTarget.Distribution);
                }
                else
                {
                    ErrorReporter.ReportAndExit("Please give a valid compilation target '/t:[x]', " +
                                                "where [x] is 'all', 'execution', 'testing' or 'distribution'.");
                }
            }
            else if (option.ToLower().Equals("/analyze"))
            {
                configuration.RunStaticAnalysis = true;
            }
            else if (option.ToLower().Equals("/showgivesup"))
            {
                configuration.ShowGivesUpInformation = true;
            }
            else if (option.ToLower().Equals("/time"))
            {
                configuration.ShowRuntimeResults = true;
            }
            else if (option.ToLower().Equals("/timedfa"))
            {
                configuration.ShowDFARuntimeResults = true;
            }
            else if (option.ToLower().Equals("/timeroa"))
            {
                configuration.ShowROARuntimeResults = true;
            }
            else if (option.ToLower().Equals("/nostatetransitionanalysis"))
            {
                configuration.DoStateTransitionAnalysis = false;
            }
            else if (option.ToLower().Equals("/analyzeexceptions"))
            {
                configuration.AnalyzeExceptionHandling = true;
            }
            else
            {
                base.ParseOption(option);
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes the P# program info.
        /// </summary>
        public static void Initialize()
        {
            ProgramInfo.CheckForCommandLineOptionErrors();

            // Create a new workspace.
            var workspace = MSBuildWorkspace.Create();

            try
            {
                // Populate the workspace with the user defined solution.
                ProgramInfo.Solution = (workspace as MSBuildWorkspace).OpenSolutionAsync(
                    @"" + Configuration.SolutionFilePath + "").Result;
            }
            catch (Exception ex)
            {
                Output.Print(ex.StackTrace);
                ErrorReporter.ReportAndExit("Please give a valid solution path.");
            }

            if (!Configuration.ProjectName.Equals(""))
            {
                // Find the project specified by the user.
                var project = ProgramInfo.GetProjectWithName(Configuration.ProjectName);
                if (project == null)
                {
                    ErrorReporter.ReportAndExit("Please give a valid project name.");
                }
            }

            ProgramInfo.HasInitialized = true;
        }
Exemple #4
0
 /// <summary>
 /// Checks and report any command line option errors.
 /// </summary>
 private static void CheckForCommandLineOptionErrors()
 {
     if (Configuration.ProjectName.Equals("") && Configuration.RunDynamicAnalysis)
     {
         ErrorReporter.ReportAndExit("Please give the name of the project to test (using either " +
                                     "'/p:[x]' or /test:[x], where [x] is the name of the project).");
     }
 }
        /// <summary>
        /// Checks for parsing errors.
        /// </summary>
        protected override void CheckForParsingErrors()
        {
            var configuration = base.Configuration as LanguageServicesConfiguration;

            if (configuration.SolutionFilePath.Equals(""))
            {
                ErrorReporter.ReportAndExit("Please give a valid solution path.");
            }
        }
Exemple #6
0
        /// <summary>
        /// Parse the given option.
        /// </summary>
        /// <param name="option">Option</param>
        protected virtual void ParseOption(string option)
        {
            if (option.ToLower().Equals("/?"))
            {
                this.ShowHelp();
                Environment.Exit(1);
            }
            else if (option.ToLower().StartsWith("/s:") && option.Length > 3)
            {
                this.Configuration.SolutionFilePath = option.Substring(3);
            }
            else if (option.ToLower().StartsWith("/p:") && option.Length > 3)
            {
                this.Configuration.ProjectName = option.Substring(3);
            }
            else if (option.ToLower().StartsWith("/o:") && option.Length > 3)
            {
                this.Configuration.OutputFilePath = option.Substring(3);
            }
            else if (option.ToLower().StartsWith("/v:") && option.Length > 3)
            {
                int i = 0;
                if (!int.TryParse(option.Substring(3), out i) && i >= 0 && i <= 3)
                {
                    ErrorReporter.ReportAndExit("Please give a valid verbosity level " +
                                                "'/v:[x]', where 0 <= [x] <= 3.");
                }

                this.Configuration.Verbose = i;
            }
            else if (option.ToLower().Equals("/debug"))
            {
                Output.Debugging = true;
            }
            else if (option.ToLower().Equals("/showwarnings"))
            {
                ErrorReporter.ShowWarnings = true;
            }
            else if (option.ToLower().StartsWith("/timeout:") && option.Length > 9)
            {
                int i = 0;
                if (!int.TryParse(option.Substring(9), out i) &&
                    i > 0)
                {
                    ErrorReporter.ReportAndExit("Please give a valid timeout " +
                                                "'/timeout:[x]', where [x] > 0.");
                }

                this.Configuration.Timeout = i;
            }
            else
            {
                this.ShowHelp();
                ErrorReporter.ReportAndExit("cannot recognise command line option '" +
                                            option + "'.");
            }
        }
        /// <summary>
        /// Checks for parsing errors.
        /// </summary>
        private void CheckForParsingErrors()
        {
            if (Configuration.SolutionFilePath.Equals(""))
            {
                ErrorReporter.ReportAndExit("Please give a valid solution path.");
            }

            if (!Configuration.SchedulingStrategy.Equals("") &&
                !Configuration.SchedulingStrategy.Equals("random") &&
                !Configuration.SchedulingStrategy.Equals("dfs"))
            {
                ErrorReporter.ReportAndExit("Please give a valid scheduling strategy " +
                                            "'/sch:[x]', where [x] is 'random' or 'dfs'.");
            }
        }
        /// <summary>
        /// Parses the command line options.
        /// </summary>
        public virtual void Parse()
        {
            for (int idx = 0; idx < this.Options.Length; idx++)
            {
                #region core options

                if (this.Options[idx].ToLower().Equals("/?"))
                {
                    this.ShowHelp();
                    Environment.Exit(1);
                }
                else if (this.Options[idx].ToLower().StartsWith("/s:") &&
                         this.Options[idx].Length > 3)
                {
                    Configuration.SolutionFilePath = this.Options[idx].Substring(3);
                }
                else if (this.Options[idx].ToLower().StartsWith("/p:") &&
                         this.Options[idx].Length > 3)
                {
                    Configuration.ProjectName = this.Options[idx].Substring(3);
                }
                else if (this.Options[idx].ToLower().StartsWith("/o:") &&
                         this.Options[idx].Length > 3)
                {
                    Configuration.OutputFilePath = this.Options[idx].Substring(3);
                }
                else if (this.Options[idx].ToLower().Equals("/noparsing"))
                {
                    Configuration.NoParsing = true;
                }
                else if (this.Options[idx].ToLower().Equals("/nocompile"))
                {
                    Configuration.NoCompilation = true;
                }
                else if (this.Options[idx].ToLower().StartsWith("/timeout:") &&
                         this.Options[idx].Length > 9)
                {
                    int i = 0;
                    if (!int.TryParse(this.Options[idx].Substring(9), out i) &&
                        i > 0)
                    {
                        ErrorReporter.ReportAndExit("Please give a valid timeout " +
                                                    "'/timeout:[x]', where [x] > 0.");
                    }

                    Configuration.AnalysisTimeout = i;
                }
                else if (this.Options[idx].ToLower().StartsWith("/v:") &&
                         this.Options[idx].Length > 3)
                {
                    int i = 0;
                    if (!int.TryParse(this.Options[idx].Substring(3), out i) &&
                        i >= 0 && i <= 3)
                    {
                        ErrorReporter.ReportAndExit("Please give a valid verbosity level " +
                                                    "'/v:[x]', where 0 <= [x] <= 3.");
                    }

                    Configuration.Verbose = i;
                }
                else if (this.Options[idx].ToLower().Equals("/debug"))
                {
                    Configuration.Debug.Add(DebugType.All);
                }
                else if (this.Options[idx].ToLower().StartsWith("/debug:") &&
                         this.Options[idx].Length > 7)
                {
                    if (this.Options[idx].Substring(7).ToLower().Equals("all"))
                    {
                        Configuration.Debug.Add(DebugType.All);
                    }
                    else if (this.Options[idx].Substring(7).ToLower().Equals("runtime"))
                    {
                        Configuration.Debug.Add(DebugType.Runtime);
                    }
                    else if (this.Options[idx].Substring(7).ToLower().Equals("analysis"))
                    {
                        Configuration.Debug.Add(DebugType.Analysis);
                    }
                    else if (this.Options[idx].Substring(7).ToLower().Equals("testing"))
                    {
                        Configuration.Debug.Add(DebugType.Testing);
                    }
                    else if (this.Options[idx].Substring(7).ToLower().Equals("liveness"))
                    {
                        Configuration.Debug.Add(DebugType.Liveness);
                    }
                    else
                    {
                        ErrorReporter.ReportAndExit("Please give a valid debug target '/debug:[x]', " +
                                                    "where [x] is 'all', 'runtime', 'analysis', 'testing' or 'liveness'.");
                    }
                }

                #endregion

                #region compilation options

                else if (this.Options[idx].ToLower().Equals("/distributed"))
                {
                    Configuration.CompileForDistribution = true;
                }

                #endregion

                #region static analysis options

                else if (this.Options[idx].ToLower().Equals("/analyze"))
                {
                    Configuration.RunStaticAnalysis = true;
                }
                else if (this.Options[idx].ToLower().Equals("/showwarnings"))
                {
                    Configuration.ShowWarnings = true;
                }
                else if (this.Options[idx].ToLower().Equals("/showgivesup"))
                {
                    Configuration.ShowGivesUpInformation = true;
                }
                else if (this.Options[idx].ToLower().Equals("/showstatistics") ||
                         this.Options[idx].ToLower().Equals("/stats"))
                {
                    Configuration.ShowProgramStatistics = true;
                }
                else if (this.Options[idx].ToLower().Equals("/time"))
                {
                    Configuration.ShowRuntimeResults = true;
                }
                else if (this.Options[idx].ToLower().Equals("/timedfa"))
                {
                    Configuration.ShowDFARuntimeResults = true;
                }
                else if (this.Options[idx].ToLower().Equals("/timeroa"))
                {
                    Configuration.ShowROARuntimeResults = true;
                }
                else if (this.Options[idx].ToLower().Equals("/nostatetransitionanalysis"))
                {
                    Configuration.DoStateTransitionAnalysis = false;
                }
                else if (this.Options[idx].ToLower().Equals("/analyzeexceptions"))
                {
                    Configuration.AnalyzeExceptionHandling = true;
                }

                #endregion

                #region dynamic analysis options

                else if (this.Options[idx].ToLower().Equals("/test"))
                {
                    Configuration.RunDynamicAnalysis = true;
                }
                else if (this.Options[idx].ToLower().StartsWith("/test:") &&
                         this.Options[idx].Length > 6)
                {
                    Configuration.RunDynamicAnalysis = true;
                    Configuration.ProjectName        = this.Options[idx].Substring(6);
                }
                else if (this.Options[idx].ToLower().StartsWith("/sch:") &&
                         this.Options[idx].Length > 5)
                {
                    Configuration.SchedulingStrategy = this.Options[idx].Substring(5);
                }
                else if (this.Options[idx].ToLower().StartsWith("/i:") &&
                         this.Options[idx].Length > 3)
                {
                    int i = 0;
                    if (!int.TryParse(this.Options[idx].Substring(3), out i) &&
                        i > 0)
                    {
                        ErrorReporter.ReportAndExit("Please give a valid number of iterations " +
                                                    "'/i:[x]', where [x] > 0.");
                    }

                    Configuration.SchedulingIterations = i;
                }
                else if (this.Options[idx].ToLower().Equals("/explore"))
                {
                    Configuration.FullExploration = true;
                }
                else if (this.Options[idx].ToLower().StartsWith("/db:") &&
                         this.Options[idx].Length > 4)
                {
                    int i = 0;
                    if (!int.TryParse(this.Options[idx].Substring(4), out i) &&
                        i >= 0)
                    {
                        ErrorReporter.ReportAndExit("Please give a valid exploration depth " +
                                                    "bound '/i:[x]', where [x] >= 0.");
                    }

                    Configuration.DepthBound = i;
                }
                else if (this.Options[idx].ToLower().StartsWith("/spb:") &&
                         this.Options[idx].Length > 5)
                {
                    int i = 0;
                    if (!int.TryParse(this.Options[idx].Substring(5), out i) &&
                        i >= 0)
                    {
                        ErrorReporter.ReportAndExit("Please give a valid safety prefix " +
                                                    "bound '/i:[x]', where [x] >= 0.");
                    }

                    Configuration.SafetyPrefixBound = i;
                }
                else if (this.Options[idx].ToLower().Equals("/liveness"))
                {
                    Configuration.CheckLiveness = true;
                }
                else if (this.Options[idx].ToLower().Equals("/printtrace"))
                {
                    Configuration.PrintTrace = true;
                }
                else if (this.Options[idx].ToLower().Equals("/nocaching"))
                {
                    Configuration.CacheProgramState = false;
                }

                #endregion

                #region error

                else
                {
                    this.ShowHelp();
                    ErrorReporter.ReportAndExit("cannot recognise command line option '" +
                                                this.Options[idx] + "'.");
                }

                #endregion
            }

            this.CheckForParsingErrors();
        }
        /// <summary>
        /// Parse the given option.
        /// </summary>
        /// <param name="option">Option</param>
        protected override void ParseOption(string option)
        {
            var configuration = base.Configuration as DynamicAnalysisConfiguration;

            if (option.ToLower().StartsWith("/test:") && option.Length > 6)
            {
                configuration.AssemblyToBeAnalyzed = option.Substring(6);
            }
            else if (option.ToLower().StartsWith("/sch:") && option.Length > 5)
            {
                if (option.ToLower().Substring(5).Equals("random"))
                {
                    configuration.SchedulingStrategy = SchedulingStrategy.Random;
                }
                else if (option.ToLower().Substring(5).Equals("dfs"))
                {
                    configuration.SchedulingStrategy = SchedulingStrategy.DFS;
                }
                else if (option.ToLower().Substring(5).Equals("iddfs"))
                {
                    configuration.SchedulingStrategy = SchedulingStrategy.IDDFS;
                }
                else if (option.ToLower().Substring(5).Equals("macemc"))
                {
                    configuration.SchedulingStrategy = SchedulingStrategy.MaceMC;
                }
            }
            else if (option.ToLower().StartsWith("/i:") && option.Length > 3)
            {
                int i = 0;
                if (!int.TryParse(option.Substring(3), out i) && i > 0)
                {
                    ErrorReporter.ReportAndExit("Please give a valid number of iterations " +
                                                "'/i:[x]', where [x] > 0.");
                }

                configuration.SchedulingIterations = i;
            }
            else if (option.ToLower().Equals("/explore"))
            {
                configuration.FullExploration = true;
            }
            else if (option.ToLower().StartsWith("/sch-seed:") && option.Length > 10)
            {
                int seed;
                if (!int.TryParse(option.Substring(10), out seed))
                {
                    ErrorReporter.ReportAndExit("Please give a valid random scheduling " +
                                                "seed '/sch-seed:[x]', where [x] is a signed 32-bit integer.");
                }

                configuration.RandomSchedulingSeed = seed;
            }
            else if (option.ToLower().StartsWith("/db:") && option.Length > 4)
            {
                int i = 0;
                if (!int.TryParse(option.Substring(4), out i) && i >= 0)
                {
                    ErrorReporter.ReportAndExit("Please give a valid exploration depth " +
                                                "bound '/db:[x]', where [x] >= 0.");
                }

                configuration.DepthBound = i;
            }
            else if (option.ToLower().StartsWith("/prefix:") && option.Length > 8)
            {
                int i = 0;
                if (!int.TryParse(option.Substring(8), out i) && i >= 0)
                {
                    ErrorReporter.ReportAndExit("Please give a valid safety prefix " +
                                                "bound '/prefix:[x]', where [x] >= 0.");
                }

                configuration.SafetyPrefixBound = i;
            }
            else if (option.ToLower().Equals("/printtrace"))
            {
                configuration.PrintTrace = true;
            }
            else if (option.ToLower().Equals("/tpl"))
            {
                configuration.ScheduleIntraMachineConcurrency = true;
            }
            else if (option.ToLower().Equals("/liveness"))
            {
                configuration.CheckLiveness = true;
            }
            else if (option.ToLower().Equals("/statecaching"))
            {
                configuration.CacheProgramState = true;
            }
            else
            {
                base.ParseOption(option);
            }
        }