Test condition function for Stateflow charts and MATLAB Function blocks
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
sldv.condition test conditions
within MATLAB code or separate the conditions into a verification
The Test conditions option in the Test generation
pane applies to test conditions represented with the
function and with the Test Condition block.
Add Test Objective and Test Conditions
Add a test objective and test conditions by using the MATLAB Function block.
sldvdemo_cruise_control model and save it as
Remove the Test Condition block for the
speed block signal. Instead of the Test
Condition block, this example uses
From the User-Defined Functions library, add a MATLAB Function block:
Name the block
Open the block and add this code:
function define_tests(speed, target) %#codegen sldv.condition(speed >= 0 && speed <= 100); sldv.test(speed > 60 && target > 40 && target < 50); sldv.test(speed < 20 && target > 50);
In the Editor tab, click Save and close the editor.
Connect the block to the signals for the
speedblock and for the
Save the changes to the
To generate test cases, on the Design Verifier tab, click Generate Tests.
expr — Boolean expression for condition
MATLAB expression, for example,
x > 0.
Instead of using the
sldv.condition function, you can insert a Test Condition block in your model. Using
instead of a Test Condition block offers several benefits, described in What Is Test Case Generation?.
You can also specify test conditions by using MATLAB for code generation without using the
sldv.condition instead of directly using MATLAB for code generation eliminates the need to:
Express the constraints with Simulink® blocks.
Explicitly connect the condition output to a Simulink block.