Skip to content

Commit

Permalink
arch: adjust gcov configuration name
Browse files Browse the repository at this point in the history
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
  • Loading branch information
Gary-Hobson authored and xiaoxiang781216 committed Oct 9, 2024
1 parent 8fe6c0e commit 034af29
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 61 deletions.
19 changes: 0 additions & 19 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -311,25 +311,6 @@ config ARCH_SIZET_LONG
C++ library routines because the NuttX size_t might not have
the same underlying type as your toolchain's size_t.

config ARCH_COVERAGE
bool "Enable code coverage analysis"
select HAVE_CXXINITIALIZE
default n
---help---
Generate code coverage

config ARCH_COVERAGE_ALL
bool "Enable code coverage for the entire image"
depends on ARCH_COVERAGE
default n
---help---
This option activates code coverage instrumentation for the
entire image. If you don't enable this option, you have to
explicitly specify "-fprofile-generate -ftest-coverage" for
the files/directories you want to check. Enabling this option
will get image size increased and performance decreased
significantly.

config ARCH_INSTRUMENT_ALL
bool "Instrument All"
default n
Expand Down
6 changes: 1 addition & 5 deletions arch/arm/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0)
ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING)
endif

ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
endif

ifeq ($(CONFIG_MM_UBSAN_ALL),y)
ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
endif
Expand Down Expand Up @@ -491,7 +487,7 @@ ifeq ($(CONFIG_LIBSUPCXX),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
endif

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
endif

Expand Down
6 changes: 1 addition & 5 deletions arch/arm64/src/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ ifeq ($(CONFIG_STACK_CANARIES),y)
ARCHOPTIMIZATION += -fstack-protector-all
endif

ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
endif

ifeq ($(CONFIG_MM_UBSAN_ALL),y)
ARCHOPTIMIZATION += $(CONFIG_MM_UBSAN_OPTION)
endif
Expand Down Expand Up @@ -196,7 +192,7 @@ ifeq ($(CONFIG_LIBSUPCXX),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
endif

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
endif

Expand Down
4 changes: 0 additions & 4 deletions arch/arm64/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ if(CONFIG_STACK_CANARIES)
add_compile_options(-fstack-protector-all)
endif()

if(CONFIG_ARCH_COVERAGE_ALL)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

if(CONFIG_MM_UBSAN_ALL)
add_compile_options(${CONFIG_MM_UBSAN_OPTION})
endif()
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/cmake/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if(CONFIG_LIBSUPCXX)
OUTPUT_VARIABLE extra_library)
list(APPEND EXTRA_LIB ${extra_library})
endif()
if(CONFIG_ARCH_COVERAGE)
if(CONFIG_SCHED_GCOV)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=libgcov.a
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ if(${CONFIG_STACK_USAGE_WARNING})
endif()
endif()

if(CONFIG_ARCH_COVERAGE)
if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/cmake/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if(CONFIG_LIBSUPCXX)
list(APPEND EXTRA_LIB ${extra_library})
endif()

if(CONFIG_ARCH_COVERAGE)
if(CONFIG_SCHED_GCOV)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=libgcov.a
Expand Down
6 changes: 1 addition & 5 deletions arch/risc-v/src/common/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0)
ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING)
endif

ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
endif

ARCHCFLAGS += -fno-common
ARCHCXXFLAGS += -fno-common

