Check Code Generation Assumptions
The code generator implements assumptions that depend, for example, on the hardware
implementation settings for your model. It is important to check that the assumptions
are valid for your target hardware. Use the buildStandaloneCoderAssumptions
(Embedded Coder) function to create an application that
performs assumption checks on your target hardware.
When you configure your model, try to specify hardware implementation and build configuration settings that match your target hardware. Then, to check code generator assumptions for your target hardware, use this workflow:
With
GenerateReport
set to'on'
, build (Ctrl+B) your model.To view the list of code generator assumptions that you can check, open the code generation report and click the Coder Assumptions link.
For more information, see Coder Assumptions List.
Run
buildStandaloneCoderAssumptions
, which uses the generated code in the build folder to create an application that runs code generation assumption checks.Download the application onto the target hardware or target environment, and then run the application.
While the application runs, use a debug tool to view check results that are in a data structure.
Check Code Generator Assumptions for Development Computer
If the target hardware is, for example, your Windows® development computer, you can use Microsoft® Visual Studio® to run and debug the application:
To open a model, in the Command Window, enter:
openExample('ecoder/SILPILVerificationExample', ... supportingFile='SILTopModel.slx')
In the Model Configuration Parameters dialog box, in the Hardware Implementation pane, specify settings to match the target hardware. For example, for a 64-bit Windows computer specify these parameter settings:
Device vendor ––
Intel
Device type ––
x86-64 (Windows 64)
Clear model configuration parameter Enable portable word sizes.
Build the model (Ctrl+B).
To view the list of code generator assumptions, open the code generation report and click the Coder Assumptions link.
From the Command Window, in the working folder, run:
In the build folder, the function creates thebuildStandaloneCoderAssumptions('SILTopModel_ert_rtw')
coderassumptions\standalone
subfolder, which contains the target application,SILTopModel_ca
.Open Microsoft Visual Studio and select File > Open > Project/Solution
Using the Open Project dialog box, navigate to the
coderassumptions\standalone
subfolder and selectSILTopModel_ca
. Then, click Open.Select File > Open > File. Using the Open File dialog box, select
coderassumptions\standalone\SILTopModel_ca.c
At the
return
statement, insert a break point.Select Debug > Start Debugging.
To verify code generator assumptions, use a Watch window to inspect the
Results
data structure:In the
SILTopModel_ca.c
code, right-clickResults
.From the context menu, select Add Watch.
The variables in the data structure contain:
Check outcomes (
TestResults
)Target hardware truths (
ActualValues
)Code generator assumptions (
ExpectedValues
)
For example, if the code generator assumption for
bitsPerChar
is accurate, you see the
CA_PASS
value in the status
variable.
Coder Assumptions List
The contents section of the code generation report has a link to the Coder Assumptions page. The page provides a list of:
Code generation assumptions that you can check
Expected results for the assumption checks
This table describes the labels that you see in the list.
Category | Label | Assumption You Can Check |
---|---|---|
C/C++ Language Configuration for Target Hardware or Development Computer |
| Number of bits per |
| Number of bits per | |
| Number of bits per | |
| Number of bits per | |
| Size of | |
| Size of | |
| Number of bits per | |
| Number of bits per | |
| Number of bits per | |
| Byte ordering
( | |
| Sign bit behavior
( | |
| Rounding behavior for integer division
( | |
C/C++ Language Standard |
| Zero initialization of memory
( |
Floating-Point Numbers |
| Flush-to-zero subnormal number processing |
| Denormals-are-zero subnormal number processing |
See Also
buildStandaloneCoderAssumptions
(Embedded Coder)
Related Topics
- Verification of Code Generation Assumptions (Embedded Coder)