« Return to Thread: Experimental Valgrind coverage tool (fwd)

Re: Experimental Valgrind coverage tool (fwd)

by Bugzilla from olig9@gmx.de :: Rate this Message:

Reply to Author | View in Thread

Nicholas Nethercote wrote:

> On Thu, 7 Feb 2008, Oliver Gerlich wrote:
>
>> that sounds quite like I was looking for. But one thing that I've
>> wondered about in particular when using Valgrind for coverage is how
>> it works with C++ templates? If a template is never instantiated, how
>> can a coverage tool detect that there is source code that is never
>> executed? Is that possible somehow?
>
> My tool just records which instructions get executed, and then maps that
> back to the source code lines according to the debug info.  It also
> identifies source lines mentioned in the debug info which weren't
> executed. So I don't know the answer to your question, it depends
> entirely how GCC produces its debug info for templates, but I suspect
> the lines of code within the template would end up marked as unexecuted.
>
> Nick
Thanks for the explanation! I had tried to build a coverage tool myself
which parses callgrind/cachegrind output files; but I have not found a
way to get it working correctly for this "not-instantiated template"
case... That's why I'm interested whether someone has found solution for
this.

Attached is an example where my coverage tool fails: while it explicitly
marks templateFunction3 as not-executed, it doesn't mark
templateFunction2 like that. You can see at
http://img509.imageshack.us/img509/9682/cgctemplateexample1na6.png how
it looks. Also, because of this, the "68% executed" number is wrong as well.


Regards,
Oliver Gerlich


/*
Test whether a coverage tool detects unused templates as "not covered".

Compile with:
g++ -o test -Wall -Wextra -g coverage-template-test.C
and run with parameter "10".

Correct coverage result would be:
- in templateFunction1 and normalFunction, the "else" branch is executed, and the "if" code is not covered.
- in templateFunction2 and templateFunction3, no code is not covered.

*/


#include <iostream>
using std::cout;
using std::cerr;
using std::endl;

template <typename T>
bool templateFunction1 (T input)
{
    if (input == 23)
        return true;
    else
        return false;
}

template <typename T>
bool templateFunction2 (T input)
{
    if (input == 24)
        return true;
    else
        return false;
}

template <typename T>
bool templateFunction3 (T input)
{
    if (input == 25)
        return true;
    else
        return false;
}

bool normalFunction (int input)
{
    if (input == 42)
        return templateFunction3(input);
    else
        return false;
}

int main (int argc, char* argv[])
{
    if (argc != 2)
    {
        cerr << "Usage: " << argv[0] << " <number>" << endl;
        return 1;
    }

    int number = atoi(argv[1]);
    cout << "number: " << number << endl;
    cout << "normalFunction: " << normalFunction(number) << endl;
    cout << "templateFunction1: " << templateFunction1(number) << endl;
    cout << "templateFunction2: " << /*templateFunction2(number)*/ "NOT EXECUTED" << endl;
    return 0;
}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-users mailing list
Valgrind-users@...
https://lists.sourceforge.net/lists/listinfo/valgrind-users

 « Return to Thread: Experimental Valgrind coverage tool (fwd)