Computernerd
Computernerd

Reputation: 7782

Interpret Gcov report for class objects

I am doing code coverage on the class cashier and my teacher gave a very brief teaching on the meaning of the report which i feel is very important for the development of my software engineering skills hence i would need your advice on the intepretation of the following gcov report . I would appreciate any links or articles which would help in my understanding of gcov

Thanks

Header file

#ifndef CASHIER_H
#define CASHIER_H
#include <string>
using namespace std;


class cashier 
{
public:

        void setID(string);
    string getID();

    void setPassword(string);
    string getPassword();

    void settries(int);
    int gettries();
        void increase_tries();

private:
    string ID;
    string Password;
    int tries;



};

#endif  /* CASHIER_H */

Implementation file

#include "cashier.h"




void cashier::setID(string value)
{
    this->ID = value;
}

void cashier::setPassword(string value)
{

    this->Password = value;

}

string cashier::getID()
{
    return this->ID;
}

string cashier::getPassword()
{
    return this->Password;
}

void cashier::settries(int value)
{
    this->tries=value;
}
int cashier::gettries()
{
    return this->tries;
}
void cashier::increase_tries()
{
    this->tries = this->tries + 1 ;

}

I type the following commands into the command prompt to use gcov on the class

gcov -b cashier.gnco

I got the following results A

File 'cashier.cpp'
Lines executed:100.00% of 18 //what does the 18 mean 
No branches                  //what does no branches mean
Calls executed:100.00% of 4   // what does 4 mean ??
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h' // Where did this come from ??
Lines executed:0.00% of 2
No branches
Calls executed:0.00% of 1
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov

I type in the following command

gcov -f cashier.gnco

I got the following results B

Function '_ZN7cashier8settriesEi' // does this refer to the function :settries
Lines executed:100.00% of 3       // my teacher doesnt think so but i feel it refer
                                  //to it , who is correct??

Function '_ZN7cashier8gettriesEv'
Lines executed:100.00% of 2

Function '_ZN7cashier14increase_triesEv'
Lines executed:100.00% of 3

Function '_ZN7cashier11getPasswordEv'
Lines executed:100.00% of 2

Function '_ZN7cashier5getIDEv'
Lines executed:100.00% of 2

Function '_ZNSsaSERKSs'
Lines executed:0.00% of 2

Function '_ZN7cashier11setPasswordESs'
Lines executed:100.00% of 3

Function '_ZN7cashier5setIDESs'
Lines executed:100.00% of 3

File 'cashier.cpp'
Lines executed:100.00% of 18
cashier.cpp:creating 'cashier.cpp.gcov'

File '/usr/include/c++/4.4/bits/basic_string.h'
Lines executed:0.00% of 2
/usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov'

My questions for Result A

1) What does 18 mean and its significance in Lines executed:100.00% of 18

2) What does no branches mean

3) what does 4 means and its significance in Calls executed:100.00% of 4

4) What does the entire paragraph mean

 File '/usr/include/c++/4.4/bits/basic_string.h'
    Lines executed:0.00% of 2
    No branches
    Calls executed:0.00% of 1
    /usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov

My questions for Result B

1) All the functions names etc: :'_ZN7cashier8settriesEi' almost matches cashier functions names etc: void settries(int) , I think it refers to the same function but my teacher feels otherwise , who is correct ??

2) What does the 3 mean in Lines executed:100.00% of 3for the function :'_ZN7cashier8settriesEi'

Upvotes: 0

Views: 490

Answers (2)

Melebius
Melebius

Reputation: 6695

The names like _ZN7cashier8settriesEi are mangled names and they definitely refer to the functions like cashier::settries() in this case.

Lines executed is simply the number of lines in the source file which were gone through during the program run. You should look into the detailed results (see example) to examine which ones are the actual executable and executed lines.

No branches means that there are no points of decision like if statements in the code.

Calls executed are the calls of functions from that file to the functions of that file.

void cashier::setID(string value)
{
    this->ID = value; // call to string::operator=()
}

void cashier::setPassword(string value)
{
    this->Password = value; // call to string::operator=()
}

string cashier::getID()
{
    return this->ID; // call to copy-constructor of string
}

string cashier::getPassword()
{
    return this->Password; // call to copy-constructor of string
}

These four methods are calling std::string’s methods, although it’s not written explicitly. (See my comments to the code above.) The other three methods manipulate variables of basic type int and this requires no function calls.

Upvotes: 2

Igor
Igor

Reputation: 1059

Result A:

  1. 18 lines of your code was executed after launch program (relate to cashier.cpp).
  2. Your code hasn't any conditions.
  3. 4 lines was executed from 4 instrumented (relate to cashier.h)
  4. Some lines of std::string became part of coverage. You should exclude std::string from coverage report(gcov -e)

Result B:

  1. Yes
  2. 3 lines was executed from 3 instrumented.

P.S. If you interested in gcov you can install lcov - it is gui representation on gcov report.

Upvotes: 3

Related Questions