Want to see Parasoft in action? Sign up for our Monthly Demos! See Demos & Events >>
Want to see Parasoft in action? Sign up for our Monthly Demos! See Demos & Events >>
The release of Parasoft C/C++test 2020.1 brings a collection of enhancements that make it easy to use with Docker containers. I’ll walk you through the steps to configure C/C++test 2020.1 to work in containerized development environments.
Containerized deployments of development tools are becoming the bread and butter of embedded development teams. Even though containers were initially developed to solve problems with the deployment of microservices and web-based applications, they recently gained popularity among embedded teams — especially big teams that use containers to manage complex toolchains.
When it comes to managing complex development environments, especially in the safety-critical space, teams usually struggle with the following challenges:
All these problems are easy to solve with containers. No wonder teams love containers! Let’s have a look at how to configure C/C++test for use in a containerized environment.
It’s easy to configure Parasoft C/C++test Professional to work with a compilation toolchain and the execution environment deployed in containers. We support deployments that are based on Linux and Docker containers. Here’s a high-level overview of how that type of setup looks:
As you can see, C/C++test accesses the containerized compiler (GNU GCC) and the runtime environments. In this specific setup, there are two separate Docker containers:
Let’s see how to configure C/C++test Professional to work with an in-container compilation toolchain and execution environment. In the example, we’ll use the latest GCC container image available via the Docker hub.
Let’s see how to configure C/C++test Professional to work with an in-container compilation toolchain and execution environment. In the example, we’ll use the latest GCC container image available via the Docker hub.
The following instructions assume you have a Docker engine correctly installed and configured in your environment. And the same for C/C++test Professional 2020.1.
2. Before we start Parasoft C/C++test, set a dedicated environmental variable CPPTEST_CONTAINER_NAME to the name of the container. This is an easy way to tell C/C++test which container should be used to invoke compiler or linker. It works nicely with Jenkins jobs.
3. In addition, I recommend that you set the CPPTEST_INSTALL variable to point to the C/C++test installation directory. It makes for a simple setup. Once the variables are set, we can start C/C++test.
4. For your workspace, select a location somewhere in the HOME directory (more on this later).
To make creating a demo project super simple, let’s create the default “HelloWorld” project using the standard “New Project” wizard.
1. Choose File Menu> New> C++ Project and then pick “Hello World C++ Project”.
2. Enter the name of choice for your project. It should look more or less like the screenshot below.
3. Click Finish to create the default project for our example.
Once the project is created, modify a couple of items in the C/C++test Build Settings.
1. Right click on the project and select Properties and then Parasoft>C/C++test>Build Settings.
2. In the Build Settings panel, modify two items in the Compiler settings section:
Make sure that the container with your compilation toolchain is up and running before using Parasoft C/C++test.
The compiler wrappers that we set up in the previous step are designed to execute the compiler commands in the running container, which is faster than starting the container for every invocation.
For CI/CD deployments, starting the container before C/C++test runs and stopping it after can be a part of the Jenkins job. In this example, we assume GUI base is used. We can create eclipse Run Configurations for this purpose. I suggest creating two configurations of “C/C++ Application” type and naming them as follows:
1. Select Run menu > Run Configurations …
2. Create two Run Configurations named “Start gcc container” and “Stop gcc container”.
3. In the Main tab for both configurations, enter your path to Docker as the “C/C++ Application” like shown below:
4. For “Start gcc container”, in the arguments tab enter the following command:
style="padding-left: 40px;">run --rm -d -it --name gcc -v ${env_var:HOME}:${env_var:HOME}
-v ${env_var:CPPTEST_INSTALL}:${env_var:CPPTEST_INSTALL} gcc
As shown in the screen shot below:
The interesting part of this command are -v options, which are used for mapping volumes.
The first -v option maps the local HOME directory to the container file system. The intention here is to enable access to the source code for the compiler operating inside the container and also for Parasoft C/C++test, which runs in the host operating system.
I’m using HOME in my example for convenience because I placed my workspace directly in HOME.
For real setups, you can strictly map only the part of the file system that contains the source tree and the eclipse workspace with project.
The second -v option maps the location of C/C++test installation directory to enable access to C/C++test header files inside the container.
5. For “Stop gcc container”, in the arguments tab enter the following command as shown in the image below:
stop gcc
6. Let’s use the “Start gcc container” run configuration to run the container.
Eclipse console should show you the hash of the container. To make sure everything is all right, you can switch to the command line and invoke the following command:
If you see our “gcc” container on the list, you're good to start using C/C++test for testing your code.
7. Let’s select the project in the navigator. Using the Parasoft menu, select Test Using> Builtin> Unit Testing> Generate Unit Tests.
You should see a new “tests” directory created inside your project with a single unit test created for the “main” function.
8. Once the test cases are generated, you're ready to execute them. For the execution, select Test Using> Builtin> Unit Testing> Run Unit Tests in the container.
C/C++test should invoke a collection of in-container compilations and linking command lines, ending with a test binary creation and execution in the container.
That’s it! With these steps, you prepared Parasoft C/C++test to perform testing activities using the in-container compilation toolchain.
If you need to change the compiler for a project or modify something in the runtime execution environment, you can either update the container image or change it to a different version. (Remember to update the CPPTEST_CONTAINER_NAME variable.)
Stay tuned for Part 2 coming soon. I will explain how to create a container image with Parasoft C/C++test Standard.
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.