Beispiel #1
0
 private void Add(SpecificationBase spec)
 {
     if (spec != null)
     {
         this.registry.Add(spec);
     }
 }
        public override void Initialize(SpecificationBase spec)
        {
            //initialize the ModelCheckingOptions
            base.Initialize(spec);

            Specification Spec = spec as Specification;

            ReachableStateCondition = Spec.DeclarationDatabase[ReachableStateLabel];

            List <string> varList = Process.GetGlobalVariables();

            varList.AddRange(ReachableStateCondition.GetVars());
            varList.AddRange(ConstraintCondition.GetVars());

            Valuation GlobalEnv = Spec.SpecValuation.GetVariableChannelClone(varList, Process.GetChannels());

            //Initialize InitialStep
            InitialStep = new Configuration(Process, Constants.INITIAL_EVENT, null, GlobalEnv, false);

            MustAbstract = Process.MustBeAbstracted();

            if (MustAbstract)
            {
                throw new ParsingException(
                          "Process " + StartingProcess +
                          " has infinite states and therefore can not be used to assert reachability with MIN/MAX constraints!",
                          AssertToken);
            }
        }
Beispiel #3
0
        public SpecificationBase GetSpecification()
        {
            if (_resolvedSpecificationBase == null)
            {
                //Lazy Load Specification
                if (String.IsNullOrEmpty(_specificationType))
                {
                    //No Specification specified, so get Default Specification For Type from Validation Catalog
                    _resolvedSpecificationBase = ValidationCatalog.SpecificationContainer.TryGetSpecification(GetTypeToValidate());
                }
                else
                {
                    //Get Specification from Type
                    //Create type from string
                    var specType = System.Type.GetType(_specificationType);

                    if (specType == null)
                    {
                        //Type creation failed
                        return(null);
                    }
                    else
                    {
                        //Query the Validation Catalog from the specification that matches type in the Catalog
                        _resolvedSpecificationBase = ValidationCatalog.SpecificationContainer.GetAllSpecifications().Where(
                            x => x.GetType() == specType).FirstOrDefault();
                    }
                }
            }

            return(_resolvedSpecificationBase);
        }
        public override void Initialize(SpecificationBase spec)
        {
            //initialize the ModelCheckingOptions
            base.Initialize(spec);

            Assertion.Initialize(this, ImplementationProcess, SpecificationProcess, spec);
        }
        public SpecificationBase GetSpecification()
        {
            if (_resolvedSpecificationBase == null)
            {
                //Lazy Load Specification
                if (String.IsNullOrEmpty(_specificationType))
                {
                    //No Specification specified, so get Default Specification For Type from Validation Catalog
                    _resolvedSpecificationBase = ValidationCatalog.SpecificationContainer.TryGetSpecification(GetTypeToValidate());
                }
                else
                {
                    //Get Specification from Type
                    //Create type from string
                    var specType = System.Type.GetType(_specificationType);

                    if (specType == null)
                    {
                        //Type creation failed
                        return null;
                    }
                    else
                    {
                        //Query the Validation Catalog from the specification that matches type in the Catalog
                        _resolvedSpecificationBase = ValidationCatalog.SpecificationContainer.GetAllSpecifications().Where(
                            x => x.GetType() == specType).FirstOrDefault();
                    }
                }
            }

            return _resolvedSpecificationBase;
        }
Beispiel #6
0
        public DiagnosisResult executeAssertion(SpecificationBase spec, String assertionName)
        {
            AssertionBase     assertion = spec.AssertionDatabase[assertionName];
            AssertionVerifier verifier  = new AssertionVerifier(assertion, 1, 0);

            return(verifier.Run());
        }
Beispiel #7
0
        public void DisplayTree(SpecificationBase Spec)
        {
            try
            {
                Specification = Spec;

                foreach (TreeNode node in TreeView_Model.Nodes)
                {
                    node.Nodes.Clear();
                }

                if (Spec != null)
                {
                    foreach (KeyValuePair <string, Declaration> pair in Spec.DeclaritionTable)
                    {
                        try
                        {
                            TreeNode node = this.TreeView_Model.Nodes[pair.Value.DeclarationType.ToString()].Nodes.Add(pair.Key);

                            node.Tag = pair.Value.DeclarationToken;
                        }
                        catch (Exception)
                        {
                        }
                    }

                    TreeView_Model.ExpandAll();
                }
            }
            catch (Exception)
            {
            }
        }
