Example #1
0
        protected ISet <Action> ActionsThatAreAlwaysEnabled(State source, Action action, IEnumerable <Action> actions,
                                                            CodeContractsRunner codeContractsRunner)
        {
            Contract.Requires(source != null);
            Contract.Requires(action != null);
            Contract.Requires(actions.Any());
            Contract.Requires(codeContractsRunner != null);

            var targetPreconditionQueries = queryGenerator.CreatePositiveQueries(source, action, actions);

            generatedQueriesCount += targetPreconditionQueries.Count;
            var queryAssembly  = CreateQueryAssembly(targetPreconditionQueries);
            var evaluator      = new QueryEvaluator(codeContractsRunner, queryAssembly);
            var enabledActions = new HashSet <Action>(evaluator.GetEnabledActions(targetPreconditionQueries));

            unprovenQueriesCount += evaluator.UnprovenQueries;
            return(enabledActions);
        }
Example #2
0
        public ActionAnalysisResults AnalyzeActions(State source, Action action, IEnumerable <Action> actions)
        {
            var codeContractsRunner = new CodeContractsRunner(workingDir, ccCheckDefaultArgs, libPaths, typeToAnalyze);

            if (action.IsPure)
            {
                return(new ActionAnalysisResults(new HashSet <Action>(source.EnabledActions), new HashSet <Action>(source.DisabledActions)));
            }

            var enabledActions  = ActionsThatAreAlwaysEnabled(source, action, actions, codeContractsRunner);
            var disabledActions = ActionsThatAreAlwaysDisabled(source, action, actions, codeContractsRunner);

            if (enabledActions.Intersect(disabledActions).Any())
            {
                Logger.Log(LogLevel.Warn,
                           "Suspicious state! Only a state with a unsatisfiable invariant can lead to actions being enabled and disabled at the same time. It can also mean a bug in our code.");
                return(new ActionAnalysisResults(new HashSet <Action>(source.EnabledActions), new HashSet <Action>(source.DisabledActions)));
            }

            return(new ActionAnalysisResults(enabledActions, disabledActions));
        }