Skip to content

Instantly share code, notes, and snippets.

@flavius
Created September 6, 2011 11:26
Show Gist options
  • Save flavius/1197309 to your computer and use it in GitHub Desktop.
Save flavius/1197309 to your computer and use it in GitHub Desktop.
code coverage
See the question: http://stackoverflow.com/questions/7319204/code-coverage-which-run-covers-which-code
#!/bin/bash
gcov -d *.c
lcov -d . -z
./primes 0
./primes 1
./primes
lcov -d . --capture --output-file primes.info
mkdir report
genhtml -o report primes.info
/**
* initially I intended to make this more involved,
* that's why it's called "primes". I've reduced the
* POC, it has nothing to do with prime numbers, and
* I'm lazy
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
int n;
if(argc == 1) {
return EXIT_FAILURE;
}
n = atoi(argv[1]);
if(n == 0) {
return EXIT_SUCCESS;
}
else {
return n;
}
}
CC=gcc
CFLAGS=-Wall -g3 -O0 -fprofile-arcs -ftest-coverage
OBJ_FILES=main.o
primes: $(OBJ_FILES)
$(CC) $(CFLAGS) -o $@ $?
main.o: main.c
$(CC) $(CFLAGS) -o $@ -c $?
clean:
rm -rf *.o primes
rm -rf *.gcno *.gcda *.gcov
rm -rf primes.info
rm -rf report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment