%% Increase Test Coverage for a Model
%
% Increase test coverage by generating test inputs.

% Copyright 2015 The MathWorks, Inc. 

%%
% If your tests achieve incomplete model coverage, you can
% increase coverage by generating test inputs using Simulink(R) Design
% Verifier(TM).
% This example shows how to increase test coverage beyond an initial 
% test case. You measure initial coverage of a test case. Then, you
% generate new test cases, add them to the test suite, 
% run the tests, and review aggregate coverage.
%
% This example uses Simulink Design Verifier and Simulink(R) Coverage(TM).
%
%% Workflow
% 
% This example tests a component of an autopilot system using 
% a test harness. Time series data from the base workspace is mapped to root
% inports in the test harness. The test file is configured to  
% collect coverage.
%
% The example workflow is:

%%
% # Measure model coverage of the initial test case.
% # Generate additional tests to achieve greater coverage.
% # Add the new test cases to the test file.
% # Run all test cases and review aggregate coverage.

%% Paths and Example Files
%
% Set paths and filenames for the example.
%
rollModel = 'RollAutopilotRevised';
testHarness = 'RollReference_LoggedDataTest';
testFile = 'RollRefTest.mldatx';

%% Run the Initial Test and Review Coverage
% 
% 1. Ensure the working folder is writable.
%
% 2. Open the test file.
sltest.testmanager.view;
sltest.testmanager.load(testFile);

%%
%
% <<../autopilot_coverage_topup_timeseries_testcase_initial.png>>
%
%%
% 3. Run the test. In the *Test Browser*, highlight the *Logged Data and
% Coverage* test suite. Click *Run*.

%%
% 4. After the test completes, in the test results, expand the *Coverage
% Results* section. The test achieves partial coverage for the |Roll
% Reference| subsystem.
%
% * Decision coverage: 80%
% * Condition coverage: 70%
% * MCDC 25%

%%
% <<../autopilot_coverage_initial_result_new.png>>

%% Generate Tests to Increase Model Coverage
%
% Generate additional tests for missing coverage.
%
% 1. Below the coverage result, click *Add Tests for Missing Coverage*.
%
% 2. In the *Add Tests for Missing Coverage* dialog box, set these options:
%
% * *Harness:* |RollReference_LoggedDataTest|. This maps the new test
% inputs to the existing test harness.
% * *Test Case*: |Create a new test case|. This creates a new test
% case with the generated test inputs.
% * *Test Type:*: |Baseline Test|. This gives the option to capture
% baseline data output from the model for the generated tests.
% * *Test File:*: |RollRefTest|. This re-uses the existing test file.

%%
% 3. Click *OK*. A dialog box shows progress of the test case generation.
% When test case generation is complete, a new test case appears in the
% Test Manager.

%%
% <<../new_test_case_after_adding_missing_coverage.png>>


%% Run the New Test Case
%
% 1. Drag and Drop the new test case into the *Logged Data and
% Coverage* test suite.
%
% 2. Run the *Logged Data and Coverage* test suite again.
%
% 3. When simulation completes, in the *Results and
% Artifacts* section, select the result set and expand the *Aggregated
% Coverage Results*. The test suite achieves complete coverage:
%
% * Decision: 100%
% * Condition: 100%
% * MCDC: 100%

%%
% <<../autopilot_coverage_new_test_case.png>>

%% Cleanup
% Clear variables and test results, and close the model.
clear reqDoc rollModel testFile testHarness topModel;
sltest.testmanager.clearResults;
sltest.testmanager.close;
close_system('RollAutopilotRevised',0);
