%% Examine Model Verification Results by Using Simulation Data Inspector
%
% This example shows how to use the Simulation Data Inspector to view the
% output from a model verification block in a system under test. If you
% have Simulink(R) Test(TM), model verification blocks return |Pass|,
% |Fail|, or |Untested| results at each time step. By examining the results
% of a model verification block, you can:
%
% * Determine the simulation time when a failure occurs.
% * Compare the verification results with other relevant signals.
% * Trace failures from the Simulation Data Inspector back to the model.
%
% For more information, see 
% <docid:sltest_ug#mw_a510e715-1f92-486c-8c50-5052e07b4a6f Model Verification Blocks>.

% Copyright 2006-2019 The MathWorks, Inc.

%%

% View plots and export results from *Assertion* and other blocks in the
% Model Verification library. 

% You can use the Test Manager or Simulation Data Inspector to view and
% export the results.

% The process is similar for viewing results in the Test Manager.

%% Verify Model Behavior With Assertion Block
% In this example, the subsystem block |Controller| models the cruise
% control system in a car. This subsystem outputs the throttle value based
% on the difference between the actual and target speeds.

model = 'sltestCruiseControlDefective';
load_system(model)

% Delete all annotations at the top level of the model
ah = find_system(model, 'FindAll', 'on', 'type', 'annotation');
for i = 1:length(ah)
   ao = get_param(ah(i), 'Object');
   ao.delete;
end

open_system(model);

%%
% The verification subsystem |Safety Properties| uses an
% <docid:simulink_ref#f6-1351879 Assertion> block to check that the system
% disengages when the brake is applied for three consecutive time steps.

open_system([model '/Safety Properties']);

%% Determine Simulation Time of Failure
% Simulate the model and view the output of the Assertion block in the
% Simulation Data Inspector.
%
% # In the *Simulation* tab, click *Run*.
% # In the *Simulation* tab, under *Review Results*, select *Data
% Inspector*.
% # In the Simulation Data Inspector navigation pane, select
% |BrakeAssertion|.
%
% The results show that the assertion fails at 0.23 seconds.
%
% <<../brake_assertion_sdi_output1.png>>

%% Compare Verification Results with Other Signals
% Examine the cause of the failure by plotting the values of the brake and
% throttle signals.
%
% # Right-click the |throt| signal and select *Log Selected Signals*.
% # Simulate the model.
% # Configure the Simulation Data Inspector with two subplots.
% # In the Simulation Data Inspector navigation pane, select the signals to
% plot. For the first subplot, select |BrakeAssertion|. For the second
% subplot, select |Controller:1| (throttle) and |Inputs:3| (brake).
%
% The results show that pressing the brake at 0.2 seconds does not
% disengage the throttle.
%
% <<../brake_assertion_sdi_output2.png>>

%% Trace Failure Back to the Model
% Find the block that produces a verification result by tracing the result
% from the Simulation Data Inspector back to the model. In the Simulation
% Data Inspector navigation pane, right-click |BrakeAssertion| and select
% *Highlight in Model*. The editor opens the verification subsystem and
% highlights the Assertion block.
%
% <<../brake_assertion_highlight.png>>

close_system(model,0)
