Exemplo n.º 1
0
        protected override void Check()
        {
            var c           = new C();
            var directModel = InitializeModel(c);

            ((C.Effect1)c.FaultEffects[0]).F = 17;

            _hasConstructorRun = false;

            var newModelInstanceBySerializeDeserialize = SafetySharpRuntimeModel.CreateExecutedModelCreator(directModel).Create(0);

            //"Create" serializes and deserializes again (second time)
            Create(newModelInstanceBySerializeDeserialize.Model);

            ExecutableStateFormulas.ShouldBeEmpty();
            RootComponents.Length.ShouldBe(1);

            var root = RootComponents[0];

            root.ShouldBeOfType <C.Effect1>();
            root.GetSubcomponents().ShouldBeEmpty();

            ((C)root).F1.ShouldBeOfType <TransientFault>();
            ((C.Effect1)root).F.ShouldBe(17);

            root.FaultEffects.Count.ShouldBe(1);
            ((C.Effect1)root.FaultEffects[0]).F.ShouldBe(17);

            typeof(C.Effect1).GetField("__fault__", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(root).ShouldBe(((C)root).F1);

            _hasConstructorRun.ShouldBe(false);
        }
Exemplo n.º 2
0
        protected bool CheckInvariant(Formula invariant, params IComponent[] components)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            var logAction = (Action <string>)(message => Output.Log("{0}", message));

            analysisTestsVariant.CreateModelChecker(SuppressCounterExampleGeneration, logAction);

            var model = TestModel.InitializeModel(components);

            var useCheckInvariantsInsteadOfCheckInvariant = Arguments.Length > 1 && (bool)Arguments[1];

            if (useCheckInvariantsInsteadOfCheckInvariant)
            {
                var modelFromFormulasGenerator = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(model);
                var results = analysisTestsVariant.CheckInvariants(modelFromFormulasGenerator, invariant);
                CounterExample = results[0].CounterExample;
                return(results[0].FormulaHolds);
            }

            var modelGenerator = SafetySharpRuntimeModel.CreateExecutedModelCreator(model, invariant);

            Result         = analysisTestsVariant.CheckInvariant(modelGenerator, invariant);
            CounterExample = Result.CounterExample;
            return(Result.FormulaHolds);
        }
        protected void GenerateStateSpace(params IComponent[] components)
        {
            _modelCreator = SafetySharpRuntimeModel.CreateExecutedModelCreator(TestModel.InitializeModel(components), new ExecutableStateFormula(() => true));

            var configuration = AnalysisConfiguration.Default;

            configuration.ModelCapacity      = ModelCapacityByMemorySize.Small;
            configuration.StackCapacity      = 10000;
            configuration.CpuCount           = 1;
            configuration.DefaultTraceOutput = Output.TextWriterAdapter();
            configuration.AllowFaultsOnInitialTransitions = AllowFaultsOnInitialTransitions;

            var analysisModelCreator = new AnalysisModelCreator(() => new ActivationMinimalExecutedModel <SafetySharpRuntimeModel>(_modelCreator, 0, configuration));

            var checker = new InvariantChecker(analysisModelCreator,
                                               configuration,
                                               formulaIndex: 0);

            _result = checker.Check();
            CounterExample.ShouldBe(null);

            Output.Log($"States: {_result.StateCount}");
            Output.Log($"Actual Transitions: {_result.TransitionCount}");
            Output.Log($"Computed Transitions: {_result.ComputedTransitionCount}");
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Checks whether the <paramref name="formula" /> holds in all states of the <paramref name="model" />. The appropriate model
        ///   checker is chosen automatically.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="formula">The formula that should be checked.</param>
        public static SafetySharpInvariantAnalysisResult Check(ModelBase model, Formula formula)
        {
            var createModel = SafetySharpRuntimeModel.CreateExecutedModelCreator(model, formula);
            var result      = new LtsMin().Check(createModel, formula);

            return(SafetySharpInvariantAnalysisResult.FromInvariantAnalysisResult(result, createModel));
        }
        /// <summary>
        ///   Checks whether the <paramref name="invariant" /> holds in all states of the <paramref name="model" />. The appropriate
        ///   model checker is chosen automatically.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="invariant">The invariant that should be checked.</param>
        public static AnalysisResult <SafetySharpRuntimeModel> CheckInvariant(ModelBase model, Formula invariant)
        {
            var createModel        = SafetySharpRuntimeModel.CreateExecutedModelCreator(model, invariant);
            var qualitativeChecker = new QualitativeChecker <SafetySharpRuntimeModel> {
                Configuration = TraversalConfiguration
            };

            return(qualitativeChecker.CheckInvariant(createModel, formulaIndex: 0));
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Checks whether the <paramref name="invariant" /> holds in all states of the <paramref name="model" />. The appropriate
        ///   model checker is chosen automatically.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="invariant">The invariant that should be checked.</param>
        public static SafetySharpInvariantAnalysisResult CheckInvariant(ModelBase model, Formula invariant)
        {
            var createModel        = SafetySharpRuntimeModel.CreateExecutedModelCreator(model, invariant);
            var qualitativeChecker = new QualitativeChecker <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = TraversalConfiguration
            };
            var result = qualitativeChecker.CheckInvariant(formulaIndex: 0);

            return(SafetySharpInvariantAnalysisResult.FromInvariantAnalysisResult(result, createModel));
        }
Exemplo n.º 7
0
        /// <summary>
        ///   Checks whether the <paramref name="invariants" /> hold in all states of the <paramref name="model" />. The appropriate
        ///   model checker is chosen automatically.
        /// </summary>
        /// <param name="model">The model that should be checked.</param>
        /// <param name="invariants">The invariants that should be checked.</param>
        public static SafetySharpInvariantAnalysisResult[] CheckInvariants(ModelBase model, params Formula[] invariants)
        {
            var createModel        = SafetySharpRuntimeModel.CreateExecutedModelCreator(model, invariants);
            var qualitativeChecker = new QualitativeChecker <SafetySharpRuntimeModel>(createModel)
            {
                Configuration = TraversalConfiguration
            };
            var results    = qualitativeChecker.CheckInvariants(invariants);
            var newResults = results.Select(result => SafetySharpInvariantAnalysisResult.FromInvariantAnalysisResult(result, createModel));

            return(newResults.ToArray());
        }
Exemplo n.º 8
0
        protected bool Check(Formula formula, params IComponent[] components)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            var modelCreator = SafetySharpRuntimeModel.CreateExecutedModelCreator(TestModel.InitializeModel(components), formula);

            analysisTestsVariant.SetModelCheckerParameter(SuppressCounterExampleGeneration, Output.TextWriterAdapter());
            analysisTestsVariant.SetExecutionParameter(AllowFaultsOnInitialTransitions);

            var result = analysisTestsVariant.Check(modelCreator, formula);

            CounterExample = result.ExecutableCounterExample(modelCreator);
            return(result.FormulaHolds);
        }
