Main Content

Test Generation for Custom Code in a Stateflow Chart

This example shows how to use test generation on a model with custom code in a Stateflow chart.

Open the model containing custom code in a Stateflow chart

open_system('sldvexSFCustomCodeExample');

Generate tests to ensure coverage of the model

Use the sldvrun function to run the Simulink® Design Verifier™ analysis.

opts = sldvoptions;
opts.Mode = 'TestGeneration';
opts.ModelCoverageObjectives = 'ConditionDecision';
opts.SaveHarnessModel = 'off';
opts.SaveReport = 'off';

[status, fileNames] = sldvrun('sldvexSFCustomCodeExample', opts);
Checking compatibility for test generation: model 'sldvexSFCustomCodeExample'
Compiling model...done
Building model representation...done

'sldvexSFCustomCodeExample' is compatible for test generation with Simulink Design Verifier.

Generating tests using model representation from 01-Sep-2021 14:12:58...
..........

Completed normally.

Generating output files:

Results generation completed.

    Data file:
    /tmp/Bdoc21b_1757077_40675/tp6193f4e0/ex18712703/sldv_output/sldvexSFCustomCodeExample/sldvexSFCustomCodeExample_sldvdata.mat

Verify the coverage

Use the sldvruntest function to verify that the test suite achieves complete model coverage.

[~, finalCov] = sldvruntest('sldvexSFCustomCodeExample', fileNames.DataFile, [], true);
cvhtml('Final Coverage', finalCov);

Clean Up

To complete the example, close all models.

close_system('sldvexSFCustomCodeExample', 0);