linux-test-project / lcov

LCOV
GNU General Public License v2.0
867 stars 235 forks source link

branch coverage is not effect #204

Closed yi452873250 closed 1 year ago

yi452873250 commented 1 year ago

ubuntu 20.04 lcov 1.16 example demo:

include

include

include

include

int main(int argc, const char *argv[]) { bool b = false; if (strcmp(argv[1], "1") == 0) b = true;

char *a = nullptr;
if (b)
  printf("Hai\n");
delete[] a;

std::string str("asdads");
str = "cd";

std::cout << str << std::endl;
return 0;

}

steps: 1.edit lcovrc line 100 image line 193 image 2.build image image build out foo foo.gcno run ./foo 1 image run lcov --capture --directory . --output-file foo.info --no-external image

run genhtml foo.info --output-directory output --title "basic test" --show-details --legend image

but the result is as fllow image

what`s wrong with me ~~

yi452873250 commented 1 year ago

image

build this github demo ,but change c to cpp ,and insert some code,finally make

image

I guess icov is only support c not c++

henry2cox commented 1 year ago

My guess would be that lcov/genhtml did not pick up the lcovrc that you edited. The lcov version you will find at top-of-tree (TOT) has some features to help debug this - but 1.16 does not.

One thing to try is to change your LCOV command to

lcov --rc lcov_branch_coverage=1 ...

and your genhtml command to

genhtml --branch-coverage ....

and see what happens (if anything). If this works - then the issue is that your lcovrc is not where you thought it was. If it doesn't work..I'm not quite sure why not. I suggest to download the latest code here - then change your capture command to add some verbosity and debug logging: lcov --capture -v -v --debug ... and then we can see what is happening.

The other question is what version of gcc you are using (gcc -dumpversion) - but that is unlikely to be your problem - unless your gcc is very, very old.

To the best of my knowledge: lcov supports multiple languages, including C/C++/python and a few others :-)

Henry

NOTE: ... means "use the rest of your original command line, unchanged"

yi452873250 commented 1 year ago

My guess would be that lcov/genhtml did not pick up the lcovrc that you edited. The lcov version you will find at top-of-tree (TOT) has some features to help debug this - but 1.16 does not.

One thing to try is to change your LCOV command to

lcov --rc lcov_branch_coverage=1 ...

and your genhtml command to

genhtml --branch-coverage ....

and see what happens (if anything). If this works - then the issue is that your lcovrc is not where you thought it was. If it doesn't work..I'm not quite sure why not. I suggest to download the latest code here - then change your capture command to add some verbosity and debug logging: lcov --capture -v -v --debug ... and then we can see what is happening.

The other question is what version of gcc you are using (gcc -dumpversion) - but that is unlikely to be your problem - unless your gcc is very, very old.

To the best of my knowledge: lcov supports multiple languages, including C/C++/python and a few others :-)

Henry

NOTE: ... means "use the rest of your original command line, unchanged"

image image

it doesn`t work ,has any idea?

henry2cox commented 1 year ago

Sorry. I think I misread your original issue. Please clarify. I now think that you are complaining the lcov has picked up a bunch of branches which are related to exception handling in C++ - and you do not what to see those. If that is the case: please take a look at the --filter branch option (on TOT code version) and/or lcov --capture --rc geninfo_no_exception_branch=1 ...

If your issue is something different...could you explain what you wanted the result to be. I'm having a hard time to guess from context.

yi452873250 commented 1 year ago

Sorry. I think I misread your original issue. Please clarify. I now think that you are complaining the lcov has picked up a bunch of branches which are related to exception handling in C++ - and you do not what to see those. If that is the case: please take a look at the --filter branch option (on TOT code version) and/or lcov --capture --rc geninfo_no_exception_branch=1 ...

If your issue is something different...could you explain what you wanted the result to be. I'm having a hard time to guess from context.

insert the option image

other operate is same with before

now result ,you see image

