docs: add ELD code coverage guide#1262
Conversation
|
|
||
| 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. |
There was a problem hiding this comment.
Can we use llvm-cov instead of relying on lcov package ?
There was a problem hiding this comment.
If we want to drop the lcov package then we may proceed in two ways:
- 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.
- 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.
There was a problem hiding this comment.
Prefer Native LLVM.
There was a problem hiding this comment.
I have updated the document and CMakeLists.txt, now it uses the LLVM native pipeline.
1ac14d3 to
300a5fb
Compare
|
|
||
| option(ELD_LLVM_COV "Build ELD with LLVM source-based coverage instrumentation" OFF) | ||
| if(ELD_LLVM_COV) | ||
| if(ELD_COVERAGE) |
There was a problem hiding this comment.
Can we just have ELD_COVERAGE and default to llvm cov.
There was a problem hiding this comment.
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?
300a5fb to
feb48ca
Compare
|
Shankar Easwaran (@quic-seaswara) Please Have a look I have updated the CMakeLists.txt. |
| ```bash | ||
| cmake -G Ninja \ | ||
| -DCMAKE_BUILD_TYPE=Debug \ | ||
| -DCMAKE_INSTALL_PREFIX=../inst \ |
There was a problem hiding this comment.
Can we remove the install ?
There was a problem hiding this comment.
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++' \ |
There was a problem hiding this comment.
enable symbol versioning, and also enable run tests
| 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}') |
There was a problem hiding this comment.
Why this ?
There was a problem hiding this comment.
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?
feb48ca to
0c71f95
Compare
- 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>
0c71f95 to
15d5fd7
Compare
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%