Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): use ENABLE_COVERAGE for coverage, fix segfault #1766

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ option(BUILD_SHARED_LIBS "Build libscap and libsinsp as shared libraries" OFF)
option(ENABLE_VM_TESTS "Enable driver sanity tests" OFF)
option(USE_ASAN "Build with AddressSanitizer" OFF)
option(USE_UBSAN "Build with UndefinedBehaviorSanitizer" OFF)
option(ENABLE_COVERAGE "Build with code coverage" OFF)
option(UBSAN_HALT_ON_ERROR "Halt on error when building with UBSan" ON)

if(${CMAKE_VERSION} VERSION_LESS "3.1.0" AND BUILD_SHARED_LIBS)
Expand Down
9 changes: 5 additions & 4 deletions cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ if(NOT MSVC)
set(FALCOSECURITY_LIBS_COMMON_FLAGS "-Wall -ggdb")
set(FALCOSECURITY_LIBS_DEBUG_FLAGS "-Og -D_DEBUG")
set(FALCOSECURITY_LIBS_RELEASE_FLAGS "-O3 -fno-strict-aliasing -DNDEBUG")
set(FALCOSECURITY_LIBS_COVERAGE_FLAGS "-O0 -fprofile-arcs -ftest-coverage")

if(MINIMAL_BUILD)
set(FALCOSECURITY_LIBS_COMMON_FLAGS "${FALCOSECURITY_LIBS_COMMON_FLAGS} -DMINIMAL_BUILD")
Expand Down Expand Up @@ -68,6 +67,11 @@ if(NOT MSVC)
endif()
endif()

if(ENABLE_COVERAGE)
set(FALCOSECURITY_LIBS_USERSPACE_COMPILE_FLAGS "${FALCOSECURITY_LIBS_USERSPACE_COMPILE_FLAGS};--coverage")
set(FALCOSECURITY_LIBS_USERSPACE_LINK_FLAGS "${FALCOSECURITY_LIBS_USERSPACE_COMPILE_FLAGS};--coverage")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FALCOSECURITY_LIBS_COMMON_FLAGS}")
# we need also `-std=c++17` here beacuse `set(CMAKE_CXX_STANDARD 17)` is not enough to enforce c++17
# with some Cmake versions: https://github.com/falcosecurity/libs/pull/950
Expand All @@ -79,9 +83,6 @@ if(NOT MSVC)
set(CMAKE_C_FLAGS_RELEASE "${FALCOSECURITY_LIBS_RELEASE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${FALCOSECURITY_LIBS_RELEASE_FLAGS}")

set(CMAKE_C_FLAGS_COVERAGE "${FALCOSECURITY_LIBS_COVERAGE_FLAGS}")
set(CMAKE_CXX_FLAGS_COVERAGE "${FALCOSECURITY_LIBS_COVERAGE_FLAGS}")

add_definitions(-D__STDC_FORMAT_MACROS)

else() # MSVC
Expand Down
5 changes: 0 additions & 5 deletions test/libscap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ set(LIBSCAP_TESTS_LIBRARIES
scap
)

# Add `gcov` to needed libraries
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
list(APPEND LIBSCAP_TESTS_LIBRARIES gcov)
endif()

set(LIBSCAP_TESTS_DEPENDENCIES
gtest
scap
Expand Down
6 changes: 0 additions & 6 deletions userspace/libsinsp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ target_link_libraries(unit-test-libsinsp
"${JSONCPP_LIB}"
)

if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
target_link_libraries(unit-test-libsinsp
gcov
)
endif()

# Add some additional include directories associated with `ADDITIONAL_SINSP_TESTS_SUITE`
# `ADDITIONAL_SINSP_TESTS_INCLUDE_FOLDERS` is a list of include paths `;` separated
if(ADDITIONAL_SINSP_TESTS_INCLUDE_FOLDERS)
Expand Down
Loading