Example #1
0
        protected SafetyAnalysisResults <SafetySharpRuntimeModel> DccaWithMaxCardinality(ModelBase model, Formula hazard, int maxCardinality, ModelCapacity capacity)
        {
            var analysis = new SafetySharpSafetyAnalysis
            {
                Backend       = (SafetyAnalysisBackend)Arguments[0],
                Configuration =
                {
                    ModelCapacity          = capacity,
                    GenerateCounterExample = !SuppressCounterExampleGeneration
                }
            };

            analysis.OutputWritten += message => Output.Log("{0}", message);

            if (Heuristics != null)
            {
                analysis.Heuristics.AddRange(Heuristics);
            }

            var result = analysis.ComputeMinimalCriticalSets(model, hazard, maxCardinality);

            Output.Log("{0}", result);

            return(result);
        }
Example #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}");
        }
Example #4
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);
        }
Example #5
0
        protected bool[] CheckInvariants(IComponent component, params Formula[] invariants)
        {
            var analysisTestsVariant = (AnalysisTestsVariant)Arguments[0];

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

            analysisTestsVariant.CreateModelChecker(SuppressCounterExampleGeneration, logAction);

            var modelCreator = SafetySharpRuntimeModel.CreateExecutedModelFromFormulasCreator(TestModel.InitializeModel(component));

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

            CounterExamples = results.Select(result => result.CounterExample).ToArray();
            return(results.Select(result => result.FormulaHolds).ToArray());
        }
Example #6
0
        protected SafetyAnalysis.Result DccaWithMaxCardinality(ModelBase model, Formula hazard, int maxCardinality)
        {
            var analysis = new SafetyAnalysis {
                Configuration = { StateCapacity = 1 << 10 }
            };

            analysis.OutputWritten += message => Output.Log("{0}", message);

            var result = analysis.ComputeMinimalCriticalSets(model, hazard, maxCardinality);

            Output.Log("{0}", result);

            result.Model.ShouldBe(model);
            return(result);
        }
Example #7
0
        private dynamic CreateModelChecker()
        {
            dynamic modelChecker = Activator.CreateInstance((Type)Arguments[0]);

            modelChecker.OutputWritten += (Action <string>)(message => Output.Log("{0}", message));

            var ssharpChecker = modelChecker as SSharpChecker;

            if (ssharpChecker != null)
            {
                ssharpChecker.Configuration.StateCapacity = 1 << 16;
            }

            return(modelChecker);
        }
Example #8
0
        protected void Check(Formula actual, Formula expected)
        {
            var builder = new StringBuilder();

            builder.AppendLine("Actual:");
            builder.AppendLine(actual.ToString());
            builder.AppendLine();

            builder.AppendLine("Expected:");
            builder.AppendLine(expected.ToString());

            Output.Log("{0}", builder);

            IsStructurallyEquivalent(actual, expected).ShouldBe(true);
        }
Example #9
0
        protected bool Compile(string testFile)
        {
            var projectPath = Path.Combine(_directory, "TestProject.csproj");

            File.Copy("End2End/Files/TestProject.csproj", projectPath, overwrite: true);
            File.Copy(Path.Combine("End2End/Files", testFile), Path.Combine(_directory, "TestCode.cs"), overwrite: true);

            var msbuildPath = ToolLocationHelper.GetPathToBuildTools(ToolLocationHelper.CurrentToolsVersion);

            var process = new ExternalProcess(Path.Combine(msbuildPath, "msbuild.exe"),
                                              $"\"{projectPath}\" /p:Configuration=Release /p:Platform=AnyCPU /nr:false",
                                              message => Output.Log("{0}", message));

            process.Run();
            return(process.ExitCode == 0);
        }
        protected OrderAnalysisResults <SafetySharpRuntimeModel> AnalyzeOrder(Formula hazard, params IComponent[] components)
        {
            var configuration = AnalysisConfiguration.Default;

            configuration.ModelCapacity          = ModelCapacityByMemorySize.Tiny;
            configuration.GenerateCounterExample = !SuppressCounterExampleGeneration;
            configuration.ProgressReportsOnly    = true;
            configuration.DefaultTraceOutput     = Output.TextWriterAdapter();

            var analysis = new SafetySharpOrderAnalysis(DccaWithMaxCardinality(hazard, Int32.MaxValue, components), configuration);

            var result = analysis.ComputeOrderRelationships();

            Output.Log("{0}", result);

            return(result);
        }
Example #11
0
        protected void GenerateCode(SerializationMode mode, params object[] objects)
        {
            objects = SerializationRegistry.Default.GetReferencedObjects(objects, mode).ToArray();
            var model = TestModel.InitializeModel(new DummyComponent(objects));

            _objectTable      = new ObjectTable(objects);
            StateVectorLayout = SerializationRegistry.Default.GetStateVectorLayout(model, _objectTable, mode);
            _serializer       = StateVectorLayout.CreateSerializer(_objectTable);
            _deserializer     = StateVectorLayout.CreateDeserializer(_objectTable);
            _rangeRestrictor  = StateVectorLayout.CreateRangeRestrictor(_objectTable);

            StateSlotCount  = StateVectorLayout.SizeInBytes / 4;
            StateVectorSize = StateVectorLayout.SizeInBytes;
            _buffer         = new MemoryBuffer();
            _buffer.Resize(StateVectorSize, zeroMemory: true);
            SerializedState = _buffer.Pointer;

            Output.Log("{0}", StateVectorLayout);
        }
Example #12
0
        protected void GenerateStateSpace(params IComponent[] components)
        {
            var serializer = new RuntimeModelSerializer();

            serializer.Serialize(TestModel.InitializeModel(components), new StateFormula(() => true));

            var configuration = AnalysisConfiguration.Default;

            configuration.StateCapacity = 10000;
            configuration.StackCapacity = 10000;
            configuration.CpuCount      = 1;

            var checker = new InvariantChecker(serializer.Load, s => Output.Log("{0}", s), configuration);

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

            Output.Log($"States: {_result.StateCount}");
            Output.Log($"Actual Transitions: {_result.TransitionCount}");
            Output.Log($"Computed Transitions: {_result.ComputedTransitionCount}");
        }