Chaosforge Forum

  • May 20, 2013, 03:21
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Pages: [1]

Author Topic: The gcov and the lcov  (Read 9074 times)

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
The gcov and the lcov
« on: November 29, 2009, 08:41 »

Okay, so I've been a little lazy lately, so it is time to program some code and chew bubble-gum... And I am all out of gum...

I created this topic as a little reminder what is there to do and what has been done.

Anyways, first I have to learn about such tools as gcov and lcov. I hope I will be able to post some progress today...

EDIT: Unfortunately, I need to download Cygwin and Active-Perl (just in case) to run lcov, as it is a set of Perl scripts that has some problems with Windows style paths. So I'll take that time to learn more about gcov (I have a slow mobile connection and it takes ages to download anything here...)

EDIT: There something wrong with the setup of the compiler. gcov reports that no part of the code (my sample code) is used. Need to investigate that later...
« Last Edit: November 29, 2009, 15:27 by Melon »
Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!

Kornel Kisielewicz

  • God Hand
  • Apostle
  • *
  • *
  • Offline Offline
  • Posts: 3684
    • View Profile
    • http://chaosforge.org/
Re: The gcov and the lcov
« Reply #1 on: November 29, 2009, 16:27 »

To be honest, I'm unsure whether lcov/gcov under windows is at all possible. I thought they were only compatible with elf/linux type executables...
Logged
at your service,
Kornel Kisielewicz

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
Re: The gcov and the lcov
« Reply #2 on: November 30, 2009, 14:46 »

To be honest, I'm unsure whether lcov/gcov under windows is at all possible. I thought they were only compatible with elf/linux type executables...
Well, I saw on forums that people run gcov under Windows. lcov is just a set of Perl scripts, and they can be run under Cygwin (at least that's what I learned from the forums so far...)

EDIT: As I promised, a very little update. I have managed to run successfully gcov for my small test project. When compiling, we have to use flags:
Code: [Select]
-fprofile-arcs -ftest-coverage
and while linking:
Code: [Select]
-fprofile-arcs
After compiling the code, we need to run the executable/binary. Only after that gcov utility is useful. To make the gcov output most human readable, we should use the -b parametre
Code: [Select]
gcov -b main.cppThis is my primitive main.cpp:
Code: [Select]
#include <iostream>

using std::cout;

int main( void )
{
    int i;
    for( i=0; i<50; i++ )
    {
        if( i == 60 )
        {
            cout << "Hello world!\n";
            return 0;
        }
        cout << "Will this run?\n";
        return 0;
    }
    cout << "This should not run!\n";
    return 1;
    cout << "And this too!";
    return 0;
}

And this is the output ot the gcov
Code: [Select]
          -:    0:Source:main.cpp
        -:    0:Graph:main.gcno
        -:    0:Data:main.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include <iostream>
        -:    2:
        -:    3:using std::cout;
        -:    4:
function main called 1 returned 100% blocks executed 56%
        1:    5:int main( void )
        -:    6:{
        -:    7:    int i;
        1:    8:    for( i=0; i<50; i++ )
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:    9:    {
        1:   10:        if( i == 60 )
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:   11:        {
    #####:   12:            cout << "Hello world!\n";
call    0 never executed
    #####:   13:            return 0;
        -:   14:        }
        1:   15:        cout << "Will this run?\n";
call    0 returned 100%
        1:   16:        return 0;
        -:   17:    }
    #####:   18:    cout << "This should not run!\n";
call    0 never executed
    #####:   19:    return 1;
        -:   20:    cout << "And this too!";
        -:   21:    return 0;
function _Z41__static_initialization_and_destruction_0ii called 1 returned 100% blocks executed 100%
function _GLOBAL__I_main called 1 returned 100% blocks executed 100%
        3:   22:}
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
call    4 returned 100%

All was run under cygwin, but I do not think that cygwin is essential for this [; In next days I will try out the lcov for this primitive project. After it is successful, I will try to do the same with Neko! To sum things up:
1) Compile and link with proper flags
2) Run the executable/binary after completion
3) Run gcov with desirable parametres
« Last Edit: November 30, 2009, 14:50 by Melon »
Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
Re: The gcov and the lcov
« Reply #3 on: December 06, 2009, 11:49 »

Unfortunately, not much of an update. I have been fighting with cygwin and lcov and I had to retire. I am reinstalling cygwin (I had some one year old version before) with bundled perl. After that, I will try to install lcov (or should I say, put it into proper directories).

