To unit test a Stateflow® chart in a Simulink® model, first break the chart into smaller, independent components by using atomic subcharts. When you generate code for your chart, a separate file stores the code for the atomic subchart. Generating reusable code from atomic subcharts is useful for testing individual parts of your Stateflow chart. For more information, see Create Reusable Subcomponents by Using Atomic Subcharts.
To specify code generation parameters for an unlinked atomic subchart:
In your chart, right-click the atomic subchart and select Properties.
In the dialog box, specify these parameters:
Set Code generation function
packaging to Reusable
function
.
Set Code generation file name options
to User specified
.
For Code generation file name, enter the name of the file with no extension.
Open the Configuration Parameters dialog box by pressing Ctrl+E.
In the Code Generation tab, set the
System target file parameter to
ert.tlc
.
(OPTIONAL) Customize the generated function names for atomic subcharts. In the Configuration Parameters dialog box, in the Code Generation > Identifiers tab, set the Subsystem methods parameter. Specify the format of the function names by using a combination of these tokens:
$R
— root model
name
$F
— type of interface
function for the atomic subchart
$N
— block name
$H
— subsystem
index
$M
— name-mangling
text
For more information, see Generate Separate Code for an Atomic Subchart.
To specify code generation parameters for linked atomic subcharts from the same library:
Open the library model that contains your atomic subchart.
Unlock the library.
Right-click the library chart and select Block Parameters.
In the dialog box, specify these parameters:
On the Main tab, select Treat as atomic unit.
On the Code Generation tab, set
Function packaging to
Reusable function
.
Set File name options to
User specified
.
For File name, enter the name of the file with no extension.
In the Code Generation tab, set the
System target file parameter to
ert.tlc
.
(OPTIONAL) Customize the generated function names for atomic subcharts. In the Configuration Parameters dialog box, in the Code Generation > Identifiers tab, set the Subsystem methods parameter. Specify the format of the function names by using a combination of these tokens:
$R
— root model
name
$F
— type of interface
function for the atomic subchart
$N
— block name
$H
— subsystem
index
$M
— name-mangling
text
When you generate code for your model, a separate file stores the code for linked atomic subcharts from the same library.