Main Content

Test Generation on Model with C Caller Block

This example shows how to use test generation on a model with a C Caller block and custom C code

Open the model containing the C Caller block and custom code

open_system('sldvexCCallerBlockExample');

Generate tests to ensure coverage of the model

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

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

[status, fileNames] = sldvrun('sldvexCCallerBlockExample', opts);
27-Feb-2023 10:36:01
Checking compatibility for test generation: model 'sldvexCCallerBlockExample'
Compiling model...done
Building model representation...done

27-Feb-2023 10:36:27

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

Generating tests using model representation from 27-Feb-2023 10:36:27...

..........
27-Feb-2023 10:36:44

Completed normally.

Generating output files:

27-Feb-2023 10:36:46
Results generation completed.

    Data file:
    /home/lucyzeng/Documents/MATLAB/ExampleManager/lucyzeng.BR2023ad.j2194193.1/sldv-ex07804984/sldv_output/sldvexCCallerBlockExample/sldvexCCallerBlockExample_sldvdata.mat

Verify the coverage

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

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

Clean Up

To complete the example, close all models.

close_system('sldvexCCallerBlockExample', 0);