Exemplo n.º 1
0
        /// <summary>
        /// Starts the engine.
        /// </summary>
        internal override void Start()
        {
            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine(". ThreadAnalysis");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Start();
            }

            Analysis.Factory.CreateThreadUsageAnalysis(base.Program.AC).Run();

            Refactoring.Factory.CreateThreadRefactoring(base.Program.AC).Run();

            Analysis.Factory.CreateLockUsageAnalysis(base.Program.AC).Run();
            Analysis.Factory.CreateAtomicRegionsAnalysis(base.Program.AC).Run();
            Analysis.Factory.CreateSharedStateAnalysis(base.Program.AC).Run();

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Stop();
                Output.PrintLine("... ThreadAnalysis done [{0}]", base.Timer.Result());
            }
        }
Exemplo n.º 2
0
        private int ReportRace(AssertCounterexample cex)
        {
//      this.PopulateModelWithStatesIfNecessary(cex);

            var resource           = this.GetSharedResourceName(cex.FailingAssert.Attributes);
            var conflictingActions = this.GetConflictingAccesses(cex, resource);

            this.UnprotectedResources.Add(resource);

            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine("..... Conflict in memory region: " + resource);
            }
            if (ToolCommandLineOptions.Get().ShowErrorModel)
            {
                this.Write(cex.Model, conflictingActions);
            }

            int errorCounter = 0;

            foreach (var action1 in conflictingActions)
            {
                foreach (var action2 in conflictingActions)
                {
                    if (this.AnalyseConflict(action1.Key, action2.Key, action1.Value, action2.Value))
                    {
                        errorCounter++;
                    }
                }
            }

            return(errorCounter == 0 ? 1 : errorCounter);
        }
