Coverage instrumentation may be disabled or enabled for specific functions by using special parasoft-instrumentation coverage comments:

  • // parasoft-instrumentation coverage off - disables coverage instrumentation.
  • // parasoft-instrumentation coverage on - re-enables coverage instrumentation.

Elements (such as lines, decisions, etc.) of a function with disabled coverage instrumentation will not be counted as coverable.

Both comments affect function definitions located in the same file (before preprocessing), beginning after the line containing each respective comment. They operate at the granularity of an entire function (as a whole) - e.g. if placed inside a function, their effect will apply only to function definitions following them.

In the following example, code coverage instrumentation will be disabled for functions f2(), f3()f5(), main() and enabled for functions g()f1()f4(). The comment inside function f4() affects functions f5() and main() as their definitions are placed after this comment. C/C++test will treat this exemplary code as having seven coverable lines (one in g(), two in f1() and four in f4()).

int g(int i) { return i+1; }

int f1(int a) {
    if (a >= 0) return +1;
    else return -1;
}

// parasoft-instrumentation coverage off

int f2(int a) {
    return g(a - 1) + g(a);
}

int f3(int a) {
    return a + 2;
}

// parasoft-instrumentation coverage on

int f4(int a, int b) {
    if (a == 3) {
        return b;
    } else {
        /* parasoft-instrumentation coverage off */
        int i = g(a+b);
        return i;
    }
}

int f5(int a) {
    return f3(a * 2);
}

int main() {
    f1(12);
    return 0;
}

The parasoft-instrumentation coverage construct may be used inside both //... and /*...*/ comments. In case of /*...*/ comments, the entire construct must be placed in the same line as the /* comment opening characters. To be recognized, the parasoft-instrumentation coverage comment must be the only construct in the code line.

  • No labels