Want to see Parasoft in action? Sign up for our Monthly Demos! See Demos & Events >>
Part 1 of this post discussed the benefits of using containers to deploy embedded development toolchains. It showed how to configure Parasoft C/C++test Professional to work with the compilation toolchain and test execution environment deployed in a container.
Now, let’s look at creating a container image with Parasoft C/C++test Standard. I’ll demonstrate a simple example with an in-container static analysis execution.
As a command line based tool, Parasoft C/C++test standard is suitable for in-container deployments. It can be packaged with the compiler and build system into one container image and used for CI/CD and deployed to developers’ desktops for the local command line scans. The image below shows the high-level overview of this setup:
The diagram shows Jenkins using containerized C/C++test to run static analysis. In this specific setup, Parasoft C/C++test, the compilation toolchain, and the build tools are deployed in the container shown in the top right corner of the diagram.
The container below it in the bottom right, provides the execution environment, which may be required to execute runtime tests, like unit tests or automated system level tests.
If we intend to implement only static analysis, our setup will most likely include only one type of container with the compilation toolchain and Parasoft C/C++test.
If you haven’t done already so, please install the latest release of the Parasoft C/C++test 2020.1 for Linux.
To simplify the process of creating a container image with C/C++test, the latest release ships with an example of the Dockerfile. You can find this Dockerfile in the following location:
<C/C++test standard installation>/integration/docker/Dockerfile
This simple Dockerfile focuses only on the required C/C++test steps to build the image. In most real world cases, you’ll need to merge this file with your Dockerfile.
Before we analyze the content in the example Dockerfile, let’s see how it works. My example assumes the following simple file structure:
1. Unzip the C/C++test distribution.
2. Copy out the example Dockerfile from the distribution
3. Prepare a property file for the C/C++test with the information about the license. We’ll use the default cpptestcli.properties file as a base, so we’ll copy it to our working directory:
Edit it to insert the information about your license server location. Use your favorite editor to configure the licensing information. Save the file when you’re done.
4. Edit the Dockerfile and uncomment line number 13 (the one where the cpptestcli.properties file is copied from the local directory to the location in the containers). The line in the Dockerfile should look like this:
5. Now, we’re ready to create the Docker image. Run the command to build the first image with C/C++test. The image name is “cpptest_ci_image”.
Docker will take some time to analyze its cache and download the required base image. Once this is done the C/C++test distribution is copied and installed into the image. After a minute or two, the image should be ready. Confirm it by executing the command to list the all the images:
In the output, you should see the “cpptest_ci_image” listed at the top. Great, so we have an image built and ready. Now it is the time to test it!
For a simple test, use one of the helper/exemplary command lines provided inside the Dockerfile.
Use your favorite editor to open the Dockerfile, and scroll down to the bottom of the files. You should see couple of example command lines like this:
Let’s use the command line from line 26 to execute an in-container static analysis on one of the C/C++test examples shipped with the distribution.
Since we decided to build in the cpptestcli.properties file with the licensing information into the container, we can simplify the command line and remove the -settings option. The command line for the test should look this:
Voila! The static analysis was executed in-container. The results were reported on the console.
We could further configure the tool to produce the HTML report on the local file system, but this is a different story. Our primary goal was to create the container with C/C++test inside and configure it to execute static analysis. We achieved the goal.
If you need to set up a CI server with static analysis as part of the process, your task is much simpler. Just access the container. The same is true if developers on your team want to run static analysis.
Need to upgrade Parasoft C/C++test to the latest release? Just download the distribution, rebuild your container image, and you’re done! The team and the automated infrastructure won’t even notice this operation. Smooth, easy, and reversible, if necessary.
Before we finish, let’s look at the content of the Dockerfile shipped with Parasoft C/C++test that was just used to create our image. The image below shows the content of <install dir>/integration/docker/Dockerfile.
Here are the details:
This is all that’s needed to create a simple container with Parasoft C/C++test that is ready to execute static analysis.
As I mentioned, this is a simple Dockerfile. It was added to the distribution to give you an example of what you may need to create a container image for your environment. You will need to adapt it to your needs or merge it with existing Dockerfiles.
Product Manager for Parasoft's embedded testing solutions, Miroslaw's specialties include C/C++, RTOSes, static code analysis, unit testing, managing software quality for safety critical applications, and software compliance to safety standards.