Exemplo n.º 3
0
        public int ReportCounterexample(Counterexample error)
        {
            Contract.Requires(error != null);
            int errors = 0;

            if (error is AssertCounterexample)
            {
                AssertCounterexample cex = error as AssertCounterexample;

                if (QKeyValue.FindBoolAttribute(cex.FailingAssert.Attributes, "race_checking"))
                {
                    errors += this.ReportRace(cex);
                }
                else
                {
                    if (ToolCommandLineOptions.Get().VerboseMode)
                    {
                        Output.PrintLine("..... Error: AssertCounterexample");
                    }
                    errors++;
                }
            }

            if (errors > 0)
            {
                this.FoundErrors = true;
            }

            return(errors);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs the summarization engine on the program.
        /// </summary>
        /// <param name="program">Program</param>
        private static void RunSummarizationEngine(Program program)
        {
            if (ToolCommandLineOptions.Get().SkipSummarization)
            {
                return;
            }

            new SummarizationEngine(program).Start();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="program">Program</param>
        internal AbstractEngine(Program program)
        {
            Contract.Requires(program != null);
            this.Program = program;

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                this.Timer = new ExecutionTimer();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Parses, analyzes and sequentializes the program.
        /// </summary>
        /// <param name="program">Program</param>
        private static void ParseAnalyzeAndSequentialize(Program program)
        {
            if (ToolCommandLineOptions.Get().SkipSequentialization)
            {
                return;
            }

            new ParsingEngine(program).Start();
            new ThreadAnalysisEngine(program).Start();
            new SequentializationEngine(program).Start();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Cleans up temporary files.
        /// </summary>
        /// <param name="program">Program</param>
        private static void CleanUpTemporaryFiles(Program program)
        {
            if (ToolCommandLineOptions.Get().KeepTemporaryFiles)
            {
                return;
            }

            Lockpwn.IO.BoogieProgramEmitter.Remove(program.FileList[program.FileList.Count - 1],
                                                   "sequentialized", "bpl");
            Lockpwn.IO.BoogieProgramEmitter.Remove(program.FileList[program.FileList.Count - 1],
                                                   "summarised", "bpl");
        }
Exemplo n.º 8
0
        internal static void Main(string[] args)
        {
            Contract.Requires(cce.NonNullElements(args));
            Driver.InstallCommandLineOptions(args);

            var program = new Program();

            try
            {
                ExecutionTimer timer = null;
                if (ToolCommandLineOptions.Get().MeasureTime)
                {
                    timer = new ExecutionTimer();
                    timer.Start();
                }

                Driver.ParseFiles(program);

                try
                {
                    Driver.ParseAnalyzeAndSequentialize(program);
                    Driver.RunSummarizationEngine(program);
                    Driver.RunReachabilityAnalysisEngine(program);
                }
                catch (AnalysisFailedException)
                {
                    Lockpwn.IO.Reporter.WarningWriteLine("Warning: Failed fast");
                }

                if (ToolCommandLineOptions.Get().MeasureTime)
                {
                    timer.Stop();
                    Output.PrintLine(". Done [{0}]", timer.Result());
                }
                else if (ToolCommandLineOptions.Get().VerboseMode)
                {
                    Output.PrintLine(". Done");
                }

                Driver.CleanUpTemporaryFiles(program);
                Environment.Exit((int)Outcome.Done);
            }
            catch (Exception e)
            {
                Console.Error.Write("Exception thrown in lockpwn: ");
                Console.Error.WriteLine(e);
                Driver.CleanUpTemporaryFiles(program);
                Environment.Exit((int)Outcome.FatalError);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Starts the engine.
        /// </summary>
        internal override void Start()
        {
            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine(". ReachabilityAnalysis");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Start();
            }

            string suffix;

            if (!ToolCommandLineOptions.Get().RequiresInvariantInference ||
                ToolCommandLineOptions.Get().SkipSummarization)
            {
                suffix = "sequentialized";
            }
            else
            {
                suffix = "summarised";
            }

            base.Program.AC = base.ParseContextFromFile(suffix);

            Analysis.Factory.CreateRaceCheckAnalysis(base.Program.AC).Run();

            if (ToolCommandLineOptions.Get().EnableCorralMode)
            {
                var originalAnalysisContext = base.ParseContextFromInputFile();
                Instrumentation.Factory.CreateYieldInstrumentation(originalAnalysisContext).Run();

                if (ToolCommandLineOptions.Get().OutputFile.Length > 0)
                {
                    base.EmitProgramContext(originalAnalysisContext);
                }
                else
                {
                    base.EmitProgramContext(originalAnalysisContext, "corral");
                }
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Stop();
                Output.PrintLine("... ReachabilityAnalysis done [{0}]", base.Timer.Result());
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Parses the input files.
        /// </summary>
        /// <param name="program">Program</param>
        private static void ParseFiles(Program program)
        {
            if (ToolCommandLineOptions.Get().Files.Count == 0)
            {
                Lockpwn.IO.Reporter.ErrorWriteLine("lockpwn: error: no input files were specified.");
                Environment.Exit((int)Outcome.FatalError);
            }

            foreach (string file in ToolCommandLineOptions.Get().Files)
            {
                string extension = Path.GetExtension(file);
                if (extension != null)
                {
                    extension = extension.ToLower();
                }

                program.FileList.Add(file);
            }

            foreach (string file in program.FileList)
            {
                Contract.Assert(file != null);
                string extension = Path.GetExtension(file);
                if (extension != null)
                {
                    extension = extension.ToLower();
                }
                if (extension != ".bpl")
                {
                    Lockpwn.IO.Reporter.ErrorWriteLine("lockpwn: error: {0} is not a .bpl file.", file);
                    Environment.Exit((int)Outcome.FatalError);
                }
            }

            if (ToolCommandLineOptions.Get().SkipSequentialization&&
                ToolCommandLineOptions.Get().SkipSummarization)
            {
                string fileName;
                var    exists = Lockpwn.IO.BoogieProgramEmitter.Exists(program
                                                                       .FileList[program.FileList.Count - 1], "sequentialized", "bpl", out fileName);
                if (!exists)
                {
                    Console.Error.WriteLine("Error: File '{0}' not found.", fileName);
                    Driver.CleanUpTemporaryFiles(program);
                    Environment.Exit((int)Outcome.FatalError);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Installs the command line options.
        /// </summary>
        /// <param name="args">Arguments</param>
        private static void InstallCommandLineOptions(string[] args)
        {
            CommandLineOptions.Install(new ToolCommandLineOptions());

            CommandLineOptions.Clo.DoModSetAnalysis      = true;
            CommandLineOptions.Clo.DontShowLogo          = true;
            CommandLineOptions.Clo.TypeEncodingMethod    = CommandLineOptions.TypeEncoding.Monomorphic;
            CommandLineOptions.Clo.ModelViewFile         = "-";
            CommandLineOptions.Clo.UseLabels             = false;
            CommandLineOptions.Clo.EnhancedErrorMessages = 1;
            CommandLineOptions.Clo.ContractInfer         = true;

            ToolCommandLineOptions.Get().RunningBoogieFromCommandLine = true;
            ToolCommandLineOptions.Get().PrintUnstructured            = 2;

            if (!ToolCommandLineOptions.Get().Parse(args))
            {
                Environment.Exit((int)Outcome.FatalError);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Starts the engine.
        /// </summary>
        internal override void Start()
        {
            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine(". Parsing");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Start();
            }

            base.Program.AC = base.ParseContextFromInputFile();

            Refactoring.Factory.CreateProgramSimplifier(base.Program.AC).Run();

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Stop();
                Output.PrintLine("... Parsing done [{0}]", base.Timer.Result());
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Starts the engine.
        /// </summary>
        internal override void Start()
        {
            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine(". Sequentialization");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Start();
            }

            Instrumentation.Factory.CreateGlobalRaceCheckingInstrumentation(base.Program.AC).Run();

            Instrumentation.Factory.CreateLocksetInstrumentation(base.Program.AC).Run();
            Instrumentation.Factory.CreateRaceCheckingInstrumentation(base.Program.AC).Run();

            Analysis.Factory.CreateSharedStateAbstraction(base.Program.AC).Run();

            Instrumentation.Factory.CreateErrorReportingInstrumentation(base.Program.AC).Run();
            Instrumentation.Factory.CreateAccessCheckingInstrumentation(base.Program.AC).Run();

            foreach (var thread in base.Program.AC.Threads)
            {
                base.Program.AC.InlineThread(thread);
            }
            base.Program.AC.InlineThreadHelpers();

            if (ToolCommandLineOptions.Get().SkipSummarization)
            {
                base.EmitProgramContext(base.Program.AC, "sequentialized");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Stop();
                Output.PrintLine("... Sequentialization done [{0}]", base.Timer.Result());
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Starts the engine.
        /// </summary>
        internal override void Start()
        {
            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine(". Summarization");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Start();
            }

            Instrumentation.Factory.CreateLoopInvariantInstrumentation(base.Program.AC).Run();

            base.EmitProgramContext(base.Program.AC, "sequentialized");

            if (ToolCommandLineOptions.Get().RequiresInvariantInference)
            {
                base.Program.AC = base.ParseContextFromFile("sequentialized");

                base.Program.AC.EliminateNonInvariantInferenceAssertions();
                base.Program.AC.EliminateDeadVariables();
                base.Program.AC.Inline();

                var summarizedAnalysisContext = base.ParseContextFromFile("sequentialized");
                Analysis.Factory.CreateHoudiniInvariantInference(base.Program.AC, summarizedAnalysisContext).Run();

                ModelCleaner.RemoveExistentials(summarizedAnalysisContext);

                base.EmitProgramContext(summarizedAnalysisContext, "summarised");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Stop();
                Output.PrintLine("... Summarization done [{0}]", base.Timer.Result());
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Emits the given analysis context.
 /// </summary>
 /// <param name="ac">AnalysisContext</param>
 /// <param name="suffix">Suffix</param>
 protected void EmitProgramContext(AnalysisContext ac, string suffix)
 {
     Lockpwn.IO.BoogieProgramEmitter.Emit(ac.TopLevelDeclarations, ToolCommandLineOptions
                                          .Get().Files[ToolCommandLineOptions.Get().Files.Count - 1], suffix, "bpl");
 }
Exemplo n.º 16
0
        /// <summary>
        /// Starts the engine.
        /// </summary>
        internal override void Start()
        {
            if (ToolCommandLineOptions.Get().VerboseMode)
            {
                Output.PrintLine(". Summarization");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Start();
            }

            Instrumentation.Factory.CreateLoopInvariantInstrumentation(base.Program.AC).Run();

            base.EmitProgramContext(base.Program.AC, "sequentialized");

            if (ToolCommandLineOptions.Get().RequiresInvariantInference)
            {
                base.Program.AC = base.ParseContextFromFile("sequentialized");

                base.Program.AC.EliminateNonInvariantInferenceAssertions();
                base.Program.AC.EliminateDeadVariables();
                base.Program.AC.Inline();

                var summarizedAnalysisContext = base.ParseContextFromFile("sequentialized");

                try
                {
                    Analysis.Factory.CreateHoudiniInvariantInference(base.Program.AC, summarizedAnalysisContext).Run();
                }
                catch (AnalysisFailedException)
                {
                    if (ToolCommandLineOptions.Get().EnableCorralMode)
                    {
                        var originalAnalysisContext = base.ParseContextFromInputFile();
                        Instrumentation.Factory.CreateYieldInstrumentation(originalAnalysisContext).Run();

                        if (ToolCommandLineOptions.Get().OutputFile.Length > 0)
                        {
                            base.EmitProgramContext(originalAnalysisContext);
                        }
                        else
                        {
                            base.EmitProgramContext(originalAnalysisContext, "corral");
                        }
                    }

                    throw;
                }

                ModelCleaner.RemoveExistentials(summarizedAnalysisContext);

                base.EmitProgramContext(summarizedAnalysisContext, "summarised");
            }

            if (ToolCommandLineOptions.Get().MeasureTime)
            {
                base.Timer.Stop();
                Output.PrintLine("... Summarization done [{0}]", base.Timer.Result());
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Emits the given analysis context to the user specified output file.
 /// </summary>
 /// <param name="ac">AnalysisContext</param>
 /// <param name="suffix">Suffix</param>
 protected void EmitProgramContext(AnalysisContext ac)
 {
     Lockpwn.IO.BoogieProgramEmitter.EmitToFile(ac.TopLevelDeclarations,
                                                ToolCommandLineOptions.Get().OutputFile);
 }