diff --git a/tests/Makefile b/tests/Makefile index b52e00cf..ac57b05a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,6 @@ #NOTE: GMP is only used for the tests CC=gcc -std=c99 -CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function +CFLAGS=-Wall -W -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith -Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code -Wlogical-op -Wstrict-aliasing=2 -Wredundant-decls -Wold-style-definition -Wno-unused-function -DSTART_COVERAGE="" -DEND_COVERAGE="" CPPFLAGS=-I.. RM=rm -f VALGRIND= @@ -64,4 +64,16 @@ gene-array: clean: $(RM) $(EXE) *.s *~ *.o ./a.dat - $(RM) -r coverage *.gcda *.gcno all.info test.tar README.html + $(RM) -rf coverage *.gcda *.gcno *.gcov all.info test.tar coverage-dir + +coverage-dir: + mkdir -p coverage-dir + +coverage-dir/%.c: %.c coverage-dir + awk '/START_COVERAGE/ { printit=1} (printit == 0) { print }' $< > coverage-dir/first.c + awk ' printit { print } /END_COVERAGE/ { printit=1}' $< > coverage-dir/end.c + $(CC) -E -std=c99 -I.. -DNDEBUG $< |grep -v '^#' |awk ' /END_COVERAGE/ { printit=0} printit { print } /START_COVERAGE/ { printit=1 }' > coverage-dir/middle.c + cat coverage-dir/first.c coverage-dir/middle.c coverage-dir/end.c > coverage-dir/$< + +coverage: coverage-dir + for i in test-m*.c ; do echo $$i ; make coverage-dir/$$i && $(CC) -ftest-coverage -fprofile-arcs -std=c99 -I.. coverage-dir/$$i -o $(EXE) -lgmp -pthread && $(EXE) && gcov $$i ; done diff --git a/tests/test-malgo.c b/tests/test-malgo.c index 2d89e3c4..3dbc4f39 100644 --- a/tests/test-malgo.c +++ b/tests/test-malgo.c @@ -4,16 +4,16 @@ #include "m-algo.h" ARRAY_DEF(int, int) - -ALGO_DEF(algo_array, ARRAY_OPLIST(int)) - LIST_DEF(int, int) +LIST_DEF(string, string_t, STRING_OPLIST) + +START_COVERAGE +ALGO_DEF(algo_array, ARRAY_OPLIST(int)) ALGO_DEF(algo_list, LIST_OPLIST(int)) -LIST_DEF(string, string_t, STRING_OPLIST) - ALGO_DEF(algo_string, LIST_OPLIST(string, STRING_OPLIST)) +END_COVERAGE static void test_list(void) { diff --git a/tests/test-marray.c b/tests/test-marray.c index a4369b42..0b86c911 100644 --- a/tests/test-marray.c +++ b/tests/test-marray.c @@ -24,9 +24,6 @@ #include #include "m-array.h" -ARRAY_DEF(uint, unsigned int) -#define ARRAY_UINT_OPLIST ARRAY_OPLIST(uint) - static void my_mpz_out_str(FILE *f, const mpz_t z) { mpz_out_str (f, 10, z); @@ -52,10 +49,15 @@ static void my_mpz_str(string_t str, const mpz_t z, bool append) free(s); } +START_COVERAGE +ARRAY_DEF(uint, unsigned int) + ARRAY_DEF(mpz, mpz_t, (INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear), \ OUT_STR(my_mpz_out_str), IN_STR(my_mpz_in_str), EQUAL(my_mpz_equal_p), \ GET_STR(my_mpz_str) )) +END_COVERAGE +#define ARRAY_UINT_OPLIST ARRAY_OPLIST(uint) static void test_uint(void) { diff --git a/tests/test-mdict.c b/tests/test-mdict.c index 3e88f9a6..f98025f9 100644 --- a/tests/test-mdict.c +++ b/tests/test-mdict.c @@ -27,7 +27,10 @@ #include "m-array.h" #include "m-string.h" +START_COVERAGE DICT_DEF2(str, string_t, STRING_OPLIST, string_t, STRING_OPLIST) +END_COVERAGE + ARRAY_DEF(string, string_t, STRING_OPLIST) array_string_t v; diff --git a/tests/test-milist.c b/tests/test-milist.c index aeeb7acf..2786c9b2 100644 --- a/tests/test-milist.c +++ b/tests/test-milist.c @@ -31,8 +31,10 @@ typedef struct test_s { ILIST_INTERFACE (tname, struct test_s); } test_t; +START_COVERAGE ILIST_DEF(tname, test_t) - +END_COVERAGE + static void test(void) { test_t x1, x2, x3; diff --git a/tests/test-mlist.c b/tests/test-mlist.c index bc8be738..8b858b7b 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -22,11 +22,9 @@ */ #include #include // For testing purpose only. +#include "m-string.h" #include "m-list.h" -LIST_DEF(uint, unsigned int) -#define LIST_UINT_OPLIST LIST_OPLIST(uint) - static void my_mpz_out_str(FILE *f, const mpz_t z) { mpz_out_str (f, 10, z); @@ -42,7 +40,6 @@ static bool my_mpz_equal_p(const mpz_t z1, const mpz_t z2) return mpz_cmp (z1, z2) == 0; } -#include "m-string.h" static void my_mpz_str(string_t str, const mpz_t z, bool append) { char *s = mpz_get_str(NULL, 10, z); @@ -51,9 +48,13 @@ static void my_mpz_str(string_t str, const mpz_t z, bool append) free(s); } +START_COVERAGE +LIST_DEF(uint, unsigned int) LIST_DEF(mpz, mpz_t, (INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear), \ OUT_STR(my_mpz_out_str), IN_STR(my_mpz_in_str), EQUAL(my_mpz_equal_p), \ GET_STR(my_mpz_str))) +END_COVERAGE +#define LIST_UINT_OPLIST LIST_OPLIST(uint) static void test_uint(void) { diff --git a/tests/test-mrbtree.c b/tests/test-mrbtree.c index 579a1c13..f8f96787 100644 --- a/tests/test-mrbtree.c +++ b/tests/test-mrbtree.c @@ -24,10 +24,12 @@ #include // For testing purpose only. #include "m-rbtree.h" +START_COVERAGE RBTREE_DEF(uint, unsigned int) -#define UINT_OPLIST RBTREE_OPLIST(uint) - RBTREE_DEF(float, float) +END_COVERAGE + +#define UINT_OPLIST RBTREE_OPLIST(uint) #define FLOAT_OP RBTREE_OPLIST(float) static void test_uint(void) diff --git a/tests/test-mtuple.c b/tests/test-mtuple.c index 6aa8edab..5ef4c912 100644 --- a/tests/test-mtuple.c +++ b/tests/test-mtuple.c @@ -26,9 +26,11 @@ #include "m-string.h" #include "m-tuple.h" +START_COVERAGE TUPLE_DEF2(pair, (key, string_t, (INIT(string_init), INIT_SET(string_init_set), SET(string_set), CLEAR(string_clear))), (value, mpz_t, (INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear) ))) +END_COVERAGE // No cmp defined TUPLE_DEF2(triple, diff --git a/tests/test-mvariant.c b/tests/test-mvariant.c index ba072daf..03b72d07 100644 --- a/tests/test-mvariant.c +++ b/tests/test-mvariant.c @@ -26,9 +26,11 @@ #include "m-string.h" #include "m-variant.h" +START_COVERAGE VARIANT_DEF2(pair, (key, int, M_DEFAULT_OPLIST), (value, float, M_DEFAULT_OPLIST) ) +END_COVERAGE static void test_pair(void) {