Add Test Cases Using Excel File
This example shows how to create test cases incrementally by using Simulink® Design Verifier™ supported Excel® file.
Simulink® Design Verifier™ generates test cases to satisfy testing criteria, such as model objectives. Owing to support limitations and model complexity, occasionally it can generate test cases that do not cover all model objectives. Use this example to understand how to:
Create test cases in Excel file format.
Write a new test case manually in an Excel file.
Create additional test cases by using test extension with Excel file.
Generate Test Cases by Using Design Verifier
Open the model and create test cases.
model = 'sldvexSpreadsheetTopoff'; open_system(model); [~, files] = sldvrun(model);
19-Aug-2023 15:33:25 Checking compatibility for test generation: model 'sldvexSpreadsheetTopoff' Compiling model...done Building model representation...done 19-Aug-2023 15:33:43 'sldvexSpreadsheetTopoff' is partially compatible for test generation with Simulink Design Verifier. The model can be analyzed by Simulink Design Verifier. It contains unsupported elements that will be stubbed out during analysis. The results of the analysis might be incomplete. See the Diagnostic Viewer for more details on the unsupported elements. Generating tests using model representation from 19-Aug-2023 15:33:43... Generating output files: 19-Aug-2023 15:34:16 Results generation completed. Data file: /tmp/Bdoc23b_2361005_1507434/tp232739a1/sldv-ex79932255/sldv_output/sldvexSpreadsheetTopoff/sldvexSpreadsheetTopoff_sldvdata.mat
Save Design Verifier Test Cases to Excel File
Simulink Design Verifier creates test cases in the MAT-file format by default. Save the test cases generated in the previous section in an Excel file by using any of these methods:
Click Save to spreadsheet button in Results.
Click Save to spreadsheet link in the results window, or results inspector.
For this example, use the
sldvgenspreadsheet function to save the test cases.
excelFilePath = sldvgenspreadsheet(model, files.DataFile);
Note: Importing or exporting to an Excel file is not supported for an array of bus signals. For more information, see Microsoft Excel Import, Export, and Logging Format.
Identify Missing Coverage Objectives
Simulate the model by using all test cases from the Excel file and create a coverage report.
sldvruntest supports test cases from a spreadsheet as simulation input.
runOpts = sldvruntestopts; runOpts.coverageEnabled = true; % Enable coverage [~, initialCov] = sldvruntest(model, excelFilePath, runOpts); % Use test cases from Excel file for simulation cvhtml('Initial coverage', initialCov);
Observe that the value of
logical trigger input is never false in the coverage report.
Write Test Case to Satisfy Coverage Objective
Determine the cause of missing the coverage objective. In this example, the model contains unsupported block Sqrt, which limits Simulink Design Verifier analysis.
To make the value of trigger input of Switch block false, observe that the value of inport In3 should be greater than 100. Add a new sheet in the Excel file with the test case.
Verify whether the new test case satisfies the required coverage objective.
excelFilePath = 'WithNewTestCase.xlsx'; runOpts = sldvruntestopts; runOpts.testIdx = 2; % Simulate only the newly added test case runOpts.coverageEnabled = true; [~, newTestCov] = sldvruntest(model, excelFilePath, runOpts); cvhtml('New test coverage', newTestCov);
Run Test Extension by Using Excel file
Simulink Design Verifier test extension workflow generates new test cases by extending the existing test cases. This helps to satisfy additional coverage objectives by extending your new test case.
opts = sldvoptions(model); opts.ExistingTestFile = excelFilePath; % Use Excel file with new test cases as input for test extension opts.ExtendExistingTests = 'on'; % Enable test extension [~, files] = sldvrun(model, opts);
19-Aug-2023 15:34:47 Checking compatibility for test generation: model 'sldvexSpreadsheetTopoff' Compiling model...done Building model representation...done 19-Aug-2023 15:34:50 'sldvexSpreadsheetTopoff' is partially compatible for test generation with Simulink Design Verifier. The model can be analyzed by Simulink Design Verifier. It contains unsupported elements that will be stubbed out during analysis. The results of the analysis might be incomplete. See the Diagnostic Viewer for more details on the unsupported elements. 19-Aug-2023 15:34:50 Loading initial test data...done Generating tests using model representation from 19-Aug-2023 15:34:50... Generating output files: 19-Aug-2023 15:35:02 Results generation completed. Data file: /tmp/Bdoc23b_2361005_1507434/tp232739a1/sldv-ex79932255/sldv_output/sldvexSpreadsheetTopoff/sldvexSpreadsheetTopoff_sldvdata1.mat
Verify Complete Coverage
Simulate the model using the new test cases and verify that you now have complete coverage.
runOpts = sldvruntestopts; runOpts.coverageEnabled = true; % Enable coverage [~, finalCov] = sldvruntest(model, files.DataFile, runOpts); cvhtml('Final coverage', finalCov); close_system(model, 0);
If the new test cases still yield partial coverage, you can write a new test case in an Excel file and then run test extension workflow till complete coverage is achieved.