本文介绍了gcov不会生成头文件的覆盖率信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用,而我有一个类似于这个。然而,我没有能够解决我的问题后,该线程中的意见。



我试图测量一个具体测试用例在,即测试文件中的testConstructor mymoneyaccounttest.cpp。此测试用例使用以下方法,它位于头文件mymoneyaccount.h中并具有可执行代码: QString的&安培; institutionId(void)const {
return m_institution;
}

因此,我构建了程序和测试,然后执行:
gcov mymoneyaccount.cpp



在显示的覆盖率信息中,我获得:

...
文件'mymoneyaccount.cpp'
执行的行数:393 $的8.91%b $ b创建'mymoneyaccount.cpp.gcov'



文件'mymoneyaccount。 h'
执行的行数:4
的25.00%创建'mymoneyaccount.h.gcov'
...



覆盖信息在mymoneyaccount.cpp.gcov是好的。相反,mymoneyaccount.h.gcov显示:

  6:81:class KMM_MYMONEY_EXPORT MyMoneyAccount:public MyMoneyObject,public MyMoneyKeyValueContainer 
...
- :192:const QString& InstitutionId(void)const {
- :193:return m_institution;
- :194:}
...
- :272:int accountCount(void)const {
#####:273:return m_accountList.count();
- :274:};

也许我错了,但是这个结果意味着gcov不考虑return m_institution;作为可执行代码,同时考虑将返回m_accountList.count()作为可执行代码。此外,它在类声明的行中显示6,所以这个文件有覆盖信息,但不是我期望的。



我不得不说问题与文件和目录的名称有关:



1-目标文件在CMakefiles / kmm_mymoney.dir中创建,以.cpp。结尾。 o,例如mymoneyaccount.cpp.o。因此,使用名称mymoneyaccount.cpp.gcno和mymoneyaccount.cpp.gcda(当然,在CMakefiles / kmm_mymoney.dir目录中)创建gcno和gcda文件。



2-当我执行时:
gcov -o CMakeFiles / kmm_mymoney.dir mymoneyaccount.cpp
gcov给出以下错误:

mymoneyaccount.gcno:无法打开便签文件



所以我必须重命名这些文件:
mv mymoneyaccount.cpp.gcno mymoneyaccount .gcno
mv mymoneyaccount.cpp.gcda mymoneyaccount.gcda



最后,我还有一个问题。当我在包含测试用例的文件中执行gcov时,我的意思是,gcov mymoneyaccounttest.cpp而不是gcov mymoneyaccount.cpp,我也获得了mymoneyaccount.h.gcov文件,但覆盖率信息更差:

  #####:81:class KMM_MYMONEY_EXPORT MyMoneyAccount:public MyMoneyObject,public MyMoneyKeyValueContainer 


对不起。谢谢。

解决方案

非常感谢Tony!该链接有解决方案。我只是将优化从-O2更改为-O0,现在结果是:

  1:192:const QString& InstitutionId(void)const {
1:193:return m_institution;
- :194:}

我必须注意,要获得mymoneyaccount.cpp。 gcov我执行gcov mymoneyaccount.cpp,但要获得mymoneyaccount.h.gcov我必须执行gcov mymoneyaccounttest.cpp。你知道为什么吗?这两个文件都包含mymoneyaccount.h。


I'm using gcov for the first time and I'm having a problem which is similar to the one reported in this thread. However, I wasn't able to solve my problem following the comments in that thread.

I'm trying to measure the coverage of a concrete test case in KMyMoney-4.6.4, namely "testConstructor" in the test file "mymoneyaccounttest.cpp". This test case is using the following method, which is in the header file "mymoneyaccount.h" and has executable code:

 const QString& institutionId(void) const {
    return m_institution;
  }

So, I build the program and the tests, and then execute:gcov mymoneyaccount.cpp

Among the coverage information displayed, I obtain:

...File 'mymoneyaccount.cpp'Lines executed:8.91% of 393Creating 'mymoneyaccount.cpp.gcov'

File 'mymoneyaccount.h'Lines executed:25.00% of 4Creating 'mymoneyaccount.h.gcov'...

The coverage information in "mymoneyaccount.cpp.gcov" is ok. In contrast, "mymoneyaccount.h.gcov" shows:

    6:   81:class KMM_MYMONEY_EXPORT MyMoneyAccount : public MyMoneyObject, public MyMoneyKeyValueContainer
    ...
    -:  192:  const QString& institutionId(void) const {
    -:  193:    return m_institution;
    -:  194:  }
    ...
    -:  272:  int accountCount(void) const {
#####:  273:    return m_accountList.count();
    -:  274:  };

Maybe I'm wrong, but this result means that gcov is not considering "return m_institution;" as executable code while does it considering "return m_accountList.count()" as executable code. Moreover, it shows "6" in the line of the class declaration, so this file has coverage information but not what I was expecting.

I have to say that maybe the problem has to do with the names of the files and the directories:

1- The object files are created in "CMakefiles/kmm_mymoney.dir" ending with ".cpp.o", for instance, mymoneyaccount.cpp.o. Thus, the "gcno" and "gcda" files are created with the name "mymoneyaccount.cpp.gcno" and "mymoneyaccount.cpp.gcda" (of course, in the directory "CMakefiles/kmm_mymoney.dir").

2- When I execute:gcov -o CMakeFiles/kmm_mymoney.dir mymoneyaccount.cppgcov gives the following error:

mymoneyaccount.gcno:cannot open notes file

So I have to rename those files:mv mymoneyaccount.cpp.gcno mymoneyaccount.gcnomv mymoneyaccount.cpp.gcda mymoneyaccount.gcda

Finally, I have another question. When I execute gcov in the file containing the test cases, I mean, "gcov mymoneyaccounttest.cpp" instead of "gcov mymoneyaccount.cpp", I also obtain a "mymoneyaccount.h.gcov" file, but the coverage information is even worse:

#####:   81:class KMM_MYMONEY_EXPORT MyMoneyAccount : public MyMoneyObject, public MyMoneyKeyValueContainer

Anyway, the question is: should I execute "gcov" on the implementation file "mymoneyaccount.cpp" or in the test file "mymoneyaccounttest.cpp"?

Sorry for the length. Thanks.

解决方案

Thank you very much Tony!! That link had the solution. I just changed the optimization from -O2 to -O0 and now the result is:

1: 192: const QString& institutionId(void) const { 
1: 193:     return m_institution; 
-: 194: } 

I have to note that to obtain "mymoneyaccount.cpp.gcov" I execute "gcov mymoneyaccount.cpp", but to obtain "mymoneyaccount.h.gcov" I have to execute "gcov mymoneyaccounttest.cpp". Do you know why? Both files include "mymoneyaccount.h".

这篇关于gcov不会生成头文件的覆盖率信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 21:55