diff mbox series

[v1,3/3] xen: debug: gcov: add condition coverage support

Message ID 20250327004044.2014048-4-volodymyr_babchuk@epam.com (mailing list archive)
State Superseded
Headers show
Series Enable MC/DC support for GCOV | expand

Commit Message

Volodymyr Babchuk March 27, 2025, 12:40 a.m. UTC
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.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
---
 xen/Kconfig.debug             | 9 +++++++++
 xen/Rules.mk                  | 3 +++
 xen/common/coverage/gcc_4_7.c | 4 ++++
 3 files changed, 16 insertions(+)

Comments

Jan Beulich March 27, 2025, 8:08 a.m. UTC | #1
On 27.03.2025 01:40, Volodymyr Babchuk wrote:
> --- a/xen/Kconfig.debug
> +++ b/xen/Kconfig.debug
> @@ -44,6 +44,15 @@ config COVERAGE
>  
>  	  If unsure, say N here.
>  
> +config CONDITION_COVERAGE
> +	bool "Condition coverage support"
> +	depends on COVERAGE && !CC_IS_CLANG
> +	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
> --- a/xen/Rules.mk
> +++ b/xen/Rules.mk
> @@ -138,6 +138,9 @@ ifeq ($(CONFIG_CC_IS_CLANG),y)
>      COV_FLAGS := -fprofile-instr-generate -fcoverage-mapping
>  else
>      COV_FLAGS := -fprofile-arcs -ftest-coverage
> +ifeq ($(CONFIG_CONDITION_COVERAGE),y)
> +    COV_FLAGS += -fcondition-coverage
> +endif
>  endif
>  
>  # Reset COV_FLAGS in cases where an objects has another one as prerequisite
> --- a/xen/common/coverage/gcc_4_7.c
> +++ b/xen/common/coverage/gcc_4_7.c
> @@ -43,6 +43,10 @@
>  #define GCOV_UNIT_SIZE 4
>  #endif
>  
> +#if defined(CONFIG_CONDITION_COVERAGE) && (GCC_VERSION < 140100)
> +#error "GCC 14.1 or never is required to generate conditional coverage data"
> +#endif

That's too late as a check. It wants to be in Kconfig (less preferred from my
pov, should at most be influencing the default there) or the latest in the
makefile (see [1]). After all a compiler not supporting the feature will
choke already on -fcondition-coverage, and hence not even get to see this
pre-processor conditional.

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2022-09/msg01793.html
diff mbox series

Patch

diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug
index f7cc5ffaab..7f758d221b 100644
--- a/xen/Kconfig.debug
+++ b/xen/Kconfig.debug
@@ -44,6 +44,15 @@  config COVERAGE
 
 	  If unsure, say N here.
 
+config CONDITION_COVERAGE
+	bool "Condition coverage support"
+	depends on COVERAGE && !CC_IS_CLANG
+	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
diff --git a/xen/Rules.mk b/xen/Rules.mk
index d759cccee3..0a2933cffa 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -138,6 +138,9 @@  ifeq ($(CONFIG_CC_IS_CLANG),y)
     COV_FLAGS := -fprofile-instr-generate -fcoverage-mapping
 else
     COV_FLAGS := -fprofile-arcs -ftest-coverage
+ifeq ($(CONFIG_CONDITION_COVERAGE),y)
+    COV_FLAGS += -fcondition-coverage
+endif
 endif
 
 # Reset COV_FLAGS in cases where an objects has another one as prerequisite
diff --git a/xen/common/coverage/gcc_4_7.c b/xen/common/coverage/gcc_4_7.c
index e3ce69dc2e..d10a16c9a8 100644
--- a/xen/common/coverage/gcc_4_7.c
+++ b/xen/common/coverage/gcc_4_7.c
@@ -43,6 +43,10 @@ 
 #define GCOV_UNIT_SIZE 4
 #endif
 
+#if defined(CONFIG_CONDITION_COVERAGE) && (GCC_VERSION < 140100)
+#error "GCC 14.1 or never is required to generate conditional coverage data"
+#endif
+
 static struct gcov_info *gcov_info_head;
 
 /**