I had seperate cygwin and perl. I do not if this is the problem, but lcov generated some strange path names (like: /cygdrive/c/lcov/examples/../bin). I will investigate this and hope that I'll manage to run lcov properly by the end of the week.
Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
Success!
« Reply #4 on: December 07, 2009, 13:17 »

I have finally managed to run the lcov example on cygwin!

I had some problems with permissions. Utility geninfo was informing me that it cannot read a specific file. I thought the problem was that it was because the file didn't exist. However, it seemed strange, that geninfo couldn't have found the "." (current) directory. What it turned out, after using the "walking ass" methodology, was that geninfo was using a small function that tested permission for some files (if it can be read/written). After fighting a while I changed the permissions (no, not with chmod, because it didn't work(?)) and finally I had a generated html document [: It is attached to this post

By the end of the week I will try to do the same with my little example I created earlier.
« Last Edit: December 09, 2009, 00:00 by Melon »
Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
Partial success
« Reply #5 on: December 14, 2009, 15:26 »

I have spent some time on gcov and lcov. Finally, I have generated a nice .html representation of what test cases are covering, and what are not. The test coverage is very low, which indicates that there are more test cases to run [:

In general lcov is an utility (which uses gcov), that shows us (at least that is how I understand it till now :) how much of the code is covered by testcases. This greatly speeds up the process of creating test cases. Effect of the lcov can be seen in the attachment.

Anyways, I had a lot of problems with lcov and there are still a lot of things to be done (mainly automatisation).

Here is my little summary, it might be helpfull for Cygwin users
1) When compiling the code, you should add the following flags: -fprofile-arcs -ftest-coverage
2) When linking the code, you should add the following flags: -fprofile-arcs -lgcov
3) gcov must have the correct version! If you are using (for example) a g++ compilet version 4.x.x, then it is most certain that gcov with version 3.x.x will start spitting errors. The problem is that lcov utility uses gcov.exe file. If you have gcov-4.exe file you have to manualy rename it (or edit the gcov.exe link) in your bin directory.
4) Where to get gcov-4? When installing cygwin, choose Delevel directory, and then choose gcc4-core package.
5) lcov can be found easily on the internet. After downloading lcov, check the Makefile to find out where to put proper files. Also read the Makefile from the example to find out how to make that cool html output [;
6) lcov will sometimes spit errors such as "ERROR: cannot read xxxxx file". It doesn't mean that the file doesn't exist. It means that the file hasn't got proper privileges set. You have to chmod that file (the best would be to chmod the whole directory ;). If chmod doesn't work, you have to set privilages from Windows, after that chmod should work fine.

And that is all folks! By the end of this year I will work on automating the test coverage.

Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
Re: The gcov and the lcov
« Reply #6 on: December 26, 2009, 07:35 »

Update: I updated the wiki page for Neko!. A page that describes how to build test coverage from scratch has been added, containing some description about gcov and lcov utilities. Anyone can build test coverage for Neko! or for his own project following easy instruction. The only thing left to do is automation of this procedure. Unfortunately, I do not have much time right now, and this might be delayed till the end of January.
Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!

arun

  • Private
  • *
  • Offline Offline
  • Posts: 1
  • Lost Soul
    • View Profile
Re: The gcov and the lcov
« Reply #7 on: January 31, 2011, 07:08 »

Hi
i have few programs written in C++ ; my intention is to check code coverage of these programs, so from internet I found that gcov/lcov/ggcov are the open source tools which will do code coverage checks for c/c++
So
 Tried to install these on my ubontu machine (ubontu synaptic manager,-->selected (lcov and ggcov ) and installed , but it is not sufficient it seems as when I start to use it always says about gcov-kernel

I did not get that from net so always my command as below is failing!

Please let me know
What are the things I need to install in details for doing code coverage analysis

Thanks in advance
arun
Logged

Melon

  • Programmer
  • Local Inquisitor
  • Colonel
  • *
  • *
  • Offline Offline
  • Posts: 525
  • Men are from Mars, Women are from Snickers
    • View Profile
Re: The gcov and the lcov
« Reply #8 on: February 04, 2011, 11:09 »

Hey arun!

I cannot help you much, because I dealt with gcov/lcov some time ago and it was under Windows/CygWin. All I can really suggest is to read the official manual, such as: http://gcc.gnu.org/onlinedocs/gcc/Gcov.html

I don't think that you will start using gcov/lcov straight away. Be patient [;

Cheers!!
Logged
Ludzie, którzy piją, są dla mnie niczym...

... niczym bracia!
Pages: [1]