feat: Add LCOV coverage support for Jenkins CI
- Add ENABLE_COVERAGE CMake option with gcov flags - Create collect-coverage.sh script for LCOV workflow - Add Qt6 test files with QTest framework - Update Jenkinsfile with Coverage stage (main/master/coverage.*) - Update CI Docker image with lcov and genhtml packages - Add .gitignore entries for coverage artifacts - Add COVERAGE.md documentation Coverage workflow: 1. Configure with -DENABLE_COVERAGE=ON 2. Build and run tests to generate .gcda/.gcno files 3. Collect coverage with lcov 4. Filter out Qt/system libraries 5. Generate HTML report and lcov.info for Jenkins Jenkins publishes coverage/lcov.info using Coverage Plugin. Coverage stage only runs on protected branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Entire-Checkpoint: 7783c7698334
This commit is contained in:
1 parent
9e3c6eef2e
commit
8ef6529c0c
19 files changed
+733
-235
No files matched your search
@@ -10,6 +10,9 @@ set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
# Coverage option - disabled by default
|
||||
option(ENABLE_COVERAGE "Enable code coverage with gcov/lcov" OFF)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
@@ -28,13 +31,66 @@ target_link_libraries(Qt6MigratedBenchmark PRIVATE
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
target_compile_features(Qt6MigratedBenchmark PRIVATE cxx_std_23)
|
||||
|
||||
# Enable warnings
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(Qt6MigratedBenchmark PRIVATE -Wall -Wextra -pedantic)
|
||||
# Coverage configuration
|
||||
if(ENABLE_COVERAGE)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
message(STATUS "Coverage enabled for ${CMAKE_CXX_COMPILER_ID}")
|
||||
|
||||
# Add coverage flags
|
||||
target_compile_options(Qt6MigratedBenchmark PRIVATE
|
||||
-g
|
||||
-O0
|
||||
--coverage
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
|
||||
target_link_options(Qt6MigratedBenchmark PRIVATE
|
||||
--coverage
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
else()
|
||||
message(WARNING "Coverage is only supported with GCC or Clang")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Add tests
|
||||
# Enable testing
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
|
||||
# Add test executable
|
||||
add_executable(Qt6MigratedBenchmarkTest
|
||||
tests/test_main.cpp
|
||||
tests/test_mainwindow.cpp
|
||||
MainWindow.h
|
||||
MainWindow.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(Qt6MigratedBenchmarkTest PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
Qt6::Test
|
||||
)
|
||||
|
||||
# Apply same coverage flags to test target
|
||||
if(ENABLE_COVERAGE)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(Qt6MigratedBenchmarkTest PRIVATE
|
||||
-g
|
||||
-O0
|
||||
--coverage
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
|
||||
target_link_options(Qt6MigratedBenchmarkTest PRIVATE
|
||||
--coverage
|
||||
-fprofile-arcs
|
||||
-ftest-coverage
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Register tests with CTest
|
||||
add_test(NAME Qt6MigratedBenchmarkTest COMMAND Qt6MigratedBenchmarkTest)
|
||||
Reference in new issue
Block a user