Main Content


Test objective function for Stateflow charts and MATLAB Function blocks



sldv.test(expr) specifies that expr is true when generating tests. Use any valid Boolean expression for expr.

This function has no output and no impact on its parenting function, other than any indirect side effects of evaluating expr. If you issue this function from the MATLAB® command line, the function has no effect.

Intersperse sldv.test test objectives within code or separate the objectives into a verification script.

The Test objectives option in the Test generation pane applies to test objectives represented by the sldv.test function and by the Test Objective block.


collapse all

Add a test objective and test conditions by using the MATLAB Function block.

Open the sldvdemo_cruise_control model and save it as ex_sldvdemo_cruise_control. You can open the model by using the command:

'supportingFile', 'sldvdemo_cruise_control')

Remove the Test Condition block from the speed signal. Instead of the Test Condition block, this example uses sldv.test and sldv.condition.

From the User-Defined Functions library, add a MATLAB Function block.

  • Name the block tests.

  • Open the block and add this code:

    function define_tests(speed, target)
    sldv.condition(speed >= 0 && speed <= 100);
    sldv.test(speed > 60 && target > 40 && target < 50);
    sldv.test(speed < 20 && target > 50);
  • Save the model and return to the top model.

  • Connect the block to the signals for the speed block and for the target block.

Save the changes to the ex_sldvdemo_cruise_control model.

To generate test cases, on the Design Verifier tab, click Generate Tests.

Input Arguments

collapse all

Expression for the tests, specified as a Boolean expression. For example, x > 0.


Instead of using the sldv.test function, you can insert a Test Objective block in your model. To learn about the differences between Test Objective blocks and sldv.test, see What Is Test Case Generation?.

Version History

Introduced in R2009b