Exemple #1
0
 /// <summary>
 /// Check if the term represented by goal is reachable in the given model program.
 /// Empty string as goal results in traversing the whole state space.
 /// </summary>
 /// <param name="mp">The model program to be checked.</param>
 /// <param name="goal">The goal term involving the model program name as outer function symbol.</param>
 /// <param name="excludeIsomorphicStates">Whether to use the symmetry reduction. Default is false.</param>
 public static ReachabilityResult Check(ModelProgram mp, string goal, bool excludeIsomorphicStates = false)
 {
     Reachability reach = new Reachability();
     reach.ModelProgram = mp;
     reach.excludeIsomorphicStates = excludeIsomorphicStates;
     return reach.CheckReachability(goal);
 }
Exemple #2
0
 public void SwitchTest()
 {
     Reachability mc = new Reachability();
     //mc.ExcludeIsomorphicStates = false;
     mc.ModelProgram = LibraryModelProgram.Create(typeof(SampleModels.PowerSwitch.Contract));
     ReachabilityResult result=mc.CheckReachability();
     Assert.AreEqual(result.StateCount, 2, "The state count returned differs from actual...");
     Assert.AreEqual(result.TransitionCount, 2, "The transition count returned differs from actual...");
 }
Exemple #3
0
        public static void Run(List<Assembly> assemblies, string goalString)
        {
            MCCmdLineParams settings = new MCCmdLineParams();
            //            if (!Parser.ParseArgumentsWithUsage(args, settings))
            //            {
            //                return;
            //            }

            #region load the libraries
            List<Assembly> libs = new List<Assembly>();
            try
            {

                if ( assemblies != null)
                {
                    foreach (Assembly l in assemblies)
                    {
            //                        libs.Add(System.Reflection.Assembly.LoadFrom(l));
                        libs.Add(l);
                    }
                }
            }
            catch (Exception e)
            {
                throw new ModelProgramUserException(e.Message);
            }
            #endregion

            #region load the test cases if any
            CompoundTerm goal = null;
            if (!String.IsNullOrEmpty(settings.goal))
            {
                try
                {
                    System.IO.StreamReader goalReader =
                        new System.IO.StreamReader(settings.goal);
                    string goalAsString = goalReader.ReadToEnd();
                    goalReader.Close();
                    goal = CompoundTerm.Parse(goalAsString);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Cannot create goal: " + e.Message);
                }
            }
            else
            {
                Console.WriteLine("No goal was specified, counting distinct states and transitions.");
                Console.WriteLine("Invalid end states check currently not enabled.");
            }
            #endregion

            #region create a model program for each model using the factory method and compose into product
            string mpMethodName;
            string mpClassName;
            ModelProgram mp = null;
            if (settings.model != null && settings.model.Length > 0)
            {
                if (libs.Count == 0)
                {
                    throw new ModelProgramUserException("No reference was provided to load models from.");
                }
                ReflectionHelper.SplitFullMethodName(settings.model[0], out mpClassName, out mpMethodName);
                Type mpType = ReflectionHelper.FindType(libs, mpClassName);
                MethodInfo mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                try
                {
                    mp = (ModelProgram)mpMethod.Invoke(null, null);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Invocation of '" + settings.model[0] + "' failed: " + e.ToString());
                }
                for (int i = 1; i < settings.model.Length; i++)
                {
                    ReflectionHelper.SplitFullMethodName(settings.model[i], out mpClassName, out mpMethodName);
                    mpType = ReflectionHelper.FindType(libs, mpClassName);
                    mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                    ModelProgram mp2 = null;
                    try
                    {
                        mp2 = (ModelProgram)mpMethod.Invoke(null, null);
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Invocation of '" + settings.model[i] + "' failed: " + e.ToString());
                    }
                    mp = new ProductModelProgram(mp, mp2);
                }
            }
            #endregion

            if (mp == null)
            {
                Console.WriteLine("ModelProgram was null");
                Console.WriteLine("Tried to instantiate:");
                if (settings.model != null)
                    foreach (string s in settings.model)
                        Console.WriteLine(s);
                return;
            }
            Reachability mc = new Reachability();
            mc.excludeIsomorphicStates = settings.excludeIsomorphic;
            mc.modelProgram = mp;
            DateTime before = DateTime.Now;
            ReachabilityResult result = mc.CheckReachability();
            DateTime after = DateTime.Now;
            Console.WriteLine("Results of reachability checking:");
            Console.WriteLine();
            Console.WriteLine(" States reached: " + result.StateCount);
            Console.WriteLine(" Transitions covered: " + result.TransitionCount);
        }
