Beispiel #1
0
        public static void InterpretNuSMVOutput(this GoalModel model, string filename, ProofObligationGenerator generator, bool verbose)
        {
            string[] lines = File.ReadAllLines(filename);

            var      proofObligations     = generator.Obligations;
            int      proofObligationIndex = 0;

            foreach (var line in lines) {
                if (line.StartsWith ("-- specification")) {
                    var regex = new Regex (@"-- specification (.+) is (true|false)");
                    var match = regex.Match (line);

                    if (match.Success) {
                        var result = bool.Parse (match.Groups[2].Value);
                        var proofObligation = proofObligations [proofObligationIndex];

                        if (result == proofObligation.ExpectedResult) {
                            if (verbose) {
                                Console.BackgroundColor = ConsoleColor.Green;
                                Console.Write ("  OK  ");
                                Console.ResetColor ();
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.Write (" " + proofObligation.SuccessMessage);
                                Console.ResetColor ();
                                Console.WriteLine ();
                            }

                        } else if (!proofObligation.Critical) {
                            Console.BackgroundColor = ConsoleColor.Blue;
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.Write (" WARN ");
                            Console.ResetColor ();
                            Console.ForegroundColor = ConsoleColor.Blue;
                            Console.Write (" " + proofObligation.FailureMessage);
                            Console.ResetColor ();
                            Console.WriteLine ();

                        } else {
                            Console.BackgroundColor = ConsoleColor.Red;
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.Write ("  KO  ");
                            Console.ResetColor ();
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write (" " + proofObligation.FailureMessage);
                            Console.ResetColor ();
                            Console.WriteLine ();
                        }
                    }
                    proofObligationIndex++;
                }
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            bool show_help = false;
            string nusmvModel = "";
            string nusmvOutput = "";
            string obstacles = null;
            bool verbose = false;

            options.Add ("w|write=", "Write a NuSMV model in specified file",
                         v => nusmvOutput = v);
            options.Add ("r|read=", "Read a NuSMV output and display a report",
                         v => nusmvModel = v);
            options.Add ("o|obstacles=", "List of obstacles",
                         v => obstacles = v);
            options.Add ("v|verbose", "Verbose mode",
                         v => verbose = true);
            options.Add ("h|help", "show this message and exit",
                         v => show_help = true);
            Init (args);

            try {
                ProofObligationGenerator generator;

                if (obstacles != null) {
                    var g = new List<Goal> ();
                    var obstructedGoalNames = obstacles.Split (',');
                    foreach (var untrimmedName in obstructedGoalNames) {
                        var name = untrimmedName.Trim ();
                        var goals = model.Goals().Where (x => x.Name == name);
                        g.AddRange (goals);
                    }

                    generator = new ProofObligationGenerator (model, null, g);
                } else {
                    generator = new ProofObligationGenerator (model);
                }

                if (!string.IsNullOrEmpty (nusmvModel)) {
                    model.InterpretNuSMVOutput (nusmvModel, generator, verbose);

                } else {
                    model.WriteNuSMVModel (nusmvOutput, generator);
                }
            } catch (Exception e) {
                PrintError (e.Message);
            }
        }
Beispiel #3
0
        public static void WriteNuSMVModel(this GoalModel model, string filename, ProofObligationGenerator generator)
        {
            var streamWriter = new StreamWriter (filename);

            streamWriter.WriteLine ("MODULE main");
            streamWriter.WriteLine ();
            streamWriter.WriteLine ("  VAR");
            foreach (var item in model.GetAlphabet ()) {
                streamWriter.WriteLine ("    {0} : boolean;", item);
            }

            streamWriter.WriteLine ();
            foreach (var proofObligation in generator.Obligations) {
                streamWriter.WriteLine ("  -- Expected result : {0} (otherwise, {1})",
                                        proofObligation.ExpectedResult,
                                        proofObligation.FailureMessage);
                streamWriter.WriteLine ("  LTLSPEC");
                streamWriter.WriteLine ("    {0}", proofObligation.Formula.ToCanonicString ());
                streamWriter.WriteLine ();
            }

            streamWriter.Close ();
        }