LCOV 使用方法

LCOV is a graphical front-end for GCC's coverage testing tool gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. LCOV supports statement, function and branch coverage measurement.

For example:
3 files: hellofunc.c, hello.c, hello.h.

/*  hellofunc.c  */
#include "hello.h"

int hellofunc(int x){
    if(x % 2)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}
/*  hello.c  */
#include "hello.h"

int main(void){
    printf("Hello From Eclipse!");

    int x = hellofunc(3);
    printf("%d\n", x);
    return 0;
}
/*  hello.h  */
#ifndef HELLO_H_
#define HELLO_H_

#include <stdio.h>

int hellofunc(int);

#endif /* HELLO_H_ */

Here are makefile

CC=gcc
CFLAGS=-I.
DEPS= hello.h
OBJ = hello.o hellofunc.o
COV = -ftest-coverage -fprofile-arcs

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS) $(COV)
    
hello: $(OBJ)
    gcc -o $@ $^ $(CFLAGS) --coverage
    ./hello
    lcov -c -o $@.info -d .
    genhtml $@.info -o $@_result
    open $@_result/index.html
    
clean:
    rm -f $(OBJ) hello hello.info hello.g* hellofunc.g*
    rm -rf hello_result

Enter this command:

make

This will open a safari and show results.

Screen Shot 2017-07-12 at 4.58.41 AM.png

You can also open the link for details.

Screen Shot 2017-07-12 at 5.02.12 AM.png

The red color is not coverage.

At last,
Enter this command will remove make results.

make clean
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,850評論 0 23
  • “生活不止眼前的茍且,還有詩和遠方的田野。你赤手空拳來到人世間,為找到那片海不顧一切。”高曉松為許巍寫的這首歌,不...
    散人于野閱讀 330評論 0 1
  • 找車找到絕望 今天又把車停在新鳳x商場的負二層,想起上回的經歷,我想我一定要找到這兩個奇特的車位,拍個片片留...
    滄海微塵閱讀 369評論 0 0
  • 人問我:“你最喜歡去哪玩?”我會脫口而出:“去海邊。遠望海天一色的壯觀景象,感受陣陣浪花的沖擊,我的整個身心仿佛融...
    NANA0閱讀 469評論 0 0
  • 當我寫下這個題目的時候,我突然意識到這真的是很需要勇氣的一件事情。 我的好朋友w,她曾經交往過一個男朋友,她很愛他...
    米姑娘閱讀 236評論 0 2