Exemple #4
0
        public static void RunWithCommandLineArguments(string[] args)
        {
            MCCmdLineParams settings = new MCCmdLineParams();

            if (!Parser.ParseArgumentsWithUsage(args, settings))
            {
                return;
            }



            #region load the libraries
            List <Assembly> libs = new List <Assembly>();
            try
            {
                if (settings.reference != null)
                {
                    foreach (string l in settings.reference)
                    {
                        libs.Add(System.Reflection.Assembly.LoadFrom(l));
                    }
                }
            }
            catch (Exception e)
            {
                throw new ModelProgramUserException(e.Message);
            }
            #endregion

            #region load the test cases if any
            CompoundTerm goal = null;
            if (!String.IsNullOrEmpty(settings.goal))
            {
                try
                {
                    System.IO.StreamReader goalReader =
                        new System.IO.StreamReader(settings.goal);
                    string goalAsString = goalReader.ReadToEnd();
                    goalReader.Close();
                    goal = CompoundTerm.Parse(goalAsString);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Cannot create goal: " + e.Message);
                }
            }
            else
            {
                Console.WriteLine("No goal was specified, counting distinct states and transitions.");
                Console.WriteLine("Invalid end states check currently not enabled.");
            }
            #endregion

            #region create a model program for each model using the factory method and compose into product
            string       mpMethodName;
            string       mpClassName;
            ModelProgram mp = null;
            if (settings.model != null && settings.model.Length > 0)
            {
                if (libs.Count == 0)
                {
                    throw new ModelProgramUserException("No reference was provided to load models from.");
                }
                ReflectionHelper.SplitFullMethodName(settings.model[0], out mpClassName, out mpMethodName);
                Type       mpType   = ReflectionHelper.FindType(libs, mpClassName);
                MethodInfo mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                try
                {
                    mp = (ModelProgram)mpMethod.Invoke(null, null);
                }
                catch (Exception e)
                {
                    throw new ModelProgramUserException("Invocation of '" + settings.model[0] + "' failed: " + e.ToString());
                }
                for (int i = 1; i < settings.model.Length; i++)
                {
                    ReflectionHelper.SplitFullMethodName(settings.model[i], out mpClassName, out mpMethodName);
                    mpType   = ReflectionHelper.FindType(libs, mpClassName);
                    mpMethod = ReflectionHelper.FindMethod(mpType, mpMethodName, Type.EmptyTypes, typeof(ModelProgram));
                    ModelProgram mp2 = null;
                    try
                    {
                        mp2 = (ModelProgram)mpMethod.Invoke(null, null);
                    }
                    catch (Exception e)
                    {
                        throw new ModelProgramUserException("Invocation of '" + settings.model[i] + "' failed: " + e.ToString());
                    }
                    mp = new ProductModelProgram(mp, mp2);
                }
            }
            #endregion

            if (mp == null)
            {
                Console.WriteLine("ModelProgram was null");
                Console.WriteLine("Tried to instantiate:");
                if (settings.model != null)
                {
                    foreach (string s in settings.model)
                    {
                        Console.WriteLine(s);
                    }
                }
                return;
            }
            Reachability mc = new Reachability();
            mc.excludeIsomorphicStates = settings.excludeIsomorphic;
            mc.modelProgram            = mp;
            DateTime           before = DateTime.Now;
            ReachabilityResult result = mc.CheckReachability();
            DateTime           after  = DateTime.Now;
            Console.WriteLine("Results of reachability checking:");
            Console.WriteLine();
            Console.WriteLine(" States reached: " + result.StateCount);
            Console.WriteLine(" Transitions covered: " + result.TransitionCount);
        }