File tree Expand file tree Collapse file tree 3 files changed +62
-6
lines changed Expand file tree Collapse file tree 3 files changed +62
-6
lines changed Original file line number Diff line number Diff line change @@ -88,25 +88,37 @@ jobs:
8888
8989 test-linux :
9090 runs-on : ubuntu-latest
91- needs : build-linux-amd64
9291 steps :
9392 - name : Checkout code
9493 uses : actions/checkout@v6
9594
9695 - name : Set up CMake
9796 uses : jwlawson/actions-setup-cmake@v2
9897
99- - name : Download build artifacts
100- uses : actions/download-artifact@v6
101- with :
102- name : build-PC-artifacts
98+ - name : Build PC (Linux) for coverage
99+ run : |
100+ cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DENABLE_COVERAGE=ON
101+ cmake --build ${{github.workspace}}/build
103102
104103 - name : Run tests for PC
105104 run : |
106- tar -xvf build-pc.tar
107105 cd build
108106 ctest
109107
108+ - name : Generate coverage report
109+ run : |
110+ sudo apt-get update
111+ sudo apt-get install -y lcov
112+ lcov --capture --directory ${{github.workspace}}/build --output-file ${{github.workspace}}/build/coverage.info
113+ lcov --remove ${{github.workspace}}/build/coverage.info '/usr/*' --output-file ${{github.workspace}}/build/coverage.info
114+ lcov --list ${{github.workspace}}/build/coverage.info
115+
116+ - name : Upload coverage report
117+ uses : actions/upload-artifact@v5
118+ with :
119+ name : coverage-report
120+ path : ${{github.workspace}}/build/coverage.info
121+
110122 - name : Upload test results
111123 uses : actions/upload-artifact@v5
112124 with :
Original file line number Diff line number Diff line change @@ -68,6 +68,8 @@ option(OAPV_BUILD_APPS "Build the included command line apps" ON)
6868option (OAPV_BUILD_STATIC_LIB "Build oapv static library" ON )
6969option (OAPV_BUILD_SHARED_LIB "Build oapv shared library" ON )
7070
71+ option (ENABLE_COVERAGE "Enable code coverage measurement" OFF )
72+
7173if (OAPV_BUILD_APPS AND OAPV_APP_STATIC_BUILD AND NOT OAPV_BUILD_STATIC_LIB)
7274 message (FATAL_ERROR "Cannot build static apps without static lib." )
7375endif ()
@@ -104,6 +106,9 @@ endif()
104106if (MSVC )
105107 message ("Not supported yet!" )
106108elseif (UNIX OR MINGW)
109+ if (ENABLE_COVERAGE)
110+ set (CMAKE_BUILD_TYPE "Debug" )
111+ endif ()
107112 if (NOT CMAKE_BUILD_TYPE )
108113 set (CMAKE_BUILD_TYPE "Release" )
109114 endif ()
@@ -120,6 +125,11 @@ elseif(UNIX OR MINGW)
120125 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_DBG} -${OPT_LV} -fomit-frame-pointer -pthread -std=c99" )
121126 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-function -Wno-pointer-sign -Wno-pointer-to-int-cast" )
122127 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lm" )
128+
129+ if (ENABLE_COVERAGE)
130+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
131+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage" )
132+ endif ()
123133else ()
124134 message ("Unknown compiler" )
125135endif ()
Original file line number Diff line number Diff line change @@ -132,6 +132,40 @@ Pattern file of APV bitstream for [ImHex](https://github.com/WerWolv/ImHex) is p
132132
133133In build directory run `` ctest ``
134134
135+ ## Code Coverage
136+
137+ To generate a code coverage report manually:
138+
139+ 1 . ** ` lcov ` is required.**
140+
141+ 2 . ** Build and Test with Coverage:**
142+ ``` bash
143+ # Create build directory and configure with coverage enabled
144+ cmake -S . -B build -DENABLE_COVERAGE=ON
145+
146+ # Build the project
147+ cmake --build build
148+
149+ # Run tests to generate coverage data
150+ cd build && ctest && cd ..
151+ ```
152+
153+ 3. ** Generate HTML Report:**
154+ ` ` ` bash
155+ # Capture coverage data
156+ lcov --capture --directory build --output-file build/coverage.info
157+
158+ # Remove coverage for external files (optional)
159+ lcov --remove build/coverage.info ' /usr/*' --output-file build/coverage.info
160+
161+ # Generate the HTML report
162+ mkdir -p coverage_report
163+ genhtml build/coverage.info --output-directory coverage_report
164+ ` ` `
165+
166+ 4. ** View Report:**
167+ Open ` coverage_report/index.html` in your web browser.
168+
135169# # Packaging
136170
137171For generating package ready for distribution (default deb) execute in build directory ` ` cpack` ` , or other formats (tgz, zip etc.) ` ` cpack -G TGZ` ` .
You can’t perform that action at this time.
0 commit comments