Coverage reports show which lines of C++ source code are exercised by
simulations. Uses the coverage build mode and LLVM's coverage tools.
Coverage reports require:
- Clang / LLVM toolchain — the project must be compiled with Clang so that LLVM source-based coverage instrumentation is available.
llvm-profdata— used to merge the raw.profrawprofile files produced during simulation into a single.profdatafile.llvm-cov— used to generate the HTML coverage report from the merged profile data.- OMNeT++
coveragebuild mode — the project must be buildable incoveragemode, which compiles with-fprofile-instr-generate -fcoverage-mapping. See Building for how build modes work.
On Debian/Ubuntu, install the LLVM tools with
sudo apt install llvm (or the versioned package matching your Clang, e.g.
llvm-17).
No extra Python packages are required.
Both generate_coverage_report() and open_coverage_report() follow the same
pipeline:
- The environment variable
LLVM_PROFILE_FILEis set tocoverage-%p.profrawso that each simulation process writes its own raw profile file (the%pis replaced by the process ID). - The simulation project is built in
coveragemode and the matching simulations are run. - All
coverage-*.profrawfiles under the project root are collected and merged withllvm-profdata mergeinto a singlemerged.profdatafile. llvm-cov showis invoked with the project's coverage-mode executable and the merged profile data. It produces an HTML report in thecoverage/directory (or a custom directory viaoutput_dir).- Temporary
.profrawfiles and the merged profile are cleaned up automatically. open_coverage_report()additionally openscoverage/index.htmlin the system's default browser.
The functions accept all the same filter parameters as run_simulations()
(e.g. working_directory_filter, config_filter, run_number,
sim_time_limit).
# Generate and open a coverage report in the browser
open_coverage_report(simulation_project=inet_project,
working_directory_filter="examples/ethernet",
sim_time_limit="10s")generate_coverage_report(simulation_project=inet_project,
working_directory_filter="examples/ethernet",
sim_time_limit="10s")
# The report is written to <project_root>/coverage/index.htmlRun more simulations to widen coverage — all .profraw files under the
project root are merged into a single report:
generate_coverage_report(simulation_project=inet_project,
working_directory_filter="examples",
sim_time_limit="10s")Both functions accept:
simulation_project— the simulation project (defaults to the current default project)output_dir— directory name for the HTML report relative to the project root (default"coverage")- All filter parameters from
run_simulations():working_directory_filter,config_filter,run_number,sim_time_limit, etc.
There are no dedicated command-line wrappers for coverage reports. Use the
Python API from within opp_repl.