Valgrind plugin¶
Description¶
The valgrind plugin is used for executing code coverage analysis using valgrind.
Mandatory settings¶
The configuration of the valgrind plugin must contain the following settings:
-
run-command
The exec-helper command or plugin to use for running the binaries which need to be analyzed.
Optional settings¶
The configuration of the valgrind plugin may contain the following settings:
-
patterns
A list of patterns to apply on the command line. See Patterns (5).
-
command-line
Additional command line parameters to pass as a list of separate arguments. By default no additional arguments are added.
-
tool
The valgrind tool to use. Default: the
tool
is omitted.
Example¶
Configuration¶
commands: # Define the commands that can be run
example: Run the lcov example
build: Build the files
clean: Clean the build
run: Run the built binaries
patterns: # Define the patterns that can be used
MAKE_TARGET: # Define make targets for building
default-values: # Only define the default value
- hello
- world
example:
- build
- valgrind # Use the valgrind plugin when running the 'example' command
build:
- make
clean:
- make
- command-line-command
run:
command-line-command
valgrind: # Configure the valgrind plugin
run-command: run # Execute the 'build' command for building, running and analyzing the project
tool: memcheck # Set the tool
command-line: # Set additional arguments for valgrind
- --error-exitcode=255
make:
build:
patterns:
- MAKE_TARGET
command-line:
- "{MAKE_TARGET}"
clean:
command-line:
- clean
command-line-command:
patterns:
- MAKE_TARGET
run:
command-line: ["build/{MAKE_TARGET}"]
clean:
command-line:
remote-gcda-file: [ rm, -rf, "{MAKE_TARGET}.gcda"]
remote-gcno-file: [ rm, -rf, "{MAKE_TARGET}.gcno"]
Additional files¶
In order for the above example to work, the following file hierarchy needs to be created in the directory:
Makefile:
CXX=g++
CXXFLAGS+=-O0 -g --coverage
LDFLAGS+=
SRC_DIR=src
BUILD_DIR=build
hello:
mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/hello $(SRC_DIR)/hello.cpp
world:
mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/world $(SRC_DIR)/world.cpp
clean:
rm -rf $(BUILD_DIR)
.PHONY: clean
hello.cpp:
#include <cstdlib>
#include <iostream>
auto main() -> int {
std::cout << "Hello" << std::endl;
return EXIT_SUCCESS;
}
world.cpp:
#include <cstdlib>
#include <iostream>
auto main() -> int {
std::cout << "World!" << std::endl;
return EXIT_SUCCESS;
}
Usage¶
Save the example to an exec-helper configuration file and execute in the same directory:
eh example
See also¶
See exec-helper (1) for information about the usage of exec-helper.
See Custom plugins (5) for the available plugins and their configuration options.
See Configuration (5) for information about the configuration file format.