Beispiel #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);
        }
Beispiel #2
0
        private static void PerformNuSmvTransation(string[] args)
        {
            var argIndex = 1;

            if (args.Length < 3)
            {
                throw new Exception("Source file with kP system model not specified.");
            }

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

            if (!fi.Exists)
            {
                throw new Exception(string.Format("File '{0}' does not exist. Please specify a valid input file.", kplFileName));
            }

            string outFileName = null;
            string kpxFileName = null;

            for (int i = ++argIndex; i < args.Length; i++)
            {
                if (args[i] == "-e")
                {
                    if (++i < args.Length)
                    {
                        kpxFileName = args[i];
                    }
                }
                else if (args[i] == "-o")
                {
                    if (++i < args.Length)
                    {
                        outFileName = args[i];
                    }
                }
            }

            KpModel kpModel = null;

            try
            {
                Console.WriteLine("-- KP model is loading");
                kpModel = KP.FromKpl(kplFileName);
                Console.WriteLine("---- KP model loaded");
            }
            catch (KplParseException kplException)
            {
                throw new Exception(string.Format("Failed to parse input file {0}. Reason: {1}", kplFileName, kplException.Message));
            }

            Experiment kpExperiment = null;

            if (!string.IsNullOrEmpty(kpxFileName))
            {
                if (new FileInfo(kpxFileName).Exists)
                {
                    try
                    {
                        kpExperiment = KP.FromKpx(kpxFileName);
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(string.Format("Failed to parse input file {0}. Reason: {1}", kplFileName, exception.Message));
                    }
                }
                else
                {
                    throw new Exception(string.Format("File '{0}' does not exist. Please specify a valid experiment file.", kpxFileName));
                }
            }

            Console.WriteLine("-- Translation to NuSMV is starting");
            TranslateSMV.Translate(kpModel, kpExperiment, outFileName);
            Console.WriteLine("---- KP model translated NuSMV model successfully.");
        }
Beispiel #3
0
        private static void PerformPromelaTranslation(string[] args)
        {
            var kplFileName           = string.Empty;
            var kpxFileName           = string.Empty;
            var outputFileName        = string.Empty;
            var translationParameters = PromelaTranslationParams.Default();
            var properties            = typeof(PromelaTranslationConfig).GetProperties();
            var argIndex = 1;

            if (args.Length >= 2)
            {
                kplFileName = args[argIndex++];

                if (!new FileInfo(kplFileName).Exists)
                {
                    throw new Exception(string.Format("File '{0}' does not exist. Please specify a valid input file.", kplFileName));
                }
            }
            else
            {
                throw new Exception("Source file with kP system model not specified");
            }

            for (int i = argIndex; i < args.Length; i++)
            {
                if (args[i] == "-e")
                {
                    if (++i < args.Length)
                    {
                        kpxFileName = args[i];
                    }
                }
                else
                {
                    if (args[i] == "-o")
                    {
                        if (++i < args.Length)
                        {
                            outputFileName = 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 property in properties)
                            {
                                if (property.Name == prop)
                                {
                                    try
                                    {
                                        if (property.PropertyType == typeof(Int32))
                                        {
                                            property.SetValue(translationParameters, Int32.Parse(val));
                                        }
                                        else if (property.PropertyType == typeof(bool))
                                        {
                                            property.SetValue(translationParameters, bool.Parse(val));
                                        }
                                        else
                                        {
                                            property.SetValue(translationParameters, val);
                                        }
                                    }
                                    catch
                                    {
                                        throw new Exception(string.Format("*** Warning. Invalid format for property {0}: value must be of type {1}",
                                                                          property.Name, property.PropertyType.ToString()));
                                    }
                                    propertyRecognized = true;
                                    break;
                                }
                            }

                            if (!propertyRecognized)
                            {
                                throw new Exception(string.Format("*** Warning. Property {0} not recognized.", prop));
                            }
                        }
                    }
                }
            }

            KpModel kpModel = null;

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

            Experiment kpExperiment = null;

            if (!string.IsNullOrEmpty(kpxFileName))
            {
                if (new FileInfo(kpxFileName).Exists)
                {
                    try
                    {
                        kpExperiment = KP.FromKpx(kpxFileName);
                    }
                    catch (Exception exception)
                    {
                        throw new Exception(string.Format("Failed to parse input file {0}. Reason: {1}", kplFileName, exception.Message));
                    }
                }
                else
                {
                    throw new Exception(string.Format("File '{0}' does not exist. Please specify a valid experiment file.", kpxFileName));
                }
            }

            Console.WriteLine("Generating verification model {0} with: ", outputFileName);
            Console.WriteLine();
            foreach (PropertyInfo property in properties)
            {
                Console.WriteLine("{0} = {1}", property.Name, property.GetValue(translationParameters).ToString());
            }
            Console.WriteLine();

            var stream = string.IsNullOrEmpty(outputFileName) ? Console.Out : new StreamWriter(outputFileName);

            KP.WritePromela(kpModel.KPsystem, kpExperiment, translationParameters, stream);
        }