Simulink Analyses
This page lists the analyses Teamscale runs on Simulink models, Stateflow charts, data dictionaries, and MATLAB code, and the analysis-profile options that control them. All analyses require the language Simulink and Stateflow in your analysis profile. The checks for .m files additionally require the language Matlab.
For an overview and setup instructions, see Teamscale for Simulink and Stateflow.
Guideline Checks
Teamscale maps its Simulink checks to two modeling guidelines published by MathWorks:
- MathWorks Advisory Board (MAB) Guidelines, which include the guidelines formerly published as MAAB and JMAAB.
- MathWorks High-Integrity Systems Modeling (HISM) Guidelines.
Every finding of a mapped check names the violated guideline rule. To see which rules Teamscale checks, open the Checks perspective and select the Guidelines view. To report on guideline compliance, add the Guideline Summary widget to a dashboard.
Each check has a detailed description with examples in the Checks perspective. Many checks have options, for example, maximum name lengths, block types to report, or expected font settings. You can change these options in the analysis profile.
Block Type Names in Check Options
Check options that take block types expect the internal block type names stored in the model files, not the names the MATLAB UI shows. See Configuring Block Types in Simulink Analyses.
Teamscale checks the following areas:
| Area | Examples |
|---|---|
| Names | Allowed characters and length of file, subsystem, block, port, signal, bus, parameter, and Stateflow data names. |
| Model structure | Number of blocks and subsystems per level, position of ports and conditional blocks, unconnected lines and ports, commented-out elements. |
| Block usage | Prohibited block types, usage of Switch, Multiport Switch, Lookup Table, Saturation, Merge, and Discrete-Time Integrator blocks, default cases in control blocks. |
| Signals and data types | Signal labels and their propagation, bus usage, type conversions, floating-point comparisons, unused data in data dictionaries. |
| Appearance | Fonts, block name display, block orientation, crossing and overlapping signal lines. |
| Variants | Missing ports in variant subsystems, default variants, variant conditions. |
| Stateflow | Number of states, state and transition actions, transition appearance, backtracking, data scope, implicit type casts, numeric literals. |
| MATLAB code in models | Size and nesting of MATLAB Function blocks, if/switch patterns, relational and logical operators. |
If you also enable the language Matlab, Teamscale analyzes .m files as well. In addition to the checks it runs for all languages, such as clone detection and comment completeness, Teamscale checks for MATLAB-specific issues, for example, use of eval, missing otherwise cases, unused variables, and function names that don't match the file name.
Most checks are enabled by default. To see all checks with their descriptions and options, open the Checks perspective, or look at the check list in your analysis profile.
Metrics and Thresholds
Teamscale computes the following metrics for each model. In the treemap and in metric tables, Teamscale uses Block Count as the size of a model, in the same way it uses lines of code for source files.
| Metric | What it counts |
|---|---|
| Block Count | All blocks in the model. |
| Subsystems | Visible subsystems on all levels of the model. |
| Model Nesting Depth | The deepest subsystem level, counted from the model root. |
| Maximum Blocks in Subsystem | The largest number of blocks directly inside one subsystem or the model root. Commented-out blocks don't count. |
| Library Links | Blocks that link to a library block. |
| Loops | For Iterator, For Each, and While Iterator blocks. |
| MATLAB Functions | MATLAB Function blocks. |
| S-Functions | S-Function blocks. |
| Stateflow Charts | Stateflow charts. |
| State Count | Stateflow states. |
| Block Clone Coverage | The share of non-trivial blocks that are part of a model clone. |
For all metrics except Block Count, State Count, and Block Clone Coverage, Teamscale creates a finding if a model exceeds a threshold. You can configure the yellow and red thresholds in the analysis profile, for example, with the option Nesting Depth Thresholds. By default, the thresholds are 3 and 5 for the nesting depth and 10 and 20 for all other metrics.
The Deep Nesting finding marks the subsystems on the deepest path, so that you can navigate to them directly.
Thresholds per Level
The thresholds above apply to a whole model. To limit the number of blocks or subsystems on each level of a model, use the checks Check for number of blocks per level and Check for number of subsystems per level.
Model Clone Detection
Teamscale detects duplicated block structures within and across models, including library models. It reports them as Simulink Clones findings in the Redundancy category. Each finding lists all instances of the clone as siblings, and you can compare them side by side.
Teamscale compares blocks by their type and their essential parameters, for example, the operator of a Logical Operator block or the value of a Constant block. Block names, positions, and layout don't matter.
By default, Teamscale reports clones with at least 10 blocks, not counting structural blocks such as subsystems and ports. You can change this with the analysis-profile option Minimal clone size.
Naming Conventions
In addition to the guideline checks for names, Teamscale offers the Simulink naming analysis. With it, you define patterns that the names of subsystems, ports, signals, and library blocks must match. This analysis is disabled by default.
You define the patterns with sub-expressions. Each line of the option Sub Expressions defines one sub-expression in the form $Name=pattern, for example, $AlphaNum=[a-z|A-Z|0-9]. You then use the sub-expressions in the pattern options, such as Signal-Name Pattern or Subsystem Instance Pattern, for example, $AlphaNum+. Findings mark the parts of a name that don't match the pattern.
Integrating Simulink Model Advisor
If you already run checks with Simulink Model Advisor, you can upload its HTML reports to Teamscale. Teamscale shows failed checks as red findings and warnings as yellow findings, located on the affected blocks. Use the report format MODEL_ADVISOR when uploading external analysis results. See Upload Formats and Samples for all supported formats.
Generated-Code Tracing
Teamscale can map findings and test coverage of the code generated from your models back to the Simulink blocks. Coverage mapped this way appears in the metric Model Line Coverage. See Mapping from Generated Code to Simulink Models.