I finally want the result is the branch coverage is correct ,but you see "printf" and "delete" and "cout" ,it shouldn`t show "+ -" could you operate the branch coverage from top code demo~ thanks your reply

henry2cox commented 1 year ago

It appears that your compiler does not correctly mark the exception branches on lines 14, 15, 17, 18, and 20. It notes that there are branches there - but does not mark that they are associated with exceptions. As a result, 'gcov' (also part of your compiler tool chain) doesn't report exception branches there - and lcov produces the report you see. This is not a surprising result. AFAIK: every version of gcc and every version of LLVM that I have tried, has at least a few of these issues.

I guess you already compared the reports that you get when you add or remvoe the "no_exception_branch" configuration flag - so you can deduce which branches are marked as exceptions and which are not.

At this point, you have 4 options:

Your other option is to take a look at the gcc/llvm implementation and improve the branch coverage implementation. Then we all benefit. (I caution that, if this was easy, it would have already been done. Not a small project.)

I recognize that this is not a terribly satisfying answer.

Henry

henry2cox commented 1 year ago

Did you run again with --filter branch - and did that remove the exception branches you did not want to see? As mentioned above: the feature works for me (and for multiple other users). If it is not working for you, then there is something unusual in your environment or you are using an old version of code.

If this is working correctly: please close the issue. If it is not working: please clarify what is not working.

Thanks Henry

yi452873250 commented 1 year ago

on my computer ,it`s not work . --filter branch is not command image

henry2cox commented 1 year ago

You need to be using the latest lcov source version from github. Whatever old version you are using does not implement the various new features. There is a link at the top of the main project page, to either clone the lcov repo or to download a zip file of the code.

To see which version you are currently using - and to verify that you are using the downloaded lcov - you can run which genhtml (will give you the install path) and genhtml --version (will tell you what install version genhtml thinks that it is).

yi452873250 commented 1 year ago

image I have downed this package image

then,run make make install is it not correct?

henry2cox commented 1 year ago

You downloaded version 1.16. It even told you that it is from june last year. Not latest.

'Latest' is from the link at the top of the main page. I appear not to be able to upload images - so I can't point you to it. Look for the green button labeled <> Code - then either Download ZIP or Clone.

yi452873250 commented 1 year ago

oh·I try it agin ,my english is so bad ,so sometimes I dont get it,I m so sorry!

henry2cox commented 1 year ago

No worries. Much (much!) better than my Mandarin. I'm lucky to make a successful coffee shop order.

yi452873250 commented 1 year ago

now,I download the latest code and unzip lcov-master,then cd lcovmaster dir,then run make install image

but run genhtml ,it has error!

henry2cox commented 1 year ago

Right. You are missing required Perl modules. That is what the Perl error is telling you. You can find a list of modules that lcov wants in the README file (or in the README section of the main page from where you downloaded the zip file). It also shows one method to install missing perl modules - but your platform may have some other method.

"DateTime" is not likely to be the only module you don't have.

yi452873250 commented 1 year ago

image finally,it works,let me feel happy ,without your assistance,I cant do it
Thank you for your patient answer image

kramer1985 commented 1 year ago

Hi, I can generate the html file but it is empty. [build] geninfo: WARNING: no data generated [build] Excluded data for 96 files due to include/exclude options [build] Finished .info-file creation [build] [9/19 36% :: 4.146] Generating lcov/data/init/smp-fcgi-time-slib.info [build] [10/19 42% :: 4.199] Post-processing lcov/data/init/smp-fcgi-time-slib.info [build] FAILED: lcov/data/init/smp-fcgi-time-slib.info

My setup -IDE: Visual studio code as well -lcov version : LCOV version v1.16-67-g1c16cc3 -OS: Linux Ubuntu

I also set these flags lcov_branch_coverage = 1 and genhtml_branch_coverage = 1

I recompiled lcov and I recompiled my application but I am still stuck with this errotr above.

Any help please ?