Created
September 6, 2011 11:26
-
-
Save flavius/1197309 to your computer and use it in GitHub Desktop.
code coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See the question: http://stackoverflow.com/questions/7319204/code-coverage-which-run-covers-which-code | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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