The C/C++test CT runtime library is a collection of helper functions and services used by source code instrumentation to emit coverage information at application runtime. Instrumented applications cannot be linked without the library. The runtime library can be linked to the final testable binary in multiple ways depending on tested project type.
In addition to providing basic services for instrumented code, the library is also used to adapt the code coverage solution to particular development environments, such as supporting non-standard transport for coverage results between tested embedded device and development host.
C/C++test CT ships with pre-built versions of the runtime library, which are suitable for use on the same platform on which C/C++test CT is installed. In most of the cases, collecting code coverage information from natively developed applications can use pre-built versions of the runtime library.
All users developing cross-platform applications will need to prepare a custom build of the runtime library using a suitable cross compiler and possibly linker. Source code of the code coverage runtime library is shipped with C/C++test CT.
The process of preparing the runtime library custom build is typically limited to the compilation of runtime library source code. In some situations, you may need to customize some fragments of source code to adapt code coverage to a particular development platform. This process is described in the following sections.
The following binary files are included with the C/C++test CT:
Linux (x86 and x86-64)
File | Description |
---|---|
<INSTALL_DIR>/runtime/lib/libcpptest.so | 32-bit shared library. To be added linking command line. <INSTALL_DIR>/runtime/lib should be added to LD_LIBRARY_PATH |
<INSTALL_DIR>/runtime/lib/libcpptest64.so | 64 bit shared library. To be added linking command line. <INSTALL_DIR>/runtime/lib should be added to LD_LIBRARY_PATH |
If you need to use the runtime library in a form not provided as an out-of-the-box solution, prepare a custom build of the runtime library that matches specific development environment requirements. For more details, see Customizing the Runtime Library.
Integrating the C/C++test CT runtime library with a tested application linking process usually requires modifying the linker command line and, in some cases, the execution environment. This section describes how to modify the linking process when using the pre-built versions shipped with C/C++test CT.
Note: When using dedicated CMake or Bazel integration packages, you do not need to integrate the C/C++test CT runtime library with your build scripts. The integration package will automatically extend your linker command line with the appropriate library. This section describes a generic process for customizations. See Collecting Coverage for CMake Projects or Collecting Coverage for Bazel Projects for more information.
Shared library for Linux GNU GCC compilers:
Modify the build scripts so that the coverage runtime library is specified somewhere in the linker command line--preferably after all object files.
Example:
$(LXX) $(PRODUCT_OBJ) $(OFLAG_EXE)$(PROJ_EXECUTABLE) $(LXXFLAGS) $(SYSLIB) $(EXECUTABLE_LIB_LXX_OPTS) -L <INSTALL>/runtime/lib -lcpptest |
Note the addition of the -L <INSTALL_DIR>/runtime/lib
and -lcpptest
options.
<INSTALL_DIR>/runtime/lib
location.You may need to customize the runtime library as a result of the following conditions:
The runtime library source code is shipped with C/C++test CT in the <INSTALL_DIR>/runtime
directory. The following table describes the structure:
Component | Description |
---|---|
include | Directory that contains the library include files. |
src | Directory that contains the library source code. |
Makefile | Basic Makefile provided for building the runtime library. |
target | Directory that contains a set of Makefile include files with compiler specific options for preparing runtime library builds for most popular development environments. |
channel | Directory that contains a set of Makefile include files with configuration for supported communication channels. |
CMakeLists.txt | Basic CMakeLists.txt file for building the runtime library with CMake (alternative to Makefile). |
The runtime library supports data collection through various communication channels. The communication channel used depends on the development environment. In most cases, storing results in a file or files is appropriate, but in other TCP/IP sockets or RS232 transport may be required. Specific communication channels can be enabled by setting the value to a dedicated macro during cpptest.c
library source file compilation. Add -D<MACRO> to the compilation command line to set the value. The following table provides the full list of communication channel control macros:
Channel | Description |
---|---|
CPPTEST_NULL_COMMUNICATION | Empty implementation. If enabled no results will be sent. Suitable for initial test builds and debugging. |
CPPTEST_FILE_COMMUNICATION | File-based implementation. ANSI C File I/O interface is used. If enabled, results will be written to a local drive file. The following additional configuration macros are also provided:
|
CPPTEST_SPLIT_FILE_COMMUNICATION | File-based implementation. ANSI C File I/O interface is used. If enabled, results will be written into a series of local drive files. You can configure this channel with the following macros:
To pass the series to
|
CPPTEST_UNIX_SOCKET_COMMUNICATION | TCP/IP socket based implementation. POSIX API is used. If enabled results are sent to the specified TCP/IP port. The following additional configuration macros are provided:
When C/C++test CT does not provide a utility for reading socket data. Depending on the automation requirements, users can apply popular open-source utilities such as Netcat or implement a dedicated Python script to read the test data sent through the socket. |
CPPTEST_WIN_SOCKET_COMMUNICATION | As above, MS Windows API is used. |
CPPTEST_UNIX_SOCKET_UDP_COMMUNICATION | As above, UDP based implementation. |
CPPTEST_RS232_UNIX_COMMUNICATION | RS232 based implementation. POSIX API is used. If enabled then results are sent via the specified RS232 system device. The following additional configuration macros are provided:
When C/C++test CT does not provide a utility for reading serial link data. Depending on the automation requirements, users can apply popular open-source utilities or implement a dedicated Python script to read the test data sent through the serial link. |
CPPTEST_RS232_WIN_COMMUNICATION | As above. MS Windows API is used. |
CPPTEST_RS232_STM32F103ZE_COMMUNICATION | STM32F103x USART based implementation. STM Cortex library interface is used (ST/STM32F10x/stm32f10x.h header file is required) |
CPPTEST_HEW_SIMIO_COMMUNICATION | Renesas HEW simulator specific implementation. |
CPPTEST_LAUTERBACH_FDX_COMMUNICATION | Lauterbach TRACE32 based implementation (FDX used) |
CPPTEST_ITM_COMMUNICATION | ARM CoreSight ITM unit based communication. Requires CMSIS header files. |
CPPTEST_CUSTOM_COMMUNICATION | Enables empty template for custom implementation |
If the runtime library is being built with the provided Makefile, then one of the make configuration files provided in the <INSTALL_DIR>/runtime/channel
directory can be used. See Building the Runtime Library Using the Provided Makefile for details.
If the runtime library is being built with the provided CMakeLists.txt, then one of the available CMake variables can be used for channel configuration. See Building the Runtime Library Using the Provided CMakeLists.txt file for details.
If none of the communication channel implementations fit into your development environment, then a custom implementation can be provided. The following instructions describe how to customize the runtime library so that it uses a custom implementation of a communication channel:
<INSTALL_DIR>
/runtime
.Open the runtime/src/cpptest.c
file, and locate the section 1.13 "Custom Communication Implementation".
The custom communication implementation section contains empty templates for four different methods:
Function | Description |
---|---|
void cpptestInitializeStream(void) | This function is responsible initializing the communication channel, for example creating and connecting to a socket or the initialization of UART device. |
void cpptestFinalizeStream(void) | This function is responsible for finalizing the communication channel. For example, it may be responsible for closing TCP/IP socket. |
| This function is responsible for sending size bytes from a data buffer. |
void cpptestFlushData(void) | This function is responsible for flushing the data. Its meaning depends on the particular transport type. It may have a limited application in some implementations. In this case, it should be left empty. |
-DCPPTEST_CUSTOM_COMMUNICATION
compiler option is used during compilation. The runtime library contains support for multithreaded applications. POSIX and VxWorks APIs are supported. You can enable support for a specific multithreading API by adding -D<MACRO>
to the compilation command line during cpptest.c
compilation. The following table describes the full list of multithreading API support control macros:
Macro | Description |
---|---|
CPPTEST_NO_THREADS | Empty implementation. Coverage runtime is not prepared to be used together with multithreaded applications |
CPPTEST_UNIX_THREADS | POSIX multithreading API implementation |
CPPTEST_VXWORKS_THREADS | VxWorks multithreading API implementation |
If you are using C/C++test CT with multithreaded applications that do not use a supported multithreading API, you can customize the runtime library to work with your multithreading API. There are following steps required:
<INSTALL_DIR>/runtime
Open the runtime/src/cpptest.c
file, and locate the section 2.5 "Custom Multithreading Implementation".
Custom multithreading implementation section contains empty templates for two different methods:
Function | Description |
---|---|
static int cpptestLock(void) | This function ensures synchronized operations inside the coverage tool runtime library. If a thread locks access to the runtime library service, it means an atomic operation is in progress and no other thread can use runtime library services. Once the lock is released other threads can use runtime library services |
static int cpptestUnlock(void) | Releases the lock on runtime library services. |
Provide the implementation for the methods that matches your environment requirements.
Compile cpptest.c
with the following macro added to compilation command line:"-DCPPTEST_CUSTOM_THREADS"
If the generated object file is insufficient, you can process the file even further to meet your needs (e.g., to create a shared library).
When the same coverage log file (.clog) is used by multiple instrumented binaries running in parallel, it is required to enable multi-process support in the Runtime Library.
In order to enable multi-process support, compile cpptest.c
with the following macro added to the compilation command line:"-DCPPTEST_MULTI_PROCESSES_LOG=1"
The C/C++test CT runtime library can be built using one of the methods:
<INSTALL_DIR>
/runtime
.If compilation flags need to be modified (e.g., adding specific cross-compiler specific or definitions to enforce runtime library reconfiguration), provide a new make configuration file in the target subdirectory. For convenience, copy one of the existing target configuration files and modify its contents to fit your needs.
Invoke the following command line to create a build
subdirectory that contains a single object cpptest.<OBJ_EXT>
, which can be used to link with the instrumented application.
make TARGET_CFG=<target config file name> CHANNEL_FILE=<channel config file name> |
Your command line may resemble the following:
make TARGET_CFG=gcc-static.mk CHANNEL_FILE=channel/unix-socket.mk |
Alternatively, you can provide the channel type:
make TARGET_CFG=gcc-static.mk CHANNEL_TYPE=unix-socket |
<INSTALL_DIR>/runtime.
cmake -S . -B build <configuration variables>
cmake -S . -B build -DCPPTEST_COMMUNICATION=CPPTEST_UNIX_SOCKET_COMMUNICATION |
cmake --build build
To setup a user build of coverage tool runtime library perform the following steps:
<INSTALL_DIR>
/runtime/src/cpptest.c
to your preferred location. -I
) with the following value:-I<INSTALL_DIR>runtime/include
-D)
Example:-DCPPTEST_FILE_COMMUNICATION -DCPPTEST_NO_THREADS