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.pngYou can also open the link for details.
Screen Shot 2017-07-12 at 5.02.12 AM.pngThe red color is not coverage.
At last,
Enter this command will remove make results.
make clean
网友评论