Coverage suppressions simplify results analysis and compliance reporting for code bases that include uncoverable code. Uncoverable code can be annotated with appropriate in-code markers that include justification. It is also possible to use regular expression-based suppressions to suppress reporting coverage from repeatable lines of code that follow specific patterns. Code coverage suppressions are typically utilized when dealing with code which is difficult or impossible to cover, such as:
After applying suppressions, the suppressed code elements will be treated as covered. However, for visibility, the number of suppressed code elements will be reported using the `(+<suppressed>)`
notation.
Example:
`SC=100% 3(+5)/8` - 3 out of 8 statements were covered, while other 5 statements were suppressed |
The process of applying coverage suppressions:
cpptestcov compute
command.cpptestcov compute -map=.cpptest/cpptestcc -clog=cpptest_results.clog -out=.coverage |
cppte
stcov suppress
command.cpptestcov suppress .coverage |
cpptestcov suppress --regex-cov-reason ".*while\(1\).*" DC "ignore decision coverage for while(1)" .coverage |
cppte
stcov re
port
command.cpptestcov report text .coverage |
Line suppression allows for ignoring coverable elements which begin in a given line. The suppression comment must be specified at the end of the line of code, using the following syntax:
// parasoft-cov-suppress <coverage-id>|ALL "<suppression comment>" |
Examples:
int getValue(int a, int b) { if ((a > 0) && // parasoft-cov-suppress MCDC "ingore boolean-decision" (b > 0)) // parasoft-cov-suppress SCC "ignore simple condition" { return a * b; // parasoft-cov-suppress SC DC "ignore statement and branch" } if (a > 0) { // parasoft-cov-suppress DC "ignore branch-decision" return a; // parasoft-cov-suppress "ignore all metrics - ALL is optional" } else { return b; } return 0; } |
Next-line suppression allows for ignoring coverable elements which begin in the next line. The suppression comment must be specified in the preceding line, using the following syntax:
// parasoft-cov-suppress-next-line <coverage-id>|ALL "<suppression comment>" |
Examples:
int getValue(int a, int b) { if (a > 0) { return a; } else { return b; } // parasoft-cov-suppress-next-line ALL "ignore all coverage metrics in the next line" return 0; } |
Block suppression allows for ignoring coverable elements in a block of code. The suppression begin/end comments must be specified before/after the block of code, using the following syntax:
// parasoft-cov-begin-suppress <coverage-id>|ALL "<suppression comment>" ...code block... // parasoft-cov-end-suppress |
Examples:
// parasoft-cov-begin-suppress ALL "ignore coverage analysis for the function" int deadCode(int i) { int k = i + 10; return getValue(i, k); } // parasoft-cov-end-suppress |
Regex-based line suppression allows for ignoring coverable elements in a line that matches a regular expression. Regular expressions can be specified with the cpptestcov suppress
command:
cpptestcov suppress --regex REGEX <COV_DATA_DIR> |
cpptestcov suppress --regex-cov-reason REGEX COVTYPE REASON <COV_DATA_DIR> |
Examples:
cpptestcov suppress --regex ".*DEBUG.*" --regex ".*ASSERT.*" cov-data-run1 cpptestcov suppress --regex-cov-reason ".*while\(1\).*" DC "ignore decision coverage for while(1)" cov-data-run1 |