This tutorial describes the usage of ConQAT’s clone detection capabilities for the modeling language Simulink. The clone detection approach is described in detail in the 2008 ICSE paper Clone Detection in Automotive Model-Based Development.

Editor showing Simulink clone

The tutorial uses parts of ConQAT that are not yet available as Open Source. To continue please download a technology preview for your platform:

We use as examples in this tutorial models that are freely available from the Matlab Central. Please note that the models are solely used for the technical demonstration of the clone detection approach and not to indentify quality problems with the example models. MATLAB, Simulink, Stateflow are registered trademarks of The MathWorks, Inc

If you are in the possession of royalty-free Simulink models and want to make them available for this tutorial, please let us know.

Step 1: Unzip and start the workbench

  • Extract the downloaded ZIP file
  • Locate and start the Eclipse executable
  • The first dialog asks for a workspace location
  • Select a new empty folder as your workspace
  • Close the welcome screen

Step 2: Import the examples

  • In the workbench’s menu select File -> New -> Example
  • There select the ConQAT Example Project and complete the wizard

The created example project contains Simulink MDL files in the subfolders of projects/simulink.

  • Locate one of the MDL files (e.g. airlib/airgk.mdl) and open it with a double-click
  • The editor shows the top-most level of the Simulink model
  • Double-click a subsystem to expand or collapse it
  • Expanded subsystems are embedded into the parent model, so it is possible to inspect the entire model in a single window

Step 4: Run the analysis

  • To run the prepared analysis, open (double-click) the file simulink-analysis.cqr
  • Unless you used ConQAT in the workbench before, a progress dialog for preparing the internal ConQAT model will show
  • Wait for the dialog to close
  • Click on the run icon in the top right corner of the editor to start the analysis
  • The analysis is complete when no new messages appear in the Eclipse console and the last line gives the total time

Step 5: Inspect the HTML output

  • The analysis writes its results into the folder output in the example project. To show them in the workbench, select the project and press F5 (refresh) after the analysis is complete.
  • Locate the file output/simulink/index.html and open it in a web browser.
  • The output contains tables of the analyzed models and the frequency of Simulink blocks used, as well as the full list of clones found.

Step 6: View the clones in the workbench

  • To inspect the clones, choose ConQAT -> Findings -> Open Finding Report from the main menu and in the dialog select the file output/simulink/model-clones.xml located in the directory you chose as workspace in the beginning.
  • The next dialog show is used to map the clones to files in your workspace. Mark the first file in the list and click the button Locate files in workspace. Pick the matching file and confirm with ok.
  • In the select visualization dialog, select marker and in the following dialog WARNING. These dialogs are only showed once.
  • Now some of the MDL files in the example project should be annotated with small warning icons.
  • The clones are listed in the Findings Group View. To open it, choose Window -> Show View -> Other from the main menu and select ConQAT/Findings Group View.
  • The view contains a sortable list of the clones. To open a clone pair, double-click an entry in the list. Then the editor opens the corresponding clone pair in a side-by-side view in the editor.

Step 7: Experiment with your own models

  • The easiest way to use your own models is to copy them into the input directory (projects/simulink) or edit the run configuration simulink-analysis.cqr

Where to go from here?

This is just a very basic example, showing some statistics and a simple clone detection configuration. ConQAT is capable of performing advanced syntactical checks for Simulink models and typically the clone detection has to be tailored to a project to get more precise results. If you want to learn more about Simulink analysis using ConQAT or need support for configuring a specific analysis, feel free to contact us at support@nospamcqse.eu.