Expand Down Expand Up @@ -400,7 +396,7 @@ ifeq ($(CONFIG_LIBSUPCXX),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
endif

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
endif

Expand Down
8 changes: 8 additions & 0 deletions arch/sim/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ config SIM_UBSAN_DUMMY
---help---
Keep SIM_UBSAN compile time but disable runtime actions.

config SIM_GCOV_ALL
bool "Enable code coverage for the entire image"
depends on COVERAGE
default n
---help---
This option activates code coverage instrumentation for the
entire image.

choice
prompt "X64_64 ABI"
default SIM_X8664_SYSTEMV if HOST_LINUX
Expand Down
2 changes: 1 addition & 1 deletion arch/sim/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ ifeq ($(CONFIG_LIBM_TOOLCHAIN),y)
STDLIBS += -lm
endif

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
STDLIBS += -lgcov
endif

Expand Down
2 changes: 1 addition & 1 deletion arch/sim/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if(CONFIG_STACK_USAGE_WARNING)
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
endif()

if(CONFIG_SIM_GCOV_ALL)
if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/sim/src/sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(HOSTSRCS)
set(HOST_INCLUDE_DIRS)
set(STDLIBS pthread)

if(CONFIG_ARCH_COVERAGE)
if(CONFIG_SCHED_GCOV)
list(APPEND STDLIBS gcov)
endif()

Expand Down
4 changes: 2 additions & 2 deletions arch/sim/src/sim/posix/sim_hostmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* Public Function Prototypes
****************************************************************************/

#ifdef CONFIG_ARCH_COVERAGE
#ifdef CONFIG_SCHED_GCOV
void __gcov_dump(void);
#endif

Expand All @@ -72,7 +72,7 @@ extern int backtrace(void **array, int size);

void host_abort(int status)
{
#ifdef CONFIG_ARCH_COVERAGE
#ifdef CONFIG_SCHED_GCOV
/* Dump gcov data. */

host_uninterruptible_no_return(__gcov_dump);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86_64/src/cmake/Toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if(${CONFIG_STACK_USAGE_WARNING})
endif()
endif()

if(CONFIG_ARCH_COVERAGE)
if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()

Expand Down
2 changes: 1 addition & 1 deletion arch/x86_64/src/cmake/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if(CONFIG_LIBSUPCXX)
list(APPEND EXTRA_LIB ${extra_library})
endif()

if(CONFIG_ARCH_COVERAGE)
if(CONFIG_SCHED_GCOV)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=libgcov.a
Expand Down
6 changes: 1 addition & 5 deletions arch/xtensa/src/lx6/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0)
ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING)
endif

ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
endif

# Instrumentation options

ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y)
Expand Down Expand Up @@ -195,7 +191,7 @@ ifeq ($(CONFIG_LIBSUPCXX),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
endif

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
endif

Expand Down
6 changes: 1 addition & 5 deletions arch/xtensa/src/lx7/Toolchain.defs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0)
ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING)
endif

ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
endif

# Instrumentation options

ifeq ($(CONFIG_ARCH_INSTRUMENT_ALL),y)
Expand Down Expand Up @@ -199,7 +195,7 @@ ifeq ($(CONFIG_LIBSUPCXX),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libsupc++.a))
endif

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
EXTRA_LIBS += $(wildcard $(shell $(CC) $(ARCHCPUFLAGS) --print-file-name=libgcov.a))
endif

Expand Down
2 changes: 1 addition & 1 deletion boards/sim/sim/sim/configs/kasan/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_CHIP="sim"
CONFIG_ARCH_COVERAGE=y
CONFIG_ARCH_SIM=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BUILTIN=y
Expand Down Expand Up @@ -39,6 +38,7 @@ CONFIG_PTHREAD_MUTEX_TYPES=y
CONFIG_PTHREAD_MUTEX_UNSAFE=y
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_RR_INTERVAL=10
CONFIG_SCHED_GCOV=y
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
Expand Down
2 changes: 1 addition & 1 deletion boards/sim/sim/sim/scripts/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ifneq ($(CONFIG_STACK_USAGE_WARNING),0)
ARCHOPTIMIZATION += -Wstack-usage=$(CONFIG_STACK_USAGE_WARNING)
endif

ifeq ($(CONFIG_ARCH_COVERAGE_ALL),y)
ifeq ($(CONFIG_SIM_GCOV_ALL),y)
ARCHOPTIMIZATION += -fprofile-generate -ftest-coverage
endif

Expand Down
12 changes: 12 additions & 0 deletions sched/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,18 @@ config SCHED_STACK_RECORD
to disable.Through instrumentation, record the backtrace at
the deepest point in the stack.

config SCHED_GCOV
bool "Enable GCOV support"
select HAVE_CXXINITIALIZE
default n
---help---
Enable GCOV support for code coverage analysis.
After turning on this option, code coverage can be analyzed.
If this option is enabled, image size and performance will be
significantly reduced. Before use, you need to add the
"-fprofile-generate -ftest-coverage" compilation parameters
to the file to be analyzed.

endmenu

menu "Files and I/O"
Expand Down
2 changes: 1 addition & 1 deletion tools/Config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ endef

# CLEAN - Default clean target

ifeq ($(CONFIG_ARCH_COVERAGE),y)
ifeq ($(CONFIG_SCHED_GCOV),y)
EXTRA = *.gcno *.gcda
endif

Expand Down

0 comments on commit 034af29

Please sign in to comment.