Beispiel #8
0
        public List <VerifyResult> SyncVerify(List <ArchDesignConfig> designSet)
        {
            PATUtil util = new PATUtil();

            // generate CSP Code
            resultSet = new List <VerifyResult>();
            List <ThreadedVerificationExecuter <VerifyResult> > threadsList = new List <ThreadedVerificationExecuter <VerifyResult> >();
            ThreadedVerificationExecuter <VerifyResult>         thread;

            PAT.CSP.ModuleFacade modulebase = new PAT.CSP.ModuleFacade();
            foreach (ArchDesignConfig designConfig in designSet)
            {
                VerifyAsset       verifyAsset = util.GenerateAsset(designConfig.matrix);
                SpecificationBase specbase    = modulebase.ParseSpecification(verifyAsset.CSPCode, string.Empty, string.Empty);
                thread = new ThreadedVerificationExecuter <VerifyResult>(collectVerifyResult, verifyAsset, specbase);
                threadsList.Add(thread);
                thread.Start();
            }

            while (resultSet.Count < designSet.Count)
            {
                System.Diagnostics.Debug.WriteLine("Waiting for result " + resultSet.Count);
            }
            return(resultSet);
        }
        public void executeVerification(VerifyAsset verifyAsset, SpecificationBase specbase)
        {
            //initialize CSP module with CSP Code

            PATUtil   util = new PATUtil();
            Stopwatch sw   = new Stopwatch();

            sw.Start();

            // run assertions and gather results
            ConcurrentBag <DiagnosisResult> results = new ConcurrentBag <DiagnosisResult>();

            foreach (String assertionName in verifyAsset.deadloopCheck)
            {
                results.Add(util.executeAssertion(specbase, assertionName));
            }
            foreach (String assertionName in verifyAsset.livelockCheck)
            {
                results.Add(util.executeAssertion(specbase, assertionName));
            }
            sw.Stop();
            VerifyResult verResult = new VerifyResult();

            verResult.elapseTime    = sw.ElapsedMilliseconds;
            verResult.diagnosisList = results;
            System.Diagnostics.Debug.WriteLine("Total Result" + results.Count);


            T stuffReturned = (T)Convert.ChangeType(verResult, typeof(T));

            callback(stuffReturned);
        }
Beispiel #10
0
        public void executeAssertion(SpecificationBase spec, String assertionName)
        {
            AssertionBase     assertion = spec.AssertionDatabase[assertionName];
            AssertionVerifier verifier  = new AssertionVerifier(assertion, 1, 0);
            T stuffReturned             = (T)Convert.ChangeType(verifier.Run(), typeof(T));

            callback(stuffReturned);
        }
Beispiel #11
0
 protected ISpecification <TEntity> InitializeSpecification(ISpecification <TEntity> specification)
 {
     if (specification == null)
     {
         specification = new SpecificationBase <TEntity>();
     }
     return(specification);
 }
