using-gcov-lcov

上面說的 gcov 都是簡單的使用方式

帶有 main 的可執行程式可以這樣簡單

但如果是 share library 該如何是好?

還好也有人有一樣的問題

Is it possible code coverage of a shared library using gcov?

 

CFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += --coverage

雖然 CFLAGS,  LDFLAGS 加入了 -fprofile-arcs -ftest-coverage 和 --coverage

但終究還是要有程式執行並 link 這個 so 才行

可惜我就是沒有可執行程式

且開發, 執行環境天差地遠...

最後用了 gtest 寫測試去 link so 才產生 coverage

 

# generate report
lcov -d . -t 'test' -o 'my_test.info' -b src/ -c
# remove unrelated source
lcov --remove my_test.info '/usr/include/*' 'output/include/*' 'src/*.cc' -o my_test.info
# generate html
genhtml -o my_test_result my_test.info

 lcov -d 帶入的是建置目錄

-b 帶入的則是 source code 目錄

LCOV Code Coverage

arrow
arrow
    全站熱搜

    JohnDX 發表在 痞客邦 留言(0) 人氣()