Skip to content

Commit

Permalink
cmake/toolchain: Support LLVM source profiling/coverage for native bo…
Browse files Browse the repository at this point in the history
…ards

Add a a new source coverage for native builds
and new kconfig choice of COVERAGE mode to select which:
* COVERAGE_NATIVE_GCOV: what we had until now with native builds
* COVERAGE_NATIVE_SOURCE: a new LLVM source coverage mode
* COVERAGE_GCOV: the old COVERAGE_GCOV (embedded gcov data generation).

Signed-off-by: Alberto Escolar Piedras <[email protected]>
  • Loading branch information
aescolar authored and carlescufi committed Aug 28, 2023
1 parent d8d5bdf commit fd27bed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmake/compiler/clang/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ set_compiler_property(PROPERTY no_printf_return_value)
check_set_compiler_property(PROPERTY hosted)

# clang flags for coverage generation
set_property(TARGET compiler PROPERTY coverage --coverage -fno-inline)
if (CONFIG_COVERAGE_NATIVE_SOURCE)
set_compiler_property(PROPERTY coverage -fprofile-instr-generate -fcoverage-mapping)
else()
set_compiler_property(PROPERTY coverage --coverage -fno-inline)
endif()

# clang flag for colourful diagnostic messages
set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics)
Expand Down
4 changes: 3 additions & 1 deletion cmake/linker/ld/clang/linker_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# The coverage linker flag is specific for clang.
if (NOT CONFIG_COVERAGE_GCOV)
if (CONFIG_COVERAGE_NATIVE_GCOV)
set_property(TARGET linker PROPERTY coverage --coverage)
elseif(CONFIG_COVERAGE_NATIVE_SOURCE)
set_property(TARGET linker PROPERTY coverage -fprofile-instr-generate -fcoverage-mapping)
endif()

# Extra warnings options for twister run
Expand Down
25 changes: 23 additions & 2 deletions subsys/testsuite/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,38 @@ config COVERAGE
For more information see
https://docs.zephyrproject.org/latest/guides/coverage.html

choice
prompt "Coverage mode"
default COVERAGE_NATIVE_GCOV if NATIVE_BUILD
default COVERAGE_GCOV if !NATIVE_BUILD
depends on COVERAGE

config COVERAGE_NATIVE_GCOV
bool "Host compiler gcov based code coverage"
depends on NATIVE_BUILD
help
Build natively with the compiler standard `--coverage` options,
that is with gcov/GCC-compatible coverage

config COVERAGE_NATIVE_SOURCE
bool "Host compiler source based code coverage"
depends on NATIVE_BUILD
depends on "${ZEPHYR_TOOLCHAIN_VARIANT}" = "llvm"
help
Build natively with the compiler source based coverage options.
Today this is only supported with LLVM

config COVERAGE_GCOV
bool "Create Coverage data from hardware platform"
default y
depends on COVERAGE
depends on !NATIVE_BUILD
help
This option will select the custom gcov library. The reports will
be available over serial. This serial dump can be passed to
gen_gcov_files.py which creates the required .gcda files. These
can be read by gcov utility. For more details see gcovr.com .

endchoice

config COVERAGE_GCOV_HEAP_SIZE
int "Size of heap allocated for gcov coverage data dump"
default 32768 if X86 || SOC_SERIES_MPS2
Expand Down

0 comments on commit fd27bed

Please sign in to comment.