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}");
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Initializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            var invariant = new UnaryFormula(hazard, UnaryOperator.Not);

            var checker = new QualitativeChecker <TExecutableModel>(RuntimeModelCreator)
            {
                Configuration = configuration
            };

            checker.Configuration.ProgressReportsOnly = false;


            var stateGraph = checker.GenerateStateGraph();



            var stateCapacity    = Math.Max(1024, (int)(stateGraph.StateCount * 1.5));
            var newModelCapacity = new ModelCapacityByModelDensity(stateCapacity, ModelDensityLimit.High);

            configuration.ModelCapacity = newModelCapacity;
            Func <AnalysisModel> createAnalysisModelFunc = () => new StateGraphModel <TExecutableModel>(stateGraph, configuration.SuccessorCapacity);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);

            _checker = new InvariantChecker(createAnalysisModel, configuration, invariant);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            Func <AnalysisModel <TExecutableModel> > createAnalysisModelFunc = () =>
                                                                               new ActivationMinimalExecutedModel <TExecutableModel>(RuntimeModelCreator, _stateHeaderBytes, configuration.SuccessorCapacity);
            var createAnalysisModel = new AnalysisModelCreator <TExecutableModel>(createAnalysisModelFunc);
            var invariant           = new UnaryFormula(hazard, UnaryOperator.Not);

            _invariantChecker = new InvariantChecker <TExecutableModel>(createAnalysisModel, OnOutputWritten, configuration, invariant);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            Func <AnalysisModel> createAnalysisModelFunc = () =>
                                                           new ActivationMinimalExecutedModel <TExecutableModel>(RuntimeModelCreator, 0, configuration);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);
            var invariant           = new UnaryFormula(hazard, UnaryOperator.Not);

            _invariantChecker = new InvariantChecker(createAnalysisModel, configuration, invariant);
        }
		/// <summary>
		///   Initizializes the model that should be analyzed.
		/// </summary>
		/// <param name="configuration">The configuration that should be used for the analyses.</param>
		/// <param name="hazard">The hazard that should be analyzed.</param>
		protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
		{
			var serializer = new RuntimeModelSerializer();
			serializer.Serialize(Model, !hazard);

			Func<AnalysisModel> createModel = () =>
				new ActivationMinimalExecutedModel(CreateModel(hazard), configuration.SuccessorCapacity);

			_invariantChecker = new InvariantChecker(createModel, OnOutputWritten, configuration, formulaIndex: 0);
		}
Ejemplo n.º 6
0
		/// <summary>
		///   Initizializes the model that should be analyzed.
		/// </summary>
		/// <param name="configuration">The configuration that should be used for the analyses.</param>
		/// <param name="hazard">The hazard that should be analyzed.</param>
		protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
		{
			var checker = new SSharpChecker { Configuration = configuration };
			checker.Configuration.ProgressReportsOnly = false;
			checker.OutputWritten += OnOutputWritten;

			var stateGraph = checker.GenerateStateGraph(Model, !hazard);

			configuration.StateCapacity = Math.Max(1024, (int)(stateGraph.StateCount * 1.5));
			_checker = new InvariantChecker(() => new StateGraphModel(stateGraph, configuration.SuccessorCapacity), OnOutputWritten,
				configuration, formulaIndex: 0);
		}
Ejemplo n.º 7
0
 private int DoWork()
 {
     using (var checker = new InvariantChecker(this))
     {
         try
         {
             // do some stuff
         }
         catch
         {
             checker.Suppress = true;
             throw;
         }
     }
 }
Ejemplo n.º 8
0
        /// <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);
            }
        }
Ejemplo n.º 10
0
        /// <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);
            }
        }
Ejemplo n.º 11
0
		/// <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);
					}
				}
			}
		}
Ejemplo n.º 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}");
        }
Ejemplo n.º 13
0
        public PostExtractorChecker(
            ContractNodes usedToExtract,
            Action<System.CodeDom.Compiler.CompilerError> errorHandler,
            bool allowPreconditionsInOverrides, bool fSharp, bool explicitUserValidations,
            bool addInterfaceWrappersWhenNeeded, int runtimeCheckingLevel)
        {
            Contract.Requires(errorHandler != null);
            Contract.Requires(usedToExtract != null);

            this.m_errorHandler = errorHandler;
            this.allowPreconditionsInOverrides = allowPreconditionsInOverrides;
            this.explicitUserValidations = explicitUserValidations;
            this.addInterfaceWrappersWhenNeeded = addInterfaceWrappersWhenNeeded;
            this.runtimeCheckingLevel = runtimeCheckingLevel;

            this.purityChecker = new PurityChecker(this.HandleError, fSharp, usedToExtract);
            this.preconditionChecker = new PreconditionChecker(this.HandleError, usedToExtract);
            this.postconditionChecker = new PostconditionChecker(this.HandleError, fSharp);
            this.invariantCallChecker = new CheckForCallsToInvariantMethods(this);
            this.methodBodyChecker = new MethodBodyChecker(this.HandleError, usedToExtract);
            this.invariantChecker = new InvariantChecker(this.HandleError, usedToExtract);
            this.contractNodes = usedToExtract;
            this.visibilityChecker = new VisibilityChecker(this.HandleError, usedToExtract);
            this.invariantMethods = new TrivialHashtable(0);
        }