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 

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 [email protected] -d .
    genhtml [email protected] -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.

LCOV 使用方法_第1张图片
Screen Shot 2017-07-12 at 4.58.41 AM.png

You can also open the link for details.

LCOV 使用方法_第2张图片
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

你可能感兴趣的:(LCOV 使用方法)