Guy on Simulink

Simulink & Model-Based Design

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Continuous Integration with Simulink Project and Simulink Test 3

Posted by Guy Rouleau,

A few days ago, my colleague Mariano published a blog post on the Developer Zone describing how to run a MATLAB Test suite on a Continuous Integration server every time changes are pushed to a Git repository branch.

As you probably guessed, as soon as I saw that, I had to implement it in a Simulink context. Let's see how that went.

The Big Picture

Here is the big picture of the workflow:

Simulink Project-Git-Jenkins workflow

The main steps are:

  • We have a Simulink Project with source control integration configured to a GitLab repository
  • In the Simulink Project, we have a test suite created using Simulink Test
  • Every time we commit and push changes to a specific branch of the Git repository, the remote repository notifies a Jenkins server
  • As soon as it gets notified, the Jenkins server pulls the commit, launches MATLAB, opens the Simulink Project and runs the Simulink Test test suite
  • If the test passes, the Jenkins server creates a merge request in GitLab.
  • If a test fails, the Simulink Test results are saved and a bug issue in GitLab is created.

This last step of saving the Simulink Test session is very important. As you will see below, it allows me to analyze the simulation results locally without re-running the failed test, saving me a lot of time if the simulation I am testing takes a long time to simulate.

Now it's time to go into the details.

Some Background

Here is a quick recap of the steps to go through outside the MATLAB environment, in Jenkins and GitLab. See Mariano's post for more details:

  • In Jenkins, specify the repository URL, the branch to build and my credentials
  • In Jenkins, set Build Trigger to build when a change is pushed to GitLab
  • In Jenkins, specify the build command to launch MATLAB and run my tests
  • In GitLab, setup a Push Event Web hook to the GitLab CI Service URL of Jenkins. This will be triggered every time I will push changes to my testing branch
  • Now let's move to the fun stuff :-)

    Simulink Project

    For this example, we will reuse the same example we used before in this post where we tested that the results of a simulation was matching results from a generated executable using Software-In-The-Loop simulation:

    Simulink versus Software in the loop validation

    The post Simulation Based Testing with Simulink Test Manager describes in detail how to set up the test, so I will not repeat it here.

    What I added for this blog is to create a Simulink Project, adding all the files to it and configure the source control integration.

    Source Control Integration in Simulink Project

    Running the Simulink Test test suite on the Jenkins Server

    In Jenkins, we need to specify a build command. This build command will launch the MATLAB executable in "nodisplay" mode and use the -r flag to run some MATLAB code (See this image). In my case, the MATLAB code is:

    Jenkins Build command

    The function runMyTests is similar to the one presented in Mariano's post. Here is what it looks like:

    running the tests

    Things to notice:

    • The tests are run through the MATLAB Testing Framework. Thanks to that, my test suite can include tests created using Simulink Test and using the MATLAB Testing Framework. As they say where I come from: A test is a test!
    • The functions writeMergeRequest() and writeIssue() contain code similar to Mariano's post, using webwrite to create a merge request or an issue in GitLab using its API.
    • I create a folder to store the results in case of failure
    • sltest.testmanager.exportResults is used to save the test results in case of a failure.

    Inspecting Test Failure

    Depending on how your Jenkins server is configured, you could write MATLAB code to put the test results at any place convenient for you. By default, I can go grab my results file in the Jenkins workspace.

    Getting the results

    Once I get the results file, I can simply double-click on it in MATLAB and the Test Manager will show what went wrong.

    Visualizing the results

    I will repeat it... since I often deal with simulations that take hours to run, getting the results file from the server saves me a lot of time since I do not need to re-run the simulation on my machine.

    Now it's your turn

    Are you incorporating change management and continuous integration tools like Git and Jenkins in your team-based Model-Based Design projects? If yes, tell us more about your setup in the comments below.

3 CommentsOldest to Newest

Giacomo Faggiani replied on : 1 of 3
This is really interest. I am using Gitlab with Simulink Project but haven't implemented yet any CI system. I know that Jenkins is very popular, however it is not supported by Core (free) version of Gitlab so a different Gitlab license (Starter, Premium or Ultimate) must be purchased. It would be very useful if you could provide instruction on how to setup the Gitlab built in CI tool, that is provided for free also with Core license, for the ones that would like to evaluate CI with Simulink before buying a new product.
@Giacomo: I cannot really comment on the GitLab licensing. However I can say that the workflow in this blog post and the one referenced on Developer Zone work on the Core (free) version of GitLab. We are not using the CI feature of GitLab, but using web hooks to trigger Jenkins and the GitLab API to feedback information. I have not tested the GitLab built-in CI tool, so I cannot comment on how it compares to the workflow in this post.
Giacomo Faggiani replied on : 3 of 3
Thanks for your answer, I found the info about licensing on GItlab website and in a forum, but Core version works for you then I will definitely try it.

Add A Comment

Your email address will not be published. Required fields are marked *

Preview: hide