Skip to content

Commit

Permalink
cmake: introduce a target coverage-reset
Browse files Browse the repository at this point in the history
The path introduce a CMake target `coverage-reset` that resets code
coverage counters:

```
$ make coverage-report
Building coverage report
(INFO) - MainThread - Reading coverage data...
(INFO) - MainThread - Writing coverage report...
lines: 53.2% (5949 out of 11177)
functions: 60.0% (631 out of 1051)
branches: 36.2% (3300 out of 9106)
decisions: 47.6% (1486 out of 3119)
Built target coverage-report

$ make coverage-reset
[100%] Reset code coverage counters
[100%] Built target coverage-reset

$ make coverage-report
Building coverage report
(INFO) - MainThread - Reading coverage data...
(INFO) - MainThread - Writing coverage report...
lines: 0.0% (0 out of 11177)
functions: 0.0% (0 out of 1051)
branches: 0.0% (0 out of 9106)
decisions: 0.0% (0 out of 3119)
Built target coverage-report
$
```

Note, files 'src/host/*.gcda' generated in LuaJIT directory are not
removed, because CMake cannot remove recursively by globbing.
Files 'src/host/*.gcda' are not used for building coverage report,
so it is ok.
  • Loading branch information
ligurio committed Dec 29, 2023
1 parent a0c23ab commit 6301a2c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,20 @@ add_custom_command(TARGET ${target_name}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)

# The .gcda count data file is generated when a program containing
# object files built with the GCC -fprofile-arcs option is executed.
# https://gcc.gnu.org/onlinedocs/gcc/Gcov-Data-Files.html
set(GCDA_FILES "${LUA_SOURCE_DIR}/*.gcda")
if(USE_LUAJIT)
# Files 'src/host/*.gcda' are not removed, because
# CMake cannot remove recursively by globbing.
# Files 'src/host/*.gcda' are not used for building coverage report.
set(GCDA_FILES "${LUA_SOURCE_DIR}/src/*.gcda")
endif(USE_LUAJIT)
add_custom_target(coverage-reset
COMMENT "Reset code coverage counters"
COMMAND ${CMAKE_COMMAND} -E rm -f ${GCDA_FILES}
)

message(STATUS "Code coverage HTML report: ${COVERAGE_HTML_REPORT}")
message(STATUS "Code coverage XML report: ${COVERAGE_XML_REPORT}")

0 comments on commit 6301a2c

Please sign in to comment.