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}"); }
/// <summary> /// Checks the invariant encoded into the model created by <paramref name="createModel" />. /// </summary> public InvariantAnalysisResult CheckInvariant(int formulaIndex) { // We have to track the state vector layout here; this will nondeterministically store some model instance of // one of the workers; but since all state vectors are the same, we don't care ExecutedModel <TExecutableModel> model = null; Func <AnalysisModel> createAnalysisModelFunc = () => model = new ActivationMinimalExecutedModel <TExecutableModel>(ModelCreator, 0, Configuration); var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc); using (var checker = new InvariantChecker(createAnalysisModel, Configuration, formulaIndex)) { var result = checker.Check(); return(result); } }
/// <summary> /// Checks the invariant encoded into the model created by <paramref name="createModel" />. /// </summary> public AnalysisResult <TExecutableModel> CheckInvariant(CoupledExecutableModelCreator <TExecutableModel> createModel, Formula formula) { // We have to track the state vector layout here; this will nondeterministically store some model instance of // one of the workers; but since all state vectors are the same, we don't care ExecutedModel <TExecutableModel> model = null; Func <AnalysisModel <TExecutableModel> > createAnalysisModelFunc = () => model = new ActivationMinimalExecutedModel <TExecutableModel>(createModel, 0, Configuration.SuccessorCapacity); var createAnalysisModel = new AnalysisModelCreator <TExecutableModel>(createAnalysisModelFunc); using (var checker = new InvariantChecker <TExecutableModel>(createAnalysisModel, OutputWritten, Configuration, formula)) { var result = checker.Check(); return(result); } }
/// <summary> /// Checks the <see cref="faults" /> for criticality using the <see cref="activation" /> mode. /// </summary> /// <param name="faults">The fault set that should be checked for criticality.</param> /// <param name="activation">The activation mode of the fault set.</param> internal override InvariantAnalysisResult CheckCriticality(FaultSet faults, Activation activation) { var suppressedFaults = new FaultSet(); foreach (var fault in RuntimeModelCreator.FaultsInBaseModel) { if (GetEffectiveActivation(fault, faults, activation) == Activation.Suppressed) { suppressedFaults = suppressedFaults.Add(fault); } } _checker.ModelTraverser.Context.TraversalParameters.TransitionModifiers.Clear(); _checker.ModelTraverser.Context.TraversalParameters.TransitionModifiers.Add(() => new FaultSuppressionModifier(suppressedFaults)); return(_checker.Check()); }
/// <summary> /// Checks whether the <paramref name="invariant" /> holds in all states of the <paramref name="stateGraph" />. /// </summary> /// <param name="stateGraph">The state graph that should be checked.</param> /// <param name="invariant">The invariant that should be checked.</param> internal InvariantAnalysisResult CheckInvariant(StateGraph <TExecutableModel> stateGraph, Formula invariant) { Requires.NotNull(stateGraph, nameof(stateGraph)); Requires.NotNull(invariant, nameof(invariant)); // We have to track the state vector layout here; this will nondeterministically store some model instance of // one of the workers; but since all state vectors are the same, we don't care AnalysisModel model = null; Func <AnalysisModel> createAnalysisModelFunc = () => model = new StateGraphModel <TExecutableModel>(stateGraph, Configuration.SuccessorCapacity); var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc); using (var checker = new InvariantChecker(createAnalysisModel, Configuration, invariant)) { var result = checker.Check(); return(result); } }
/// <summary> /// Checks the invariant encoded into the model created by <paramref name="createModel" />. /// </summary> internal AnalysisResult CheckInvariant(Func<AnalysisModel> createModel, int formulaIndex) { Requires.That(IntPtr.Size == 8, "Model checking is only supported in 64bit processes."); var stopwatch = new Stopwatch(); stopwatch.Start(); using (var checker = new InvariantChecker(createModel, OutputWritten, Configuration, formulaIndex)) { var result = default(AnalysisResult); var initializationTime = stopwatch.Elapsed; stopwatch.Restart(); try { result = checker.Check(); return result; } finally { stopwatch.Stop(); if (!Configuration.ProgressReportsOnly) { OutputWritten?.Invoke(String.Empty); OutputWritten?.Invoke("==============================================="); OutputWritten?.Invoke($"Initialization time: {initializationTime}"); OutputWritten?.Invoke($"Model checking time: {stopwatch.Elapsed}"); if (result != null) { OutputWritten?.Invoke($"{(long)(result.StateCount / stopwatch.Elapsed.TotalSeconds):n0} states per second"); OutputWritten?.Invoke($"{(long)(result.TransitionCount / stopwatch.Elapsed.TotalSeconds):n0} transitions per second"); } OutputWritten?.Invoke("==============================================="); OutputWritten?.Invoke(String.Empty); } } } }
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}"); }
/// <summary> /// Checks the <see cref="faults" /> for criticality using the <see cref="activation" /> mode. /// </summary> /// <param name="faults">The fault set that should be checked for criticality.</param> /// <param name="activation">The activation mode of the fault set.</param> internal override AnalysisResult <TExecutableModel> CheckCriticality(FaultSet faults, Activation activation) { ChangeFaultActivations(faults, activation); return(_invariantChecker.Check()); }