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:
INSTALL_DIR>/integration/docker:remote-gcc – a gcc command wrapperremote-g++ – a g++ command wrapperremote-exec – a generic command wrapperbuiltin://Run Unit Tests in Container – a test configuration for running unit tests inside a Docker 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.
CPPTEST_CONTAINER_NAME environment 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:
export CPPTEST_CONTAINER_NAME=gcc9-test-container |
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.
<CUSTOM_COMPILER_CONFIG>/gui.properties file to set or remove the following options:autoBuildRuntimeLib=true-lcpptestruntime64 from linkerCmdLineYou can skip creating a custom compiler configuration if you only run static code analysis.
You need to modify your project properties to configure a remote toolchain for your project.
<CPPTEST_INSTALL_DIR>/integration/docker/remote-gcc<CPPTEST_INSTALL_DIR>/integration/docker/remote-g++<CPPTEST_INSTALL_DIR>/integration/docker/remote-g++<CPPTEST_INSTALL_DIR>/integration/docker into 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:${project_loc}/docker/remote-gcc${project_loc}/docker/remote-g++${project_loc}/docker/remote-g++
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).
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).
Follow these steps to run unit tests with C/C++test:
Run Unit Tests in Container test 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:${cpptest:install_dir}/integration/docker/remote-exec).Run Unit Tests in Container test configuration. C/C++test will:remote-exec wrapper script.