Exemplo n.º 9
0
        protected bool[] CheckInvariants(IComponent component, params Formula[] invariants)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            var modelCreator = SafetySharpRuntimeModel.CreateExecutedModelCreator(TestModel.InitializeModel(component), invariants);

            analysisTestsVariant.SetModelCheckerParameter(SuppressCounterExampleGeneration, Output.TextWriterAdapter());
            analysisTestsVariant.SetExecutionParameter(AllowFaultsOnInitialTransitions);

            var results = analysisTestsVariant.CheckInvariants(modelCreator, invariants);

            CounterExamples = results.Select(result => result.ExecutableCounterExample(modelCreator)).ToArray();
            return(results.Select(result => result.FormulaHolds).ToArray());
        }
Exemplo n.º 10
0
        protected bool Check(Formula formula, params IComponent[] components)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            var logAction = (Action <string>)(message => Output.Log("{0}", message));

            analysisTestsVariant.CreateModelChecker(SuppressCounterExampleGeneration, logAction);

            var modelCreator = SafetySharpRuntimeModel.CreateExecutedModelCreator(TestModel.InitializeModel(components), formula);
            var result       = analysisTestsVariant.Check(modelCreator, formula);

            CounterExample = result.CounterExample;
            return(result.FormulaHolds);
        }
Exemplo n.º 11
0
        protected bool CheckInvariant(Formula invariant, params IComponent[] components)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

            analysisTestsVariant.SetModelCheckerParameter(SuppressCounterExampleGeneration, Output.TextWriterAdapter());
            analysisTestsVariant.SetExecutionParameter(AllowFaultsOnInitialTransitions);

            var modelCreator = SafetySharpRuntimeModel.CreateExecutedModelCreator(TestModel.InitializeModel(components), invariant);

            var useCheckInvariantsInsteadOfCheckInvariant = Arguments.Length > 1 && (bool)Arguments[1];


            if (useCheckInvariantsInsteadOfCheckInvariant)
            {
                var results = analysisTestsVariant.CheckInvariants(modelCreator, invariant);
                CounterExample = results[0].ExecutableCounterExample(modelCreator);
                return(results[0].FormulaHolds);
            }

            Result         = analysisTestsVariant.CheckInvariant(modelCreator, invariant);
            CounterExample = Result.ExecutableCounterExample(modelCreator);
            return(Result.FormulaHolds);
        }
 /// <summary>
 ///   Checks whether the <paramref name="formula" /> holds in all states of the <paramref name="model" />. The appropriate model
 ///   checker is chosen automatically.
 /// </summary>
 /// <param name="model">The model that should be checked.</param>
 /// <param name="formula">The formula that should be checked.</param>
 public static AnalysisResult <SafetySharpRuntimeModel> Check(ModelBase model, Formula formula)
 {
     return(new LtsMin().Check(SafetySharpRuntimeModel.CreateExecutedModelCreator(model, formula), formula));
 }