This section explains how to run analysis and execute tests with C/C++test utilizing a C/C++ toolchain or testing environment provided by a Docker container.
In this section:
C/C++test ships with support for running analysis and executing tests in a Docker container. In this scenario, C/C++test hosted on your local machine is configured to run analysis and execute tests in a container that contains your testing environment or C/C++ toolchain.
Docker integration for C/C++test consist of following components:
- Scripts for remote process execution in a Docker container located in
remote-gcc– a gcc command wrapper
remote-g++– a g++ command wrapper
remote-exec– a generic command wrapper
builtin://Run Unit Tests in Container– a test configuration for running unit tests inside a Docker container.
- Linux 64-bit (host)
- C/C++test Professional for Linux 64-bit (installed on a host)
- A Docker container image that includes your toolchain and test execution environment for running analysis and testing with C/C++test
Configuring and Starting the Container
To enable communication between C/C++test and your Docker container, you must ensure that the container has access to all directories on the host that are related to the project you want to test with C/C++test and that C/C++test can identify the container you want to use by its identifier or name.
- Mount the following folders to the container:
- Eclipse workspace location.
- Eclipse project location – if the project is located outside of the Eclipse project or workspace.
- Locations of all source files that are outside of the Eclipse project or workspace.
- C/C++test installation location – only required for unit testing of your project to ensure access to C/C++test runtime library from within the container.
2. Assign the container ID or container name to the
CPPTEST_CONTAINER_NAMEenvironment variable. For the ease of use, we recommend that you give your container a readable and meaningful name.
The following example assumes that the project and all source files are in the Eclipse workspace (
/home/devel/workspace) and C/C++test is installed in
/opt/parasoft/cpptest. The container name is specified with the
--name option is "gcc9-test-container" to indicate that the container image includes the GCC 9 compiler.
docker run --rm -it -d -v /opt/parasoft/cpptest:/opt/parasoft/cpptest -v /home/devel/workspace:/home/devel/workspace --name gcc9-test-container gcc:9
Assign the container name to the environment variable:
Configuring C/C++test to Run Analysis and Testing in the Container
Creating a Custom Compiler Configuration for Unit Testing
Executing tests with C/C++test in a Docker container requires creating a custom compiler configuration to ensure that C/C++test's runtime library can be built inside your container.
- Duplicate the compiler configuration that matches your Docker compiler (see Configuring Testing with the Cross Compiler for details about creating a custom compiler configuration).
- Modify the
<CUSTOM_COMPILER_CONFIG>/gui.propertiesfile to set or remove the following options:
You can skip creating a custom compiler confguration if you only run static code analysis.
Setting Up a Project for Testing in a Container
You need to modify your project properties to configure a remote toolchain for your project.
- Open the project properties in your IDE.
- Go to Parasoft> C/C++test> Build Settings> Compliler settings.
- Select the compiler family that matches your compiler configuration; see Creating a Custom Compiler Configuration for Unit Testing.
- Replace the default C / C++ compiler and linker commands with wrapper scripts:
- C compiler:
- C++ compiler:
Alternatively, you can copy the scripts from
<CPPTEST_INSTALL_DIR>/integration/dockerinto your project and specify the paths relative to your project. This allows you to store the settings in your source control system and share them across the team. For example:
- C compiler:
- C++ compiler:
Running Static Analysis in the Container
Before you run static analysis, ensure that your Docker container is running (see Configuring and Starting the Container). No further configuration steps are required.
You can use any test configuration to analyze your code. During analysis, C/C++test will use the C/C++ compiler from the Docker container accessed via the wrapper script you configured in your project properties (see Setting Up a Project for Testing in a Container).
Creating and Executing Unit Test in the Container
Generating Unit Tests
Before you create unit tests with C/C++test, ensure that your Docker container is running (see Configuring and Starting the Container). No further configuration steps are required.
You can use a test configuration to generate unit tests (for example,
builtin://Generate Unit Tests). During test generation, C/C++test will use the C/C++ compiler from the Docker container accessed via the wrapper script you configured in your project properties (see Setting Up a Project for Testing in a Container).
Executing Test Cases
- Before you run unit tests with C/C++test, ensure that your Docker container is running (see Configuring and Starting the Container).
- (optional) Duplicate the built-in
Run Unit Tests in Containertest configuration and modify the parameters to create a custom test configuration. For example, you can modify the location of the execution wrapper script in Execution> General> Execution details> Remote execution command (the default is
- Run the built-in or custom
Run Unit Tests in Containertest configuration. C/C++test will:
a) build a test executable using the remote toolchain specified in the project properties (see Setting Up a Project for Testing in a Container).
b) execute tests inside your container using the
c) automatically collect test results and coverage information.