]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen: debug: gcov: add condition coverage support
authorVolodymyr Babchuk <volodymyr_babchuk@epam.com>
Tue, 22 Apr 2025 23:29:23 +0000 (16:29 -0700)
committerStefano Stabellini <stefano.stabellini@amd.com>
Tue, 22 Apr 2025 23:29:23 +0000 (16:29 -0700)
Condition coverage, also known as MC/DC (modified condition/decision
coverage) is a coverage metric that tracks separate outcomes in
boolean expressions.

This patch adds CONFIG_CONDITION_COVERAGE option to enable MC/DC for
GCC. Clang is not supported right now because Xen can't emit version
10 of LLVM profile data, where MC/DC support was added.

Also, use the opportunity to convert COV_FLAGS to cov-cflags-y, which
reduces amount of ifeqs in Rules.mk. Otherwise this patch had to add
another nesting level with "ifeq ($(CONFIG_CONDITION_COVERAGE),y)".

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/Kconfig
xen/Kconfig.debug
xen/Rules.mk

index 486b36b843a85edb0a543537136596336cd7989a..1b24e8f3c0cddc8acfa609d14de97ba73a96c462 100644 (file)
@@ -47,6 +47,10 @@ config CC_HAS_ASM_GOTO_OUTPUT
        depends on !GCC_ASM_GOTO_OUTPUT_BROKEN
        depends on $(success,echo 'int foo(int x) { asm goto ("": "=r"(x) ::: bar); return x; bar: return 0; }' | $(CC) -x c - -c -o /dev/null)
 
+# Compiler supports -fcondition-coverage aka MC/DC
+config CC_HAS_MCDC
+       def_bool $(cc-option,-fcondition-coverage)
+
 # Set code alignment.
 #
 # Allow setting on a boolean basis, and then convert such selection to an
index c4a8d86912e09b1038deba982048dcd954eda74e..d14093017e21c7b7a5f318e30f41054cf42c6ff8 100644 (file)
@@ -44,6 +44,15 @@ config COVERAGE
 
          If unsure, say N here.
 
+config CONDITION_COVERAGE
+       bool "Condition coverage support"
+       depends on COVERAGE && CC_HAS_MCDC
+       help
+         Enable condition coverage support. Used for collecting MC/DC
+         (Modified Condition/Decision Coverage) metrics.
+
+         If unsure, say N here.
+
 config DEBUG_LOCK_PROFILE
        bool "Lock Profiling"
        select DEBUG_LOCKS
index d759cccee3716b60787762e656d56d846b72b5a6..da21850926d38308cda94c8451939fa8d2a35c81 100644 (file)
@@ -29,6 +29,7 @@ targets :=
 subdir-y :=
 CFLAGS-y :=
 AFLAGS-y :=
+cov-cflags-y :=
 nocov-y :=
 noubsan-y :=
 
@@ -133,19 +134,18 @@ $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS
 
 non-init-objects = $(filter-out %.init.o, $(obj-y) $(obj-bin-y) $(extra-y))
 
-ifeq ($(CONFIG_COVERAGE),y)
 ifeq ($(CONFIG_CC_IS_CLANG),y)
-    COV_FLAGS := -fprofile-instr-generate -fcoverage-mapping
+    cov-cflags-$(CONFIG_COVERAGE) := -fprofile-instr-generate -fcoverage-mapping
 else
-    COV_FLAGS := -fprofile-arcs -ftest-coverage
+    cov-cflags-$(CONFIG_COVERAGE) := -fprofile-arcs -ftest-coverage
+    cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcondition-coverage
 endif
 
-# Reset COV_FLAGS in cases where an objects has another one as prerequisite
+# Reset cov-cflags-y in cases where an objects has another one as prerequisite
 $(nocov-y) $(filter %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)): \
-    COV_FLAGS :=
+    cov-cflags-y :=
 
-$(non-init-objects): _c_flags += $(COV_FLAGS)
-endif
+$(non-init-objects): _c_flags += $(cov-cflags-y)
 
 ifeq ($(CONFIG_UBSAN),y)
 # Any -fno-sanitize= options need to come after any -fsanitize= options