Beispiel #12
0
        public void DoubleNotSpecificationTrueTest(string name)
        {
            var spec1 = new SpecificationBase <SimpleTestObject>(t => t.Name == name);

            var spec = !!spec1;

            Assert.True(spec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
        }
Beispiel #13
0
 //todo properly handle deletable and expirable
 public void Remove(SpecificationBase <T> specification)
 {
     if (specification == null)
     {
         throw new ArgumentNullException(nameof(specification));
     }
     _dbSet.RemoveRange(_dbSet.Where(specification.ToExpression())
                        .Select(x => x));
 }
Beispiel #14
0
 // handle translation
 public IEnumerable <T> Find(SpecificationBase <T> spec)
 {
     return(EnableTranslation && _lexiconDictionary.IsMultiLingualEntity(typeof(T))
         ? _lexiconDictionary.Translate(
                ApplySpecification(spec)
                .ToList(), _userContext?.Identity.LanguageIsoCode)
         : ApplySpecification(spec)
            .ToList());
 }
Beispiel #15
0
        //private string GetOption()
        //{
        //    string option = "";
        //    option += MenuButton_EnableSimplificationOfTheFormula.Checked ? "" : "l";
        //    option += MenuButton_EnableOntheflyAutomataSimplification.Checked ? "" : "o";
        //    option += MenuButton_EnableAPosterioriAutomataSimplification.Checked ? "" : "p";
        //    option += MenuButton_EnableStronglyConnectedComponentsSimplification.Checked ? "" : "c";
        //    option += MenuButton_EnableTrickingInAcceptingConditions.Checked ? "" : "a";
        //    return option;
        //}

        private SpecificationBase parseSpecification()
        {
            SpecificationBase spec = null;

            do
            {
                if (mTabItem == null || mTabItem.Text.Trim() == "")
                {
                    DevLog.e(TAG, "mTabItem is null");
                    break;
                }

                // DisableAllControls();
                try
                {
                    string moduleName = mTabItem.ModuleName;
                    if (LoadModule(moduleName))
                    {
                        //string option = GetOption();
                        Stopwatch t = new Stopwatch();
                        // DisableAllControls();
                        disableAllControls();
                        t.Start();
                        spec = mModule.ParseSpecification(mTabItem.Text, "", mTabItem.FileName);
                        t.Stop();

                        if (spec != null)
                        {
                            mTabItem.Specification = spec;
                            if (spec.Errors.Count > 0)
                            {
                                string key = "";
                                foreach (KeyValuePair <string, ParsingException> pair in spec.Errors)
                                {
                                    key = pair.Key;
                                    break;
                                }

                                ParsingException parsingException = spec.Errors[key];
                                spec.Errors.Remove(key);
                                throw parsingException;
                            }
                        }

                        // Spec = spec;
                        initLogic();
                        enableAllControls();
                        // EnableAllControls();
                    }
                }
                catch (ParsingException ex) { }
                catch (Exception ex) { }
            } while (false);

            return(spec);
        }
Beispiel #16
0
        public void SpecificationOrSpecificationFalseTest(string name, int count)
        {
            var spec1 = new SpecificationBase <SimpleTestObject>(t => t.Name == name);
            var spec2 = new SpecificationBase <SimpleTestObject>(t => t.Count == count);

            var spec = spec1 | spec2;

            Assert.False(spec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
            Assert.False(spec.Or(spec2).IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
        }
Beispiel #17
0
        public void Configuration_NewOrderSpecification_ShouldBeCorrectlyConfigured()
        {
            var configuration = new SpecificationBase <Entity>(new OrderSpecification <Entity, int>(x => x.Value1));

            configuration.QuerySpecification.Internal.Should().NotBeNull();
            configuration.QuerySpecification.Should().NotBeNull();
            configuration.QuerySpecification.AsExpression().Should().BeNull();
            configuration.QuerySpecification.AsFunc().Should().BeNull();
            configuration.OrderSpecifications.Count.Should().Be(1);
        }
Beispiel #18
0
        /// <summary>
        /// Assertion Initialization to create the initial step based on the concrete types.
        /// This method shall be invoked after the parsing immediately to instanciate the initial step
        /// </summary>
        /// <param name="spec">The concrete specification of the module</param>
        public override void Initialize(SpecificationBase spec)
        {
            //initialize model checking options, the default option is for deadlock/reachablity algorithms
            ModelCheckingOptions = new ModelCheckingOptions();
            List <string> DeadlockEngine = new List <string>();

            DeadlockEngine.Add(Constants.ENGINE_SMT_DTMC);
            DeadlockEngine.Add(Constants.ENGINE_SMT_MDP);
            ModelCheckingOptions.AddAddimissibleBehavior(Constants.COMPLETE_BEHAVIOR, DeadlockEngine);
        }
Beispiel #19
0
        public void Configuration_NewSpecification_ShouldBeCorrectlyConfigured()
        {
            var configuration = new SpecificationBase <Entity>(new Specification <Entity>());

            configuration.QuerySpecification.Internal.Should().NotBeNull();
            configuration.QuerySpecification.Should().NotBeNull();
            configuration.QuerySpecification.AsExpression().Should().BeNull();
            configuration.QuerySpecification.AsFunc().Should().BeNull();
            configuration.OrderSpecifications.Any().Should().BeFalse();
        }
        public IQueryable<Loan> FindElementsBy(SpecificationBase<Loan> spec)
        {
            Loan[] loans = new[]{
                                new Loan(){DateTaken = DateTime.Now.AddDays(-15) , LoanPeriod = new TimeSpan(14,0,0,0),Amount = 15000.0},
                                new Loan(){DateTaken = DateTime.Now.AddDays(-5), LoanPeriod = new TimeSpan(6,0,0,0),Amount = 10000.0},
                                new Loan(){DateTaken = DateTime.Now.AddDays(-7), LoanPeriod = new TimeSpan(6,0,0,0),Amount = 5000.0}
                                };

            return spec.SatisfyingElementsFrom(loans.AsQueryable());
        }
Beispiel #21
0
        //Exception Logging for the application
        public static void LogException(Exception ex, SpecificationBase spec)
        {
            ExceptionDialog log = new ExceptionDialog(ex, APPLICATION_NAME, spec);

            log.ShowDialog();
            if (Common.Utility.Utilities.IsWindowsOS)
            {
                FlashWindowEx(log);
            }
        }
Beispiel #22
0
 // handle translation : TODO manage paging, orderby & translation
 public async Task <IEnumerable <T> > FindAsync(SpecificationBase <T> specification,
                                                CancellationToken cancellationToken = default)
 {
     return(EnableTranslation && _lexiconDictionary.IsMultiLingualEntity(typeof(T))
         ? _lexiconDictionary.Translate(
                await ApplySpecification(specification)
                .ToListAsync(cancellationToken), _userContext?.Identity.LanguageIsoCode)
         : await ApplySpecification(specification)
            .ToListAsync(cancellationToken));
 }
Beispiel #23
0
        public static void Initialize(AssertionBase Assertion, PetriNet Process, SpecificationBase spec)
        {
            Specification Spec = spec as Specification;

            //get the relevant global variables; remove irrelevant variables so as to save memory;
            Valuation GlobalEnv = Spec.SpecValuation.GetClone();

            //Initialize InitialStep
            Assertion.InitialStep = new PNConfiguration(Process, Constants.INITIAL_EVENT, null, GlobalEnv, false, spec);
        }
Beispiel #24
0
        // This method is called on a worker thread (via asynchronous
        // delegate invocation).  This is where we call the operation (as
        // defined in the deriving class's DoWork method).
        public void InternalStart()
        {
            // isRunning is set during Start to avoid a race condition
            try
            {
                Spec = CurrentModule.ParseSpecification(this.Text, Options, File);

                OnReturnResult();
            }
            catch (CancelRunningException)
            {
                AcknowledgeCancel();
            }
            catch (Exception e)
            {
                // Raise the Failed event.  We're in a catch handler, so we
                // had better try not to throw another exception.
                try
                {
                    if (e is System.OutOfMemoryException)
                    {
                        e = new PAT.Common.Classes.Expressions.ExpressionClass.OutOfMemoryException("");
                    }

                    FailOperation(e);
                }
                catch
                {
                }

                // The documentation recommends not catching
                // SystemExceptions, so having notified the caller we
                // rethrow if it was one of them.
                if (e is SystemException)
                {
                    throw;
                }
            }


            lock (this)
            {
                // If the operation wasn't cancelled (or if the UI thread
                // tried to cancel it, but the method ran to completion
                // anyway before noticing the cancellation) and it
                // didn't fail with an exception, then we complete the
                // operation - if the UI thread was blocked waiting for
                // cancellation to complete it will be unblocked, and
                // the Completion event will be raised.
                if (!cancelAcknowledgedFlag && !failedFlag)
                {
                    CompleteOperation();
                }
            }
        }
Beispiel #25
0
 public static void LockSharedData(SpecificationBase specification)
 {
     if (ShareDataLock != null && ShareDataLock.ToString() == "True")
     {
         lock (ShareDataLock)
         {
             ShareDataLock = specification;
             specification.LockSpecificationData();
         }
     }
 }
Beispiel #26
0
        public SpecificationWorker(PNExtendInfo pnExtendInfo, SpecificationBase spec, ISpecificationWorker listener, Form parentFrm)
        {
            mExtendInfo = pnExtendInfo;
            mSpec       = spec;
            mListener   = listener;
            mForm       = parentFrm;

            // Setup timer
            mTimer          = new Timer();
            mTimer.Tick    += MCTimer_Tick;
            mTimer.Interval = 1000;
        }
Beispiel #27
0
        /// <summary>
        /// Assertion Initialization to create the initial step based on the concrete types.
        /// This method shall be invoked after the parsing immediately to instanciate the initial step
        /// </summary>
        /// <param name="spec">The concrete specification of the module</param>
        public override void Initialize(SpecificationBase spec)
        {
            //initialize model checking options, the default option is for deadlock/reachablity algorithms
            ModelCheckingOptions = new ModelCheckingOptions();
            List <string> engines = new List <string>();

            engines.Add(Constants.ENGINE_FD_REFINEMENT_ANTICHAIN_DEPTH_FIRST_SEARCH);
            engines.Add(Constants.ENGINE_FD_REFINEMENT_ANTICHAIN_BREADTH_FIRST_SEARCH);
            engines.Add(Constants.ENGINE_FD_REFINEMENT_DEPTH_FIRST_SEARCH);
            engines.Add(Constants.ENGINE_FD_REFINEMENT_BREADTH_FIRST_SEARCH);
            ModelCheckingOptions.AddAddimissibleBehavior(Constants.COMPLETE_BEHAVIOR, engines);
        }
Beispiel #28
0
        public void NotSpecificationTest(string name)
        {
            var trueSpec = new SpecificationBase <SimpleTestObject>(t => t.Name == name);

            var falseSpec = !trueSpec;

            Assert.True(trueSpec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
            Assert.False(falseSpec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));

            Assert.True(trueSpec.IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
            Assert.False(trueSpec.Not().IsSatisfiedBy(SimpleTestObject.Create_For_Test_Where_Count_Is_Five_And_Name_Is_Name()));
        }
Beispiel #29
0
 public virtual SpecificationBase ParseSpecification(string text, string options, string filePath)
 {
     if (Common.Classes.Ultility.Ultility.GrabSharedDataLock())
     {
         Specification = InstanciateSpecification(text, options, filePath);
         return(Specification);
     }
     else
     {
         MessageBox.Show(Resources.Please_stop_verification_or_simulation_before_parsing_the_model_, Common.Ultility.Ultility.APPLICATION_NAME, MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
         return(null);
     }
 }
Beispiel #30
0
 public static bool UnLockSharedData(SpecificationBase specification)
 {
     //try to lock the data and operations.
     if (ShareDataLock != null && ShareDataLock == specification)
     {
         lock (ShareDataLock)
         {
             specification.UnLockSpecificationData();
             ShareDataLock = null;
         }
         return(true);
     }
     return(false);
 }
        public SpecificationBase <T> Create <T>(FilterDescriptor filter)
        {
            var expression = this.CreateExpression <T>(filter);


            if (expression == null)
            {
                return(null);
            }

            var spec = new SpecificationBase <T>(expression);

            return(spec);
        }
Beispiel #32
0
        public ModelCheckingForm(string Name, SpecificationBase spec)
        {
            ModelCheckingFormInstance = this;
            InitializeComponent();

            InitializeResourceText();

            this.Spec = spec;

            int Index = 1;

            foreach (KeyValuePair <string, AssertionBase> entry in Spec.AssertionDatabase)
            {
                ListViewItem item = new ListViewItem(new string[] { "", Index.ToString(), entry.Key });

                //if the assertion is LTL, the button of the view BA should be enabled.
                if (entry.Value is AssertionLTL)
                {
                    item.Tag = "LTL";

                    //BuchiAutomata BA = (entry.Value as AssertionLTL).BA;

                    //if (BA != null)
                    //{
                    //    if (BA.HasXOperator)
                    //    {
                    //        item.SubItems[0].Tag = true;
                    //    }
                    //}
                }


                //set the question mark image
                item.ImageIndex = 2;

                this.ListView_Assertions.Items.Add(item);
                Index++;
            }

            if (Name != "")
            {
#if DEBUG
                this.Text = this.Text + " (Debug Model) - " + Name;
#else
                this.Text = this.Text + " - " + Name;
#endif
            }

            this.StatusLabel_Text.Text = Resources.Select_an_assertion_to_start_with;
        }
Beispiel #33
0
 public CategoryBuilder(SpecificationBase specification)
 {
     this.specification = specification;
 }