See what API testing solution came out on top in the GigaOm Radar Report. Get your free analyst report >>

See what API testing solution came out on top in the GigaOm Radar Report. Get your free analyst report >>
Jump to Section
You may have read in a previous post about how to apply SAST and unit testing in a containerized environment. Here's a continuation on how you can aptly deploy static analysis and unit testing using Parasoft C/C++test Standard in a Docker container.
Jump to Section
Jump to Section
Containers are an evolutionary, standardized, and portable packaging technology that’s being deployed right into today’s modern Agile development workflows like DevOps/DevSecOps. Containers were first introduced for web applications and microservices development and deployment where they gained wide adoption in the IT industry. Today, the embedded industry uses containers extensively.
Containers offer a quick reproduction of identical environments for embedded development, software testing, staging, and production at any phase of the SDLC.
Deploying containers provides several benefits.
It’s important to understand the container architecture. Let’s go through a quick description. A container is an application bundled with other components or dependencies like binaries or specific language runtime libraries and configuration files. Containers have their own processes, their own network interfaces, and mounts.
Containers are also isolated from each other and run on top of a container engine, such as Docker, for easy portability and flexibility. In addition, containers share an operating system and run on any of the following:
It’s also important to understand the role of the container engine because it provides crucial functionalities, including:
A container image is a static file with executable code and includes everything a container needs to run. Therefore, a container is a running instance of a container image. C/C++test ships with an example container image, but to be more specific, it’s a Docker file.
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 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:
style=”font-size: 13px;”>$HOME/sandbox/parasoft_cpptest_standard-2020.1.0-linux.x86_64.tar.gz
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 like this:
Voila! 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 that’s another 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 product 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.