From 672c2d509d1e6a066ef68cb64d4e3f5706bb38af Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 10 Jul 2017 17:35:16 +0200 Subject: [PATCH] Update the way of working of the coverage so that it produces more useful information about the line coveraged, and avoid expanding low level macros. --- tests/Makefile | 6 +++--- tests/test-malgo.c | 1 + tests/test-marray.c | 2 +- tests/test-mdict.c | 21 +++++++++++---------- tests/test-milist.c | 1 + tests/test-mmempool.c | 1 + tests/test-mrbtree.c | 2 +- tests/test-mshared.c | 29 ++++++++++++++++++++++++++--- tests/test-msnapshot.c | 4 ++++ tests/test-mtuple.c | 1 + tests/test-mvariant.c | 1 + 11 files changed, 51 insertions(+), 18 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 65204490..4ace8d57 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,6 @@ #NOTE: GMP is only used for the tests CC=gcc -std=c99 -WCFLAGS=-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="" +WCFLAGS=-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 XCFLAGS= CFLAGS=$(WCFLAGS) $(XCFLAGS) CPPFLAGS=-I.. @@ -96,11 +96,11 @@ 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 }' |perl -pi -e 's/;/;\n/g ; s/}/}\n/g ; s/{/{\n/g' > coverage-dir/middle.c + $(CC) -E -std=c99 -I. -I.. -DNDEBUG -DWITHIN_COVERAGE $< |grep -v '^#' |awk ' /END_COVERAGE/ { printit=0} printit { print } /START_COVERAGE/ { printit=1 }' |perl -pi -e 's/;/;\n/g ; s/}/}\n/g ; s/{/{\n/g' > coverage-dir/middle.c cat coverage-dir/first.c coverage-dir/middle.c coverage-dir/end.c > coverage-dir/$< coverage-test/%.c: coverage-dir/%.c - $(CC) -ftest-coverage -fprofile-arcs -g -I.. $< -o $(EXE) $(LDFLAGS) + $(CC) -ftest-coverage -fprofile-arcs -g -I. -I.. $< -o $(EXE) $(LDFLAGS) $(EXE) gcov $$(basename $< .c).gcno diff --git a/tests/test-malgo.c b/tests/test-malgo.c index 1c03e50e..4914dfe3 100644 --- a/tests/test-malgo.c +++ b/tests/test-malgo.c @@ -7,6 +7,7 @@ ARRAY_DEF(int, int) LIST_DEF(int, int) LIST_DEF(string, string_t, STRING_OPLIST) +#include "coverage.h" START_COVERAGE ALGO_DEF(algo_array, ARRAY_OPLIST(int)) diff --git a/tests/test-marray.c b/tests/test-marray.c index 2b3b6793..047bd874 100644 --- a/tests/test-marray.c +++ b/tests/test-marray.c @@ -49,9 +49,9 @@ static void my_mpz_str(string_t str, const mpz_t z, bool append) free(s); } +#include "coverage.h" 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), \ diff --git a/tests/test-mdict.c b/tests/test-mdict.c index 25d71b63..6438792f 100644 --- a/tests/test-mdict.c +++ b/tests/test-mdict.c @@ -27,15 +27,6 @@ #include "m-array.h" #include "m-string.h" -START_COVERAGE -DICT_DEF2(str, string_t, STRING_OPLIST, string_t, STRING_OPLIST) -END_COVERAGE - -DICT_SET_DEF2(setstr, string_t, STRING_OPLIST) - -ARRAY_DEF(string, string_t, STRING_OPLIST) -array_string_t v_str; - static inline bool oor_equal_p(int k, unsigned char n) { return k == (int)-n-1; @@ -44,8 +35,18 @@ static inline void oor_set(int *k, unsigned char n) { *k = (int)-n-1; } -DICT_OA_DEF2(oa_int, int, M_OPEXTEND(M_DEFAULT_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)), int, M_DEFAULT_OPLIST) +#include "coverage.h" +START_COVERAGE +DICT_DEF2(str, string_t, STRING_OPLIST, string_t, STRING_OPLIST) +DICT_OA_DEF2(oa_int, int, M_OPEXTEND(M_DEFAULT_OPLIST, OOR_EQUAL(oor_equal_p), OOR_SET(oor_set M_IPTR)), int, M_DEFAULT_OPLIST) +END_COVERAGE + +DICT_SET_DEF2(setstr, string_t, STRING_OPLIST) + +/* Helper structure */ +ARRAY_DEF(string, string_t, STRING_OPLIST) +array_string_t v_str; static void init_data(int data_size) { diff --git a/tests/test-milist.c b/tests/test-milist.c index 2786c9b2..e5014af2 100644 --- a/tests/test-milist.c +++ b/tests/test-milist.c @@ -31,6 +31,7 @@ typedef struct test_s { ILIST_INTERFACE (tname, struct test_s); } test_t; +#include "coverage.h" START_COVERAGE ILIST_DEF(tname, test_t) END_COVERAGE diff --git a/tests/test-mmempool.c b/tests/test-mmempool.c index a5615b7c..e79f90e6 100644 --- a/tests/test-mmempool.c +++ b/tests/test-mmempool.c @@ -26,6 +26,7 @@ #include "m-mempool.h" +#include "coverage.h" START_COVERAGE MEMPOOL_DEF(uint, unsigned int) END_COVERAGE diff --git a/tests/test-mrbtree.c b/tests/test-mrbtree.c index 07cf0938..a9951289 100644 --- a/tests/test-mrbtree.c +++ b/tests/test-mrbtree.c @@ -40,7 +40,7 @@ static void uint_get_str(string_t str, unsigned int u, bool append) (append ? string_cat_printf : string_printf) (str, "%u", u); } - +#include "coverage.h" START_COVERAGE RBTREE_DEF(uint, unsigned int, M_OPEXTEND(M_DEFAULT_OPLIST, IN_STR(uint_in_str M_IPTR), OUT_STR(uint_out_str), GET_STR(uint_get_str)) ) RBTREE_DEF(float, float) diff --git a/tests/test-mshared.c b/tests/test-mshared.c index d33727cb..30dcf156 100644 --- a/tests/test-mshared.c +++ b/tests/test-mshared.c @@ -1,12 +1,35 @@ +/* + * Copyright (c) 2017, Patrick Pelissier + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include #include #include "m-shared.h" +#include "coverage.h" +START_COVERAGE SHARED_PTR_DEF(int, int) - -#include - SHARED_PTR_DEF(mpz, mpz_t, M_CLASSIC_OPLIST(mpz)) +END_COVERAGE static int f(const shared_int_t p) { diff --git a/tests/test-msnapshot.c b/tests/test-msnapshot.c index bfc85f58..e06381a9 100644 --- a/tests/test-msnapshot.c +++ b/tests/test-msnapshot.c @@ -21,11 +21,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include // For testing purpose only. + #include "m-snapshot.h" +#include "coverage.h" +START_COVERAGE SNAPSHOT_DEF(uint, unsigned int) SNAPSHOT_DEF(mpz, mpz_t, (INIT(mpz_init), INIT_SET(mpz_init_set), SET(mpz_set), CLEAR(mpz_clear))) +END_COVERAGE static void test_uint(void) { diff --git a/tests/test-mtuple.c b/tests/test-mtuple.c index e56bca87..e53992ae 100644 --- a/tests/test-mtuple.c +++ b/tests/test-mtuple.c @@ -26,6 +26,7 @@ #include "m-string.h" #include "m-tuple.h" +#include "coverage.h" START_COVERAGE TUPLE_DEF2(pair, (key, string_t, (INIT(string_init), INIT_SET(string_init_set), SET(string_set), CLEAR(string_clear))), diff --git a/tests/test-mvariant.c b/tests/test-mvariant.c index 0558414b..50fe64e5 100644 --- a/tests/test-mvariant.c +++ b/tests/test-mvariant.c @@ -26,6 +26,7 @@ #include "m-string.h" #include "m-variant.h" +#include "coverage.h" START_COVERAGE VARIANT_DEF2(pair, (key, int, M_DEFAULT_OPLIST),