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,916评论 0 23
  • “生活不止眼前的苟且,还有诗和远方的田野。你赤手空拳来到人世间,为找到那片海不顾一切。”高晓松为许巍写的这首歌,不...
    散人于野阅读 330评论 0 1
  • 找车找到绝望 今天又把车停在新凤x商场的负二层,想起上回的经历,我想我一定要找到这两个奇特的车位,拍个片片留...
    沧海微尘阅读 372评论 0 0
  • 人问我:“你最喜欢去哪玩?”我会脱口而出:“去海边。远望海天一色的壮观景象,感受阵阵浪花的冲击,我的整个身心仿佛融...
    NANA0阅读 473评论 0 0
  • 当我写下这个题目的时候,我突然意识到这真的是很需要勇气的一件事情。 我的好朋友w,她曾经交往过一个男朋友,她很爱他...
    米姑娘阅读 237评论 0 2