Skip to content

Commit 4e7aa00

Browse files
mxHuberfabianbs96
andauthored
added test coverage for ci (#792)
* added test coverage for ci * merged coverage job into build, removed all but one step for testing * test code for meeting * Call-Graph Improvements (#785) * minor fix in CHA and RTA resolvers * Several small improvements for call-graph resolving * Fix out-of-bounds access in getVarTypeFromIR() * Add address-taken functions caching in base resolver * Some cleanup in resolvers * pre-commit * Fix bug in the overloads of buildLLVMBasedCallGraph() that takes a CallGraphAnalysisType * Dbg-Info based Type Matching (#791) * moved stripPointerTypes() + debug prints * MetadataKind approach * I think we don't get around using getName() * unittests still fail * bugfix + cleanup * Some cleanup * Implement allocated-types collection in terms of debug info * Fix libdeps * Remove some unneeded includes --------- Co-authored-by: Fabian Schiebel <[email protected]> Co-authored-by: Fabian Schiebel <[email protected]> * Some fixes in the IterativeIDESolver (#782) * Fix the IterativeIDESolver by allowing to analyze problems that override extend() and combine() * Use the logger in the IterativeIDESolver * Make it possible to solve the IDEFeatureTaintAnalysis with the IterativeIDESolver * Fix errors introduced by merge * Bump dependencies (#784) * Remove boost from BitVectorSet (#788) * Remove boost from BitVectorSet * Minor deboostifying * Apply review comment on Bit-index-inbounds check + simplify operator<< * GCC Compatibility (#787) * Make phasar compile with gcc (g++-11) and uncover (and fix) two bugs related to json ser/de with LLVMAliasSet and LLVMBasedICFG that were not detected untio now, because of nlohmann's implicit conversions feature * Address review comments * Simplify isLLVMZeroValue according to the discussion in #787 * backup for rebase * cmake works, g++ fails * working version (with local hacks -20) * added regex for filter, it is not working * fixed filtering + cleanup * basic ci impl, lib coverage, fixed release cmake error * added cmake-scripts to submodule index * set llvm-cov before code-cov script * fixed version of llvm-cov * testing v19 due to ci issues * testing cov only when in debug build type * fixed all build type checks * added -v to see invocation of error in ci * only run coverage when matrix.build is Debug * Debug code + potential bug found? * only run cov when PHASAR_DEBUG_LIBDEPS is off * removed debug code, added messages for cov paths * testing llvm cov 19 * hardcoded llvm-19 for cov * adding llvm-19 as dependency for cov tools * disabling asan for release for now * removed unneccesary char * development merge + json external * Is the sanitizer the problem? * fixed cmake failing when in debug w/o -DCODE_COVERAGE=ON * added coverage report artifact uploading * fixed ci * fixed filtering not working correctly on runner * docker sanitizer back ON + new matrix entry DebugCov * Docker sanitizer still fails, disabling for now * Removed coverage of unittests * cleanup * Some cleanup * Add demangling to cov report * artifact should be entire all-merged/ folder * external diff * removed rename of index.html * Revert json downgrade --------- Co-authored-by: Fabian Schiebel <[email protected]> Co-authored-by: Fabian Schiebel <[email protected]> Co-authored-by: Fabian Schiebel <[email protected]>
1 parent 153083a commit 4e7aa00

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
matrix:
1717
os: [ubuntu-24.04, ubuntu-24.04-arm]
1818
compiler: [ [clang++-19, clang-19, "clang-19 libclang-rt-19-dev"] ]
19-
build: [ Debug, Release, DebugLibdeps ]
19+
build: [ Debug, Release, DebugLibdeps, DebugCov ]
2020
include:
2121
- build: Debug
2222
cmake_build_type: Debug
@@ -27,11 +27,17 @@ jobs:
2727
- build: DebugLibdeps
2828
cmake_build_type: Debug
2929
flags: -DPHASAR_DEBUG_LIBDEPS=ON -DBUILD_SHARED_LIBS=ON
30+
- build: DebugCov
31+
cmake_build_type: Debug
32+
flags: -DCODE_COVERAGE=ON
33+
extra_dependencies: llvm-19 # For coverage
3034
exclude:
3135
- os: ubuntu-24.04-arm
3236
build: Debug
3337
- os: ubuntu-24.04-arm
3438
build: DebugLibdeps
39+
- os: ubuntu-24.04-arm
40+
build: DebugCov
3541

3642
continue-on-error: false
3743
steps:
@@ -44,7 +50,7 @@ jobs:
4450
- name: Install Phasar Dependencies
4551
shell: bash
4652
run: |
47-
./utils/InstallAptDependencies.sh --noninteractive tzdata ${{ matrix.compiler[2] }}
53+
./utils/InstallAptDependencies.sh --noninteractive tzdata ${{ matrix.compiler[2] }} ${{ matrix.extra_dependencies }}
4854
4955
- name: Building Phasar in ${{ matrix.build }} with ${{ matrix.compiler[0] }}
5056
env:
@@ -77,3 +83,18 @@ jobs:
7783
cd ./examples/how-to
7884
cmake -S . -B build -Dphasar_ROOT="$PHASAR_ROOT_DIR/INSTALL"
7985
cmake --build ./build --target run_sample_programs
86+
87+
- name: Check test coverage and generate HTML report
88+
if: matrix.build == 'DebugCov'
89+
shell: bash
90+
run: |
91+
cmake --build ./build --target ccov-all
92+
93+
- name: Upload coverage HTML report artifact
94+
if: matrix.build == 'DebugCov'
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: CoverageReport
98+
path: ./build/ccov/all-merged/
99+
if-no-files-found: error
100+
retention-days: 7

CMakeLists.txt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,43 @@ find_package(Threads)
268268
set(CMAKE_CXX_CLANG_TIDY "")
269269

270270
# Nlohmann JSON
271-
272271
include(add_nlohmann_json)
273272
add_nlohmann_json()
274273
add_json_schema_validator()
275274

275+
# Coverage
276+
if (CODE_COVERAGE)
277+
set(CODE_COVERAGE_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/code-coverage.cmake")
278+
file(DOWNLOAD "https://raw.githubusercontent.com/StableCoder/cmake-scripts/refs/tags/25.08/code-coverage.cmake" "${CODE_COVERAGE_SCRIPT}"
279+
EXPECTED_HASH SHA256=cad4dd2bdf944f77627687e0298debc8341bfdeffaf949937f319c7c4ff3fdaf
280+
TLS_VERIFY ON
281+
STATUS CODE_COVERAGE_SCRIPT_DOWNLOAD_STATUS
282+
)
283+
message(STATUS "Download code-coverage.cmake: ${CODE_COVERAGE_SCRIPT_DOWNLOAD_STATUS}")
284+
285+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
286+
string(REGEX MATCH "^[0-9]+" COMPILER_VERSION_MAJOR "${CMAKE_CXX_COMPILER_VERSION}")
287+
message(STATUS "Clang major version: ${COMPILER_VERSION_MAJOR}")
288+
set(LLVM_TOOL_VERSION_SUFFIX "-${COMPILER_VERSION_MAJOR}")
289+
endif()
290+
291+
# pre-populate these cmake variables as we require specific versions:
292+
find_program(LLVM_COV_PATH "llvm-cov${LLVM_TOOL_VERSION_SUFFIX}" REQUIRED)
293+
find_program(LLVM_PROFDATA_PATH "llvm-profdata${LLVM_TOOL_VERSION_SUFFIX}" REQUIRED)
294+
message(STATUS "Found llvm-cov: ${LLVM_COV_PATH}")
295+
message(STATUS "Found llvm-profdata: ${LLVM_PROFDATA_PATH}")
296+
297+
include("${CODE_COVERAGE_SCRIPT}")
298+
299+
find_program(cxxfilt "c++filt" QUIET)
300+
if (cxxfilt)
301+
set(DEMANGLER_OPTIONS LLVM_COV_HTML_OPTIONS "-Xdemangler=${cxxfilt}")
302+
endif()
303+
304+
set(COV_FILEPATH_FILTER "(usr/*|external/|unittests/)")
305+
add_code_coverage_all_targets(EXCLUDE ${COV_FILEPATH_FILTER} ${DEMANGLER_OPTIONS})
306+
endif()
307+
276308
# Googletest
277309
if (NOT PHASAR_IN_TREE)
278310
if(PHASAR_BUILD_UNITTESTS AND NOT TARGET gtest)

bootstrap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fi
9797
tmp_dir=$(mktemp -d "llvm-build.XXXXXXXX" --tmpdir)
9898
./utils/install-llvm.sh "${NUM_THREADS}" "${tmp_dir}" "${LLVM_INSTALL_DIR}" ${LLVM_RELEASE}
9999
rm -rf "${tmp_dir}"
100+
100101
echo "dependencies successfully installed"
101102

102103
# *Always* set the LLVM root to ensure the Phasar script uses the proper toolchain

cmake/phasar_macros.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ function(add_phasar_unittest test_name)
3535
)
3636
set_tests_properties("${test}" PROPERTIES LABELS "all")
3737
set(CTEST_OUTPUT_ON_FAILURE ON)
38+
39+
if (CODE_COVERAGE)
40+
target_code_coverage(${test} AUTO ALL)
41+
endif()
3842
endfunction()
3943

4044
function(validate_binary_version result item)
@@ -351,6 +355,10 @@ function(add_phasar_library name)
351355
endif()
352356

353357
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
358+
359+
if (CODE_COVERAGE)
360+
target_code_coverage(${name} AUTO ALL)
361+
endif()
354362
endfunction(add_phasar_library)
355363

356364
macro(subdirlist result curdir)

0 commit comments

Comments
 (0)