First Steps with Continuous Integration and TargetLink: Every Beginning Is Easy

Published: April 27, 2021

Sven Siemon, Technical Author, R&D Governance & Competence Partners, dSPACE GmbH

When Grady Booch introduced his coding method in 1991, he could not have known how it would revolutionize software development – a positive black swan. In his proposal, continuous integration was not intended to be used multiple times a day or in the build process of an entire application. But the strong acceleration of development speed and the increased complexity of business processes of the last decades called for more software iterations with more integration steps. As a consequence, integrations at the latest point of development, known as big bang integrations, are becoming riskier and riskier. This is true for safety- and non-safety-relevant software development where processes are strict, complex and the margin of error is zero. Continuous integration has enabled many customers to develop, test, and build software faster and more efficiently. More importantly, companies can automate their software development and testing processes, which, in turn, means that continuous integration increases software maturity and customer satisfaction in the long term. Therefore, we at dSPACE are not surprised that our customers use or want to use its advantages for their model-based development projects.

We want our customers to be successful. The production code generator TargetLink has everything you need to implement a continuous integration workflow in your model-based development environment. This blog post shows you the first steps to using TargetLink’s strengths in a continuous integration workflow.  

Automation Server

Figure 1: Example of a MATLAB start command in PowerShell.

If a developer makes local changes to the model of a software unit and checks them into a version control system, the automation server starts a software unit testing and integration process. In this blog post, we provide an example using the free and open-source Jenkins automation server. With Jenkins, you can create as many different continuous delivery pipelines as you need. In the configuration file, you can define the pipeline tasks and their order. You must ensure that the scripts for all tasks are executed in batch mode, i.e., the MATLAB® scripts must be executed without user interaction, refer to the code snippet in figure 1.  

Figure 2: Example of error handling in M.

TargetLink uses the MATLAB batch option as an initial value for all tasks and all APIs work without user interaction.

We all know how time-consuming it is to investigate why a particular piece of functionality is not working as intended. Defensive programming techniques, such as implementing error handling, help you recognize, find, and fix errors in the pipeline. For example, you can use the Try and Catch syntax constructs to capture terminating errors. 

You can also implement error handling in your MATLAB.  

Creating a Continuous Software Unit Testing Pipeline

Figure 3: An exemplary continuous software testing pipeline.

Let’s now take a closer look at a continuous software unit testing pipeline with TargetLink. Typical tasks for a continuous software unit testing pipeline are:

  • Modeling guideline checks
  • Code generation
  • Building code for SIL/PIL simulation
  • Software unit tests
  • Static code analysis

You can check your code against your own modeling guidelines or our TargetLink Modeling Guidelines by using the quality tools from our partner Model Engineering Solutions (MES). You can start the code generation process via the tl_generate_code API. If you need simulation frames to test the code automatically later on, use the SimMode property. Next, build the application for the software unit. Your choice of using SIL or PIL simulation determines whether to use the tl_compile_host or tl_compile_target API. You can then use the tl_sim API to start the simulation. Keep in mind that SIL and PIL simulations use different compilers to build the application. If you generated the code and the application for both SIL and PIL simulation modes, you can easily switch between the two modes with the tl_set_sim_mode API. In addition to intrinsic TargetLink functionality for simulating and testing software units, you can also benefit from dedicated products by our TargetLink Ecosystem partners, such as BTC EmbeddedTester or PikeTec TPT. In this blog article, PIL simulation refers to the virtualization of a PIL board. However, by using an instruction set simulator, such as the Lauterbach ISS, TargetLink 4.2 and later can also virtualize the actual functionality. Additionally, the TargetLink tlSimInterface and tlSimParameterUpdate APIs let you manipulate the simulation without having to generate the code or application again. With these APIs, you can reset the application, get variable addresses, and write new values to these addresses to test the application with different parameters. Lastly, you can access the TargetLink Data Server and the stored simulation data by using the tl_access_logdata API. You can combine the APIs with ds_error_check to check if all commands were executed currectly. For an example, refer to figure 2. 

As mentioned before, you can create as many different pipelines in Jenkins as you want. For example, the continuous software unit testing pipeline shown in this post can be one part of a continuous integration pipeline. Continuous integration can be used for models, production code, or even object code. If you use a separate software unit testing pipeline, you can create a continuous integration pipeline that generates what is known as glue code. In this case, only the code parts are generated that glue the tested software units together. In this continuous integration pipeline, your application is built from tested software units and you can start to test the entire software, for example, to check if the interfaces or parameters are perfectly in tune. Depending on your test goals, you can combine the TargetLink APIs to create a continuous integration pipeline that meets all of your requirements. If you want to see TargetLink in action with a continuous integration pipeline using a Jenkins server, join our webinar “Learning Connection: How to Implement a Continuous Integration Workflow with Model-Based Development (MBD)”.

But There Is More …

Software development processes are becoming more and more complex, and our customers have to stay on top of them. We are proud that TargetLink offers you everything you need to reach your goals. Stay tuned for more detailed posts about continuous integration pipelines. Until then, we look forward to supporting you in creating your own continuous integration workflows. If you have any questions on new or existing pipelines, feel free to contact us.

Product Information Contact Information

Drive innovation forward. Always on the pulse of technology development.

Subscribe to our expert knowledge. Learn from our successful project examples. Keep up to date on simulation and validation. Subscribe to/manage dSPACE direct and aerospace & defense now.

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.