1. 程式人生 > >google test lcov genhtml 產生覆蓋率xml檔案,去除不需要的檔案(include),或者包含需要的(source)

google test lcov genhtml 產生覆蓋率xml檔案,去除不需要的檔案(include),或者包含需要的(source)

接我的上一篇

問題:在產生了.gcno 和 .gcda兩個檔案後,使用lcov -c -d Debug/source/ -o Debug/coverage.info 產生中間檔案coverage.info檔案,然後用genhtml -o output/  Debug/coverage.info產生html檔案,發現產生的index.xml檔案包含了include,甚至/usr/*下的公共標頭檔案,怎麼去除這些不需要統計覆蓋率的檔案?

1。正向提取需要的檔案:

//比如希望把source相關的路徑提取出來

lcov --extract Debug/coverage.info '*source/*' -o Debug/finalresult.info

//然後產生的xml就包含所有source相關的檔案

genhtml -o output/  Debug/finalresult.info

2。反向去除不需要的檔案:

//比如希望去除UnitTest 和/usr/相關檔案:

lcov --remove Debug/coverage.info '*UnitTest/*' '/usr/*' -o Debug/finalresult.info

//然後產生的xml就去除了UnitTest 和/usr/相關的檔案

genhtml -o output/  Debug/finalresult.info

注意:lcov 不允許同時使用--extract  和  --remove