Meta+CMake: Enable coverage for test binaries

This will allow everything defined in headers to be instrumented. As an
example, the function `AK::any_of` isn't instantiated inside AK, that
means that no coverage is reported if we don't consider the
instantiation in the test binary itself.
This commit is contained in:
Lucas Chollet committed 2026-10-14 09:14:25 +02:00
1 parent 05d7ed4e2c
commit 1241e4f0a6
3 files changed
+17 -17

No files matched your search

+16
View File
@@ -261,6 +261,22 @@ elseif("${SERENITY_ARCH}" STREQUAL "x86_64")
add_link_options(LINKER:-z,pack-relative-relocs)
endif()
# Escape hatch target to prevent runtime startup libraries from having coverage enabled
# at awkward points in program initialization
add_library(NoCoverage INTERFACE)
if (ENABLE_USERSPACE_COVERAGE_COLLECTION)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
target_compile_options(NoCoverage INTERFACE -fno-profile-generate -fno-profile-instr-use -fno-profile-instr-generate -fno-coverage-mapping)
target_link_options(NoCoverage INTERFACE -fno-profile-generate -fno-profile-instr-use -fno-profile-instr-generate -fno-coverage-mapping)
else()
message(FATAL_ERROR "ENABLE_USERSPACE_COVERAGE_COLLECTION not supported yet for ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()
add_subdirectory(Userland)
add_subdirectory(Tests)
+1 -1
View File
@@ -35,7 +35,7 @@ echo "[ELEVATED] Making sure profile data files are owned by the current user, t
echo "Discovering all binaries and shared libraries in $BUILD_DIR/Root"
# shellcheck disable=SC2156 # The recommended fix on the Shellcheck github page for this warning causes the script to not find any files at all
all_binaries=$(find "$BUILD_DIR"/Root -type f -executable -exec sh -c "file {} | grep -vi relocatable | grep -Eiq ': elf (32|64)-bit'" \; -printf "-object %p\n" | grep -Ev '(usr\/Tests|usr\/local|boot\/|Loader.so)')
all_binaries=$(find "$BUILD_DIR"/Root -type f -executable -exec sh -c "file {} | grep -vi relocatable | grep -Eiq ': elf (32|64)-bit'" \; -printf "-object %p\n" | grep -Ev '(usr\/local|boot\/|Loader.so)')
CLANG_BINDIR="${SERENITY_ROOT}/Toolchain/Local/clang/bin"
LLVM_PROFDATA="$CLANG_BINDIR/llvm-profdata"
-16
View File
@@ -1,21 +1,5 @@
add_compile_options(-O2)
# Escape hatch target to prevent runtime startup libraries from having coverage enabled
# at awkward points in program initialization
add_library(NoCoverage INTERFACE)
if (ENABLE_USERSPACE_COVERAGE_COLLECTION)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
target_compile_options(NoCoverage INTERFACE -fno-profile-generate -fno-profile-instr-use -fno-profile-instr-generate -fno-coverage-mapping)
target_link_options(NoCoverage INTERFACE -fno-profile-generate -fno-profile-instr-use -fno-profile-instr-generate -fno-coverage-mapping)
else()
message(FATAL_ERROR "ENABLE_USERSPACE_COVERAGE_COLLECTION not supported yet for ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()
add_subdirectory(Applications)
add_subdirectory(Demos)
add_subdirectory(DevTools)