Example #1
0
        private static int PerformImprovedPromelaTranslation(string[] args)
        {
            var argIndex = 1;

            if (args.Length < 2)
            {
                Console.WriteLine("Source file with kP system model not specified.");
                return(1);
            }

            string   srcFileName = args[argIndex];
            FileInfo fi          = new FileInfo(srcFileName);

            if (!fi.Exists)
            {
                Console.WriteLine("File '{0}' does not exist. Please specify a valid input file.", srcFileName);
                return(1);
            }

            string outFileName = string.Empty;
            string kpxFile     = string.Empty;

            VerificationModelParams vmp = VerificationModelParams.Default();

            PropertyInfo[] vmpProperties = typeof(VerificationModelParams).GetProperties();

            for (int i = ++argIndex; i < args.Length; i++)
            {
                if (args[i] == "-o")
                {
                    if (++i < args.Length)
                    {
                        outFileName = args[i];
                    }
                }
                if (args[i] == "-e")
                {
                    if (++i < args.Length)
                    {
                        kpxFile = args[i];
                    }
                }
                else
                {
                    string arg     = args[i];
                    int    eqIndex = arg.IndexOf('=');
                    if (eqIndex > 0)
                    {
                        string prop = arg.Substring(0, eqIndex);
                        string val  = arg.Substring(eqIndex + 1);
                        bool   propertyRecognized = false;
                        foreach (PropertyInfo vmpProp in vmpProperties)
                        {
                            if (vmpProp.Name == prop)
                            {
                                try
                                {
                                    if (vmpProp.PropertyType == typeof(Int32))
                                    {
                                        vmpProp.SetValue(vmp, Int32.Parse(val));
                                    }
                                    else if (vmpProp.PropertyType == typeof(bool))
                                    {
                                        vmpProp.SetValue(vmp, bool.Parse(val));
                                    }
                                    else
                                    {
                                        vmpProp.SetValue(vmp, val);
                                    }
                                }
                                catch
                                {
                                    Console.WriteLine("*** Warning. Invalid format for property {0}: value must be of type {1}",
                                                      vmpProp.Name, vmpProp.PropertyType.ToString());
                                }
                                propertyRecognized = true;
                                break;
                            }
                        }

                        if (!propertyRecognized)
                        {
                            Console.WriteLine("*** Warning. Property {0} not recognized.", prop);
                        }
                    }
                }
            }

            KpModel kpModel = null;

            try
            {
                kpModel = KP.FromKpl(srcFileName);
            }
            catch (KplParseException kplException)
            {
                Console.WriteLine("Parsing failed. Source: {0}", srcFileName);
                Console.WriteLine(kplException.Message);
                return(1);
            }

            Experiment kpExperiment = null;

            if (!string.IsNullOrEmpty(kpxFile))
            {
                try
                {
                    kpExperiment = KP.FromKpx(kpxFile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Parsing failed. Source: {0}", kpxFile);
                    Console.WriteLine(ex.Message);
                    return(1);
                }
            }

            Console.WriteLine("Generating verification model {0} with: ", outFileName);
            Console.WriteLine();
            foreach (PropertyInfo vmpProp in vmpProperties)
            {
                Console.WriteLine("{0} = {1}", vmpProp.Name, vmpProp.GetValue(vmp).ToString());
            }
            Console.WriteLine();

            TextWriter owt = string.IsNullOrEmpty(outFileName) ? Console.Out : new StreamWriter(outFileName);

            KP.WriteVerificationPromelaModel(kpModel, kpExperiment, vmp, owt);
            //KP.WritePromela(kpModel.KPsystem, owt);

            return(0);
        }
Example #2
0
        public async Task Verify(FileInfo kplModelFile, IEnumerable <IProperty> properties, FileInfo verificationDirectory, IModelCheckingProgressMonitor monitor)
        {
            await Task.Run(() =>
            {
                try
                {
                    monitor.Start(4, string.Format("Verifying the {0} model using the SPIN modelchecker...", kplModelFile.Name));

                    monitor.LogProgress(0, "Generating the correspoding PROMELA model...");

                    var verificationModelFileName = string.Format("{0}\\{1}.pml", verificationDirectory.FullName, Path.GetFileNameWithoutExtension(kplModelFile.Name));
                    using (var fileWriter = new FileInfo(verificationModelFileName).CreateText())
                    {
                        //Old translator

                        /*
                         * var translationParameters = PromelaTranslationParams.Default();
                         * translationParameters.PrintRuleExecution = false;
                         * translationParameters.PrintConfiguration = false;
                         * translationParameters.PrintTargetSelection = false;
                         * translationParameters.PrintLinks = false;
                         */

                        var translationParameters = VerificationModelParams.Default();

                        KpModel kpModel = null;
                        try
                        {
                            kpModel = KP.FromKpl(kplModelFile.FullName);
                        }
                        catch (KplParseException kplException)
                        {
                            throw new Exception(string.Format("Failed to parse input file {0}. Reason: {1}", kplModelFile.Name, kplException.Message));
                        }

                        var experiment = new Experiment
                        {
                            LtlProperties = properties.Where(p => p is ILtlProperty).Cast <ILtlProperty>().ToList(),
                        };

                        //Old translator
                        //KP.WritePromela(kpModel.KPsystem, experiment, translationParameters, fileWriter);

                        KP.WriteVerificationPromelaModel(kpModel, experiment, translationParameters, fileWriter);
                    }

                    monitor.LogProgress(1, "Translating the PROMELA model into its computationally equivalent verification model...");
                    GenerateModel(verificationDirectory, verificationModelFileName);

                    monitor.LogProgress(2, "Compiling the verification model...");
                    CompileModel(verificationDirectory, verificationModelFileName);

                    monitor.LogProgress(3, "Performing model checking...");
                    ExecuteModel(verificationDirectory, verificationModelFileName);

                    //monitor.LogProgress(4, "Generating the output trail file...");
                    //GenerateTrail(verificationDirectory, verificationModelFileName);

                    monitor.Done("Finished the verification process");
                }
                catch (Exception e)
                {
                    monitor.Terminate("Verification failed: " + e.Message);
                }
            });
        }
Example #3
0
 public static void WriteVerificationPromelaModel(KpModel kpModel, Experiment kpExperiment, VerificationModelParams parameters, TextWriter writer)
 {
     new VerificationModelWriter(writer, parameters).Write(kpModel, kpExperiment);
 }