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('sldvSFCustomCodeExample');

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('sldvSFCustomCodeExample', opts);
13-Feb-2024 01:15:44
Checking compatibility for test generation: model 'sldvSFCustomCodeExample'
Compiling model...done
Building model representation...done

13-Feb-2024 01:16:05

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

Generating tests using model representation from 13-Feb-2024 01:16:05...

..........
13-Feb-2024 01:16:21

Completed normally.

Generating output files:

13-Feb-2024 01:16:23
Results generation completed.

    Data file:
    /tmp/Bdoc24a_2528353_1833648/tp6a7968b9/sldv-ex18712703/sldv_output/sldvSFCustomCodeExample/sldvSFCustomCodeExample_sldvdata.mat

Verify the Coverage

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

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

Clean Up

To complete the example, close all models.

close_system('sldvSFCustomCodeExample', 0);