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

江枫思渺然 提交于 2019-12-06 08:08:47

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?

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