Code Verification - MATLAB & Simulink (original) (raw)
Main Content
Behavioral verification of generated code, traceability, code generation reports
After you generate code, inspect the source code and output results for verification purposes. The code generation report provides an interactive interface for inspecting the generated C/C++ source files, generated data types, and other code insights. Access a subset of information from the code generation report programmatically by using the report information object. You can test the output of generated MEX code against the original MATLAB® code, or you can create custom tests based on the MATLAB unit test classes. You can choose to generate run-time error checks that alert you to errors that occur during code execution.
Functions
codegen | Generate C/C++ code fromMATLAB code |
---|---|
coder.config | Create code generation configuration objects |
coder.ignoreConst | Prevent use of constant value of expression for function specializations |
coder.ignoreSize | Prevent code generator from creating function specializations for constant-size expressions |
coder.mfunctionname | Name of calling function or method (Since R2021b) |
coder.runTest | Run test replacing calls to MATLAB functions with calls to MEX functions |
getLineColumn | Find locations of beginning and end of MATLAB code involved in code generation |
Classes
coder.HardwareImplementation | Hardware-specific configuration parameters for C/C++ code generation fromMATLAB code |
---|
Objects
coder.CodeConfig | Configuration parameters for C/C++ code generation from MATLAB code |
---|---|
coder.EmbeddedCodeConfig | Configuration parameters for C/C++ code generation from MATLAB code with Embedded Coder |
coder.MexCodeConfig | Configuration parameters for MEX function generation from MATLAB code |
Properties
coder.BuildLog Properties | Build logs produced during code generation |
---|---|
coder.CodeFile Properties | Description of file containing text that is involved in code generation |
coder.File Properties | Description of file without text that is involved in code generation |
coder.Function Properties | Description of MATLAB function used in code generation |
coder.Message Properties | Description of message produced during code generation readiness analysis or during code generation |
coder.Method Properties | Description of method in a MATLAB class used in code generation |
coder.ReportInfo Properties | Code generation report information |
coder.Summary Properties | Summary of code generation from MATLAB code |
Topics
Code Generation Reports
- Code Generation Reports
View code generation results. - Tracing Generated C/C++ Code to MATLAB Source Code
Generate traceability tags. - Access Code Generation Report Information Programmatically
Access information about code generation such as input files, generated files, and error messages by using a report information object.
Testing Generated Code
- Testing Code Generated from MATLAB Code
Verify numerical behavior of generated code. - Verify MEX Functions in the MATLAB Coder App
Compare results of running the original MATLAB function with the results from running the MEX function. - Verify MEX Functions at the Command Line
Test MEX functions withcoder.runTest
or thecodegen
-test
option. - Unit Test Generated Code with MATLAB Coder
Run MATLAB unit tests on generated code. - Unit Test External C Code with MATLAB Coder
Run MATLAB unit tests on generated code that integrates external C code.
Run-Time Error Detection
- Generate Standalone C/C++ Code That Detects and Reports Run-Time Errors
Generate standalone libraries and executables that detect and report run-time errors, such as out-of-bounds array indexing.
Troubleshooting
- Avoid Duplicate Functions in Generated Code
Reduce the occurrence of duplicate functions in the generated code. - Run-time Stack Overflow
Set the value of the maximum stack usage parameter.
Featured Examples
New
Generate C Code from Spectral Analysis Algorithm and Verify Using Parameterized Equivalence Tests
Write a unit test to verify both generated MEX and static library code.
(MATLAB Test)
- Since R2023a
Calculate Number of Lines of Code by Using Report Information Object
Calculate the number of lines in the source code and the generated code by programmatically accessing code generation report information.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
Belgium (English)
Denmark (English)
Deutschland (Deutsch)
España (Español)
Finland (English)
France (Français)
Ireland (English)
Italia (Italiano)
Luxembourg (English)
Netherlands (English)
Norway (English)
Österreich (Deutsch)
Portugal (English)
Sweden (English)
Switzerland
United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)