From d127dd5cab51a869d6f6bb6c2a0860c458d3fecd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 21 Feb 2022 23:00:24 +0100 Subject: Add coverage test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 7 +++++++ config-coverage-gcc.mk | 11 +++++++++++ test.c | 8 +++++--- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 config-coverage-gcc.mk diff --git a/Makefile b/Makefile index be1a6ca..2660901 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ CONFIGFILE = config.mk include $(CONFIGFILE) + BIN =\ bsum\ b2sum @@ -22,6 +23,11 @@ ALIASES =\ b384sum\ b512sum +SRC =\ + $(OBJ:.o=.c)\ + $(HDR)\ + test.c + # Known answers tests KAT_FILES =\ kat/blake2b\ @@ -31,6 +37,7 @@ KAT_FILES =\ kat/blake2xb\ kat/blake2xs + all: $(BIN) test $(OBJ): $(HDR) diff --git a/config-coverage-gcc.mk b/config-coverage-gcc.mk new file mode 100644 index 0000000..a505279 --- /dev/null +++ b/config-coverage-gcc.mk @@ -0,0 +1,11 @@ +CONFIGFILE_PROPER = config.mk +include $(CONFIGFILE_PROPER) + +CC = $(CC_PREFIX)gcc -std=c99 +GCOV = gcov + +CFLAGS = -g -O0 -pedantic -fprofile-arcs -ftest-coverage +LDFLAGS = -lblake -lgcov -fprofile-arcs + +coverage: check + $(GCOV) -pr $(SRC) 2>&1 diff --git a/test.c b/test.c index 8f66b0e..3bd23ef 100644 --- a/test.c +++ b/test.c @@ -235,20 +235,22 @@ hashx(unsigned char **msg, size_t msglen, size_t *msgsize, ERROR("Internal test error: %s\n", strerror(errno)); /* $covered$ */ if (!pid) { + /* $covered{$ */ close(input_pipe[1]); close(output_pipe[0]); if (input_pipe[0] != STDIN_FILENO) { if (dup2(input_pipe[0], STDIN_FILENO) != STDIN_FILENO) - ERROR("Internal test error: %s\n", strerror(errno)); /* $covered$ */ + ERROR("Internal test error: %s\n", strerror(errno)); close(input_pipe[0]); } if (output_pipe[1] != STDOUT_FILENO) { if (dup2(output_pipe[1], STDOUT_FILENO) != STDOUT_FILENO) - ERROR("Internal test error: %s\n", strerror(errno)); /* $covered$ */ + ERROR("Internal test error: %s\n", strerror(errno)); close(output_pipe[1]); } execv(argv[0], (void *const)argv); - ERROR("Internal test error: %s\n", strerror(errno)); /* $covered$ */ + ERROR("Internal test error: %s\n", strerror(errno)); + /* $covered}$ */ } else { close(input_pipe[0]); -- cgit v1.2.3-70-g09d2