Line Suppression
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
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
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
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:
- suppressing all coverage metrics in lines matching REGEX with an auto-generated justification (reason):
cpptestcov suppress --regex REGEX <COV_DATA_DIR>
- suppressing selected coverage metrics in lines matching REGEX with a specific justification (reason):
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
Reporting Suppressed Coverage
Coverage reporters cpptestcov report
will apply coverage suppressions to the number of covered elements (numerator) and print the number of suppressed elements with `(+<suppressed>)`.
Example:
`SC=100% 3(+5)/8` - 3 out of 8 statements were covered, while other 5 statements were suppressed
See also cpptestcov report suppressions or cpptestcov report suppressed-lines for more details about suppressed coverage.