コード例 #1
0
ファイル: InvariantChecker.cs プロジェクト: cubeme/ssharp
            /// <summary>
            ///   Creates a counter example for the current topmost state.
            /// </summary>
            private void CreateCounterExample(bool endsWithException)
            {
                if (Interlocked.CompareExchange(ref _context._generatingCounterExample, _index, -1) != -1)
                {
                    return;
                }

                var indexedTrace = _stateStack.GetTrace();
                var traceLength  = 1 + (endsWithException ? indexedTrace.Length + 1 : indexedTrace.Length);
                var trace        = new byte[traceLength][];

                trace[0] = _model.ConstructionState;

                if (endsWithException)
                {
                    trace[trace.Length - 1] = new byte[_model.StateVectorSize];
                }

                for (var i = 0; i < indexedTrace.Length; ++i)
                {
                    trace[i + 1] = new byte[_model.StateVectorSize];
                    Marshal.Copy(new IntPtr((int *)_states[indexedTrace[i]]), trace[i + 1], 0, trace[i + 1].Length);
                }

                // We have to create new model instances to generate and initialize the counter example, otherwise hidden
                // state variables might prevent us from doing so if they somehow influence the state
                var replayInfo = _createModel().GenerateReplayInformation(trace, endsWithException);

                _context._counterExample = new CounterExample(_createModel(), trace, replayInfo, endsWithException);
            }