In this section:
Verify that the executable (
C/C++test is optimized to minimize the impact on your development process. By reusing information collected in previous analysis runs, it can reduce the analysis time in subsequent runs. The information is stored in the .cpptest folder in your working directory (see the -workspace option).
To ensure optimal performance, avoid removing the .cpptest folder or deleting the contents of the folder.
C/C++test must be configured for use with specific C and C++ compilers and versions before you can analyze code. The configuration should reflect the original compiler and version used for building the code under test. The original compiler executable must be available on $PATH (unless it is specified with a full path).
-compiler switch to specify the compiler configuration identifier:
cpptestcli -config "builtin://Recommended Rules" -compiler gcc_4_5 -input cpptest.bdf
Alternatively, you can configure the
cpptest.compiler.family property in a custom configuration file:
If you are using a single compiler and version for all testing, the compiler identifier can be specified in the
cpptestcli.properties global configuration file in either the [INSTALL_DIR] or [USER_HOME] directory; see Configuration Overview.
Perform one of the following actions to find the configuration for your compiler:
-detect-compiler switch to the auto-detect configuration:
cpptestcli -detect-compiler gcc
-list-compilers switch to find the configuration in the list of all supported compilers:
See Configuring the Compiler and Supported Compilers for additional information.
The following instructions assume that:
Run an analysis and specify the original compiler command with the
-- switch (separator).
All values after
cpptestcli -config "builtin://Recommended Rules" -compiler gcc_3_4 -- gcc -I include Bank.cxx
C/C++test will analyze the Bank.cxx file using the original compiler executable and compiler options and report detected violations to the output console.
Only the specified source files will be analyzed. Header files included by the source files will be excluded from analysis. To broaden the scope of files tested, including header files, see.
You can also use the
-fail option to generate a non-zero exit code when the analysis reports static analysis findings (see Command Line Exit Codes).
Run code analysis and specify the original build command with the
All values after -trace will be interpreted as a build command, so options specific to C/C++test must be specified before
cpptestcli -config "builtin://Recommended Rules" -compiler gcc_3_4 -trace make clean all
C/C++test will perform the following tasks:
C/C++test will detect a source file for testing only if that file was compiled when running the build command. Only source files from Makefile will be analyzed. Header files included by the source files will be excluded from analysis. To broaden the scope of files tested, including header files, see.
You can create a build data file (.bdf), which stores information such as the working directory, command line options for the compilation,and link processes of the original build, so that C/C++test can analyze a project without having to rebuild it. The following example is a fragment from a build data file:
working_dir=/home/place/project/hypnos/pscom project_name=pscom arg=g++ arg=-c arg=src/io/Path.cc arg=-Iinclude arg=-I. arg=-o arg=/home/place/project/hypnos/product/pscom/shared/io/Path.o
You can use the
-trace switch to create a .bdf or use the standalone
cpptesttrace utility located in the [INSTALL_DIR]/bin directory.
cpptestscan utility is used as a wrapper for the compiler and/or linker during the normal build. To use
cpptestscan with an existing build, prefix the compiler/linker executable with
cpptestscan when building the code base. This can be done in two ways:
cpptestscanas the wrapper for the compiler/linker executables
cpptestscanin the actual make file or build script.
cpptesttrace with an existing build, prefix the entire build command with
cpptesttrace when building the code base.
cpptesttrace will trace the compiler and linker processes executed during the build and store them in the build data file.
In both cases, you must specify the full path to either utility in your PATH environment variable. Additional options for
cpptesttrace are summarized in the following table. Options can be set directly for the
cpptestscan command or via environment variables. Most options can be applied to
cpptesttrace by changing the prefix in the command line.
Basic cpptestscan usage:
cpptestscan.exe [options] [compile/link command]
cpptestscan [options] [compile/link command]
Basic cpptesttrace usage:
cpptesttrace.exe [options] [build command]
cpptesttrace [options] [build command]
|CPPTEST_SCAN_OUTPUT_FILE||Defines file to append build information to.||cpptestscan.bdf|
|CPPTEST_SCAN_PROJECT_NAME||Defines a suggested name of the C++test project.||name of the current working directory|
|CPPTEST_SCAN_RUN_ORIG_CMD||If set to "yes",original command line will be executed.||yes|
Determines the way C++test quotes parameters when preparing cmd line to run.
cpptestscanQuoteCmdLineMode is not supported on Linux
|CPPTEST_SCAN_CMD_LINE_PREFIX||If non-empty and running original executable is turned on, the specified command will be prefixed to the original command line.||[empty]|
|CPPTEST_SCAN_ENV_IN_OUTPUT||Enabling dumps the selected environment variables and the command line arguments that outputs the file. For advanced settings use --cpptestscanEnvFile and --cpptestscanEnvars options||no|
|CPPTEST_SCAN_ENV_FILE||If enabled, the specified file keeps common environment variables for all build commands; the main output file will only keep differences. Use this option to reduce the size of the main output file. Use this option with --cpptestscanEnvInOutput enabled||[empty]|
Run code analysis and specify the existing build data file with the
cpptestcli -config "builtin://Recommended Rules" -compiler gcc_3_4 -input cpptest.bdf
C/C++test will perform the following tasks:
Multiple build data files can be specified using multiple
cpptestcli -config "builtin://Recommended Rules" -compiler gcc_3_4 -input project1.bdf -input project2.bdf
Only the source files defined in the build data file will be analyzed. Header files included by the source files will be excluded from analysis. To broaden the scope of files tested, including header files, see.
C/C++test can read Visual Studio project and solution files and analyze all source and included header files from the project or solution. Use the
-input switch to specify a Visual Studio project or solution file:
cpptestcli -config "builtin://Recommended Rules" -input MyProject.vcproj
You can specify the build configuration and the platform you want to use during analysis of your project or solution. Append the configuration and platform names to the solution or project file name. Your command may resemble the following:
cpptestcli -config "builtin://Recommended Rules" -input [email protected]|x64
Alternatively, you can use the following properties to specify the build configuration and the platform you want to use during analysis of all Visual Studio solutions and projects:
For all Microsoft Visual Studio settings, see Visual Studio Settings.
Ensure that the correct version of Microsoft Visual C++ compiler is available on $PATH before running analysis. Microsoft Visual Studio 6 is not supported.
Exclusive access to the
.cpptest directory is required. The directory is created in the current working directory by default, which is where some of the run-specific data is stored. As a result, only one instance of C/C++test can run in a directory at a time. You can use the
-workspace switch to change the location of the .cpptest directory.