Skip to content

docs: add ELD code coverage guide#1262

Open
Saharsh Burra (bsaharsh) wants to merge 1 commit into
qualcomm:mainfrom
bsaharsh:code-coverage-guide
Open

docs: add ELD code coverage guide#1262
Saharsh Burra (bsaharsh) wants to merge 1 commit into
qualcomm:mainfrom
bsaharsh:code-coverage-guide

Conversation

@bsaharsh

@bsaharsh Saharsh Burra (bsaharsh) commented Jun 10, 2026

Copy link
Copy Markdown

Added a step by step code coverage guide for ELD using llvm-cov. It covers environment setup, build configuration and the full llvm cov pipeline in 5 steps. Finally added the commands to get the final percentages. Updated CMakeLists.txt to use ELD_COVERAGE cmake option to default to llvm cov. Currently the percentages are as below
Line: 82.73%
Function: 78.07%
Region: 79.37%
Branch: 76.39%

Comment thread docs/DeveloperDocs/EldCodeCoverage.md Outdated

Before starting, ensure lcov is available. If not, install it:
- Install on Debian/Ubuntu: `sudo apt-get install lcov`
- genhtml comes bundled with the lcov package.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use llvm-cov instead of relying on lcov package ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to drop the lcov package then we may proceed in two ways:

  1. Using the Gcov-Compatible Mode (llvm-cov gcov): According to the llvm-cov documentation, this subcommand specifically takes a SOURCEFILE as an argument, making it a file-level tool. It lacks a project-wide command (like lcov --directory) to automatically scan and aggregate coverage across the entire build. To obtain project-wide metrics, a custom script would be required to aggregate the individual file results.
  2. Using the Native LLVM Pipeline: The documentation suggests a native pipeline that avoids the gcov format entirely. This approach requires building the project with the -fprofile-instr-generate and -fcoverage-mapping flags. The LLVM_PROFILE_FILE environment variable is used at runtime to produce raw profile data, which is then merged into a .profdata file using llvm-profdata. But this pipeline is not GNU Gcov compatible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer Native LLVM.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the document and CMakeLists.txt, now it uses the LLVM native pipeline.

@bsaharsh Saharsh Burra (bsaharsh) force-pushed the code-coverage-guide branch 4 times, most recently from 1ac14d3 to 300a5fb Compare June 18, 2026 03:35
Comment thread CMakeLists.txt Outdated

option(ELD_LLVM_COV "Build ELD with LLVM source-based coverage instrumentation" OFF)
if(ELD_LLVM_COV)
if(ELD_COVERAGE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just have ELD_COVERAGE and default to llvm cov.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have removed the --coverage entirely and just used the below
option(ELD_COVERAGE "Build ELD with LLVM source-based coverage instrumentation" OFF)
if(ELD_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
endif()

I have run the pipeline, the results are the same. Are there any other changes which you would recommend?

@bsaharsh

Copy link
Copy Markdown
Author

Shankar Easwaran (@quic-seaswara) Please Have a look I have updated the CMakeLists.txt.

Comment thread docs/DeveloperDocs/EldCodeCoverage.md Outdated
```bash
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX=../inst \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the install ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can remove the install, updated.

-DLLVM_EXTERNAL_PROJECTS=eld \
-DLLVM_EXTERNAL_ELD_SOURCE_DIR=${PWD}/llvm-project/eld \
-DLLVM_TARGETS_TO_BUILD='ARM;AArch64;RISCV;Hexagon;X86' \
-DCMAKE_CXX_FLAGS='-stdlib=libc++' \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable symbol versioning, and also enable run tests

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

REGION_COV=$(echo "$TOTAL_LINE" | awk '{print $4}')
FUNC_COV=$(echo "$TOTAL_LINE" | awk '{print $7}')
LINE_COV=$(echo "$TOTAL_LINE" | awk '{print $10}')
BRANCH_COV=$(echo "$TOTAL_LINE" | awk '{print $13}')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llvm-cov report command writes only to stdout — there is no -o flag to save output. So due to this I have saved the report using the COV_SUMMARY , which contains the final summary line so piped it to extract with the awk commands. We can use the export command which emits json output, we make a json file for it. What do you suggest?

- Updated CMakeLists.txt to add ELD_LLVM_COV cmake option
- Updated EldCodeCoverage.md with llvm-cov source-based coverage pipeline

Coverage results using ELD_LLVM_COV=ON on the x86 default test suite:
  Line:     82.73%
  Function: 78.07%
  Region:   79.37%
  Branch:   76.39%

Signed-off-by: bsaharsh <bsaharsh@qti.qualcomm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants