How to find the coverage of a library opened using dlopen()?

余生长醉 提交于 2019-12-12 09:58:07

问题


I have a C++ library (.so) which is opened using dlopen() by another application. But I need to find the code coverage of this library while run within the application using gcov. Is it possible? If yes, how can it be done?

If not, how can the issue be resolved?


回答1:


Firstly have your compiled your C++ library with the --coverage flag? I've never actually used a '.so' library with gcov before, so I'm not sure it would work anyway.

Secondly could you arrange a test version of your application to not use dlopen(), but instead be linked to a static library(.a) version of your library and still make the usual calls?




回答2:


Yes. Coverage of shared library loaded by dlopen can be generated.

1) compile shared library with flags -fprofile-arcs -ftest-coverage

2) compile program that using dlopen with flags -fprofile-arc -ftest-coverage

3) lcov to generate .info file

lcov --capture --rc lcov_branch_coverage=1 --directory path/to/.gcda --output-file coverage.info 

4) generate html

genhtml coverage.info --branch-coverage --output-directory out 


来源:https://stackoverflow.com/questions/6368124/how-to-find-the-coverage-of-a-library-opened-using-dlopen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!