increase test coverage
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 16 Jan 2023 13:28:13 +0000 (14:28 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 16 Jan 2023 13:28:13 +0000 (14:28 +0100)
compress.c
makefile

index 4b91bbf02e73dfbd38626dc76889c31f734ba466..bd343842da026aae79be2baa0e68368931d4f090 100644 (file)
@@ -760,10 +760,14 @@ int main (int argc, char *argv[])
 // test: compress.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
 // test: compress.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
 // test: compress.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
+// test: compress.exe -v 2>&1 | grep -q 'missing verbose level'
+// test: compress.exe -c -i compress.c 2>&1 | grep -q 'missing file'
+// test: compress.exe -c -v 4 -i compress.c -o compress.mz | grep -q "Occurence table"
 // test: compress.exe -c -i compress.c -o compress.mz
 // test: ls -sS1 compress.c compress.mz | tail -1 | grep compress.mz
 // test: compress.exe -d -i compress.mz -o tmp.c
-// test: cmp compress.c tmp.c
-// test: rm compress.mz tmp.c
+// test: cmp compress.c tmp.c; x=$?; rm compress.mz tmp.c; test x$x = x0
+// test: compress.exe -c -i test/compress.c -o compress.mz 2>&1 | grep "can't open file"
+// test: compress.exe -c -i compress.c -o test/compress.mz 2>&1 | grep "can't open file"
 
 /* vim: set ts=4 sw=4 et: */
index 997c6d7fa56281800ee0b62f1d0251141c4af1bc..c4b250ed69c7c8fbb1af26e2d41eaaa4fdd0c9bd 100644 (file)
--- a/makefile
+++ b/makefile
@@ -11,19 +11,20 @@ OFLAGS  = -O4 -Os
 #OFLAGS += -malign-double
 CFLAGS += -W -Wall -Wextra -g
 CFLAGS += -std=c99 -D_XOPEN_SOURCE=500
-CFLAGS += $(OFLAGS) $(INCLUDES)
-LDFLAGS += -g
+CFLAGS += $(OFLAGS) $(INCLUDES) $(GCOV)
+LDFLAGS += -g $(GCOV)
 
 # Targets
 
 ALLEXE  =
 ALLEXE += compress
-ALLEXE += skel
+#ALLEXE += skel
 
 SHELL = bash
 
-MAKE = mingw32-make
+#MAKE = mingw32-make
 MAKEFLAGS += -s
+include $(wildcard .makefile)
 
 # Functions
 
@@ -43,11 +44,6 @@ VALID = $(call TITLE, $(1)) && $(2) && $(call PASS, SUCCESS) || { $(call FAIL, F
 all: depends
        $(MAKE) $(ALLEXE:%=%.exe)
 
-alltests: all
-       $(MAKE) $(addprefix test_,$(ALLEXE:%.exe=%))
-
-depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
-
 count:
        wc $(wildcard *.c *.h) $(MAKEFILE_LIST)
 
@@ -57,17 +53,43 @@ clean:
        rm -f clean $(wildcard *.d *.ld *.log *.o *.test *~ .exec_*)
        $(call PASS, SUCCESS)
 
+depends: $(patsubst %.c, %.d, $(wildcard *.c)) $(patsubst %, %.ld, $(ALLEXE))
+
+gcovs:
+       $(MAKE) $(addprefix gcov_,$(ALLEXE))
+
 purge: clean
        $(call TITLE, "Purging")
        touch purge
-       rm -f purge $(ALLEXE) $(shell [ -f .targets ] && { cat .targets | sort | uniq; echo .targets; })
+       rm -f purge $(ALLEXE:%=%.exe)
        $(call PASS, SUCCESS)
 
+valgrinds:
+       $(MAKE) $(addprefix valgrind_,$(ALLEXE))
+
+wipe: purge
+       $(call TITLE, "Wiping")
+       touch wipe
+       rm -f wipe $(wildcard *.gcda *.gcno *.gcov)
+       $(call PASS, SUCCESS)
+
+tests: all
+       $(MAKE) $(addprefix test_,$(ALLEXE))
+
 ## Main rules
 
 include $(wildcard *.d)
 include $(wildcard *.ld)
 
+gcov_%:
+       $(MAKE) purge
+       GCOV="-fprofile-arcs -ftest-coverage -O0" $(MAKE)
+       $(MAKE) test_$(@:gcov_%=%)
+       gcov `sed -e 's/\.exe:/.c/;s/\.o/.c/g' $(@:gcov_%=%.ld)`
+       touch gcov
+       rm -f gcov $(wildcard *.gcda *.gcno)
+       $(MAKE) purge
+
 %.test: %.c
        $(call TITLE, "Building $@")
 #      awk '/\/\* *test:.*\*\// { sub(/^.*\/\* *test: */, ""); sub(/ *\*\/.*$$/, ""); print }' $< > $@
@@ -82,12 +104,12 @@ test_%: %.test %.exe
          [ $$? -eq 0 ] && echo -e "\033[1;32mSUCCESS\033[0;0m" \
                        || { echo -e "\033[1;31mFAILED\033[0;0m"; RC=1; }; \
        done; \
-       test "$$RC" -ne 1 
+       test "$$RC" -ne 1
 
-valgrind_%: %
+valgrind_%: %.exe
        VALGRIND="valgrind -v --leak-check=full --show-reachable=yes --log-fd=2"; \
        export VALGRIND; \
-       $(MAKE) test_$<
+       $(MAKE) $(@:valgrind_%=test_%)
 
 %.d: %.c
        $(call TITLE, "Building $@")
@@ -114,7 +136,7 @@ valgrind_%: %
 
 ## Phony
 
-.PHONY: clean count purge
+.PHONY: all clean count depends gcovs purge tests
 
 ## Precious