www.gusucode.com > simulinktestdemos 工具箱matlab源码程序 > simulinktestdemos/sltestCoverageIncreaseAPDemo.m
%% Extend Model Coverage of a Test Suite % % Increase coverage of a test suite by generating tests using Simulink(R) % Design Verifier(TM). Copyright 2015 The MathWorks, Inc. %% % This example shows you how to % extend coverage of a test suite beyond an initial % test case. You start by measuring coverage for the initial % test which uses timeseries data. You save the results of the % initial coverage measurement, then use Simulink(R) Design Verifier(TM) to % add new test cases to the Test Manager. You then % simulate the expanded test suite and review aggregate coverage. % % This example builds on the workflow from another example, % <matlab:showdemo('sltestRequirementsTestingAutopilotDemo') Requirements-Based Testing for Model Development> %% Paths and Example Files % % Enter the following to store paths and filenames for the example and set % the current folder. % filePath = fullfile(matlabroot,'toolbox','simulinktest','simulinktestdemos'); rollModel = 'RollAutopilotRevised'; testHarness = 'RollReference_LoggedDataTest'; testFile = 'RollRefTest.mldatx'; %% Background and Workflow for the Example % % Tests commonly use timeseries % inputs to exercise the model or a particular model component. Timeseries % inputs can include logged data from simulation or from physical measurements. % Logged data can cover important simulation cases, but not necessarily % achieve full model coverage. If you have Simulink(R) Test(TM) and % Simulink(R) Design Verifier(TM), you can generate test cases to increase % test coverage and view cumulative coverage from a suite of test cases. % % This example uses an updated version of the |Roll Reference| subsystem, % a test case, and a test harness for a timeseries input. The basic % workflow is: %% % # Measure model coverage with the timeseries input and save the coverage % result. % # Generate additional test cases for coverage not achieved in the first % test case. % # Run the suite of test cases and measure cumulative model coverage. %% % The |Roll Reference| subsystem is one component of an autopilot control % system. The subsystem controls the reference angle of the aircraft's roll % axis. %% The Test Case and Timeseries Test Harness % % The model contains a test harness |RollReference_LoggedDataTest|, which % uses timeseries data from the base workspace. The test case % collects MCDC coverage for the |Roll Reference| subsystem. %% Run the Test and Save Coverage Results % % Set the current folder to a writable location. Open the test file % |RollRefTest|: sltest.testmanager.view; sltest.testmanager.load(fullfile(filePath,testFile)); %% % % <<autopilot_coverage_topup_timeseries_testcase_initial.png>> % %% % In the *Test Browser*, expand the *Logged Data and Coverage* test suite. % Highlight the |RollReference Timeseries Input| test % case and click *Run*. %% % When simulation completes, in the *Results and Artifacts* pane, select % the test case. In the test results, expand the *Coverage Results* % section. The results show that the test % achieves partial coverage for the |Roll Reference| subsystem: % % * Decision coverage: 80% % * Condition coverage: 70% % * MCDC 25% %% % <<autopilot_coverage_initial_result.png>> %% % Save the coverage result: % % # Select the coverage result. % # Click *Export*. % # In the *Export* dialog, select *Export to CVT-file*. % # Click the *Browse* icon. Select your working folder. % # Save the coverage result to the file |RollRefInitialCov.cvt|. %% Generate Tests to Increase Model Coverage % % You can use Simulink(R) Design Verifier(TM) to generate additional tests % for missing coverage data. For more information, see % <matlab:helpview(fullfile(docroot,'sldv','ug','generate-test-cases-for-missing-coverage-data.html')) Generate Test Cases for Missing Coverage Data>. %% % # In the test browser, select the |RollReference Timeseries Input| test % case. Expand the *System Under Test* in the right pane. % # Expand *Test % Harness* and click the arrow next to the *Harness* field to open the test % harness. In the test harness, test case generation ignores objectives % satisfied in |RollRefInitialCov.cvt|. You control % this in the *Design Verifier > Test Generation* configuration % parameters. % # In the top level of the test harness, right-click % the |Roll Reference| subsystem and select % *Design Verifier > Generate Tests for Subsystem*. % Test case generation executes, and the results summary window opens. %% % % <<autopilot_coverage_results_summary_window.png>> %% Export Test Cases to the Test Manager % % # In the Design Verifier Results Summary window, click *Export test cases to % Simulink Test*. % # Use the same test harness for the additional test cases. In the % *Harness Selection* dialog box, select |RollReference_LoggedDataTest|. % Click *OK*. % # In the test manager, a new test file appears, containing the new test case. % # Right-click the new test case, and select *Cut*. % # Highlight the *Logged Data and Coverage* test suite, and select % *Paste*. The test suite now contains both test cases for increased % coverage. %% % <<autopilot_coverage_new_testcases.png>> %% Run the Expanded Test Suite % % In |RollRefCumulativeCovTest|, select the |Logged Data and Coverage| test % suite and click *Run*. %% % When simulation completes, in the *Results and % Artifacts* section, select the test suite name and expand the *Aggregated % Coverage Results*. The coverage results show the expanded coverage for % the combined tests. The additional test case completes the model coverage % in the test suite. % % * Decision: 100% % * Condition: 100% % * MCDC: 100% %% % <<autopilot_coverage_combined_report.png>> %% clear filePath reqDoc rollModel testFile testHarness topModel; sltest.testmanager.clearResults; sltest.testmanager.close; close_system('RollAutopilotRevised',0);