aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJørgen Kvalsvik <j@lambda.is>2024-06-21 20:28:01 +0200
committerJørgen Kvalsvik <j@lambda.is>2024-06-26 12:18:47 +0200
commit229bf66f8d5d6df2997cee37575241cae944e4a6 (patch)
treecd650aa7cd290cf199f6694c5cfa802f8150e5b3
parent19f630e6ae8da7159a8c82f337b699245f66e6a6 (diff)
Add section on MC/DC in gcov manual
gcc/ChangeLog: * doc/gcov.texi: Add MC/DC section.
-rw-r--r--gcc/doc/gcov.texi72
1 files changed, 72 insertions, 0 deletions
diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index c118061aed5..fa5bdd3d452 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -890,6 +890,78 @@ of times the call was executed will be printed. This will usually be
100%, but may be less for functions that call @code{exit} or @code{longjmp},
and thus may not return every time they are called.
+When you use the @option{-g} option, your output looks like this:
+
+@smallexample
+$ gcov -t -m -g tmp
+ -: 0:Source:tmp.cpp
+ -: 0:Graph:tmp.gcno
+ -: 0:Data:tmp.gcda
+ -: 0:Runs:1
+ -: 1:#include <stdio.h>
+ -: 2:
+ -: 3:int
+ 1: 4:main (void)
+ -: 5:@{
+ -: 6: int i, total;
+ 1: 7: total = 0;
+ -: 8:
+ 11: 9: for (i = 0; i < 10; i++)
+condition outcomes covered 2/2
+ 10: 10: total += i;
+ -: 11:
+ 1*: 12: int v = total > 100 ? 1 : 2;
+condition outcomes covered 1/2
+condition 0 not covered (true)
+ -: 13:
+ 1*: 14: if (total != 45 && v == 1)
+condition outcomes covered 1/4
+condition 0 not covered (true)
+condition 1 not covered (true false)
+ #####: 15: printf ("Failure\n");
+ -: 16: else
+ 1: 17: printf ("Success\n");
+ 1: 18: return 0;
+ -: 19:@}
+@end smallexample
+
+For every condition the number of taken and total outcomes are
+printed, and if there are uncovered outcomes a line will be printed
+for each condition showing the uncovered outcome in parentheses.
+Conditions are identified by their index -- index 0 is the left-most
+condition. In @code{a || (b && c)}, @var{a} is condition 0, @var{b}
+condition 1, and @var{c} condition 2.
+
+An outcome is considered covered if it has an independent effect on
+the decision, also known as masking MC/DC (Modified Condition/Decision
+Coverage). In this example the decision evaluates to true and @var{a}
+is evaluated, but not covered. This is because @var{a} cannot affect
+the decision independently -- both @var{a} and @var{b} must change
+value for the decision to change.
+
+@smallexample
+$ gcov -t -m -g tmp
+ -: 0:Source:tmp.c
+ -: 0:Graph:tmp.gcno
+ -: 0:Data:tmp.gcda
+ -: 0:Runs:1
+ -: 1:#include <stdio.h>
+ -: 2:
+ 1: 3:int main()
+ -: 4:@{
+ 1: 5: int a = 1;
+ 1: 6: int b = 0;
+ -: 7:
+ 1: 8: if (a && b)
+condition outcomes covered 1/4
+condition 0 not covered (true false)
+condition 1 not covered (true)
+ #####: 9: printf ("Success!\n");
+ -: 10: else
+ 1: 11: printf ("Failure!\n");
+ -: 12:@}
+@end smallexample
+
The execution counts are cumulative. If the example program were
executed again without removing the @file{.gcda} file, the count for the
number of times each line in the source was executed would be added to