Commit cac5d927 by Ramsay Jones

Add support for running the tests via valgrind

Add some makefile targets, which use valgrind's memcheck tool to
run the tests, in order to help diagnose memory problems in the
library.

In addition, we enable the '--leak-check' option to report on any
memory leaks. However, unlike the other memory problems reported
by memcheck, memory leak reports do not result in an error exit
from valgrind. (So memory leaks are reported on stderr, but don't
halt the test run.)

A suppressions file (tests.supp) is included since libz triggers
some false positives.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
parent 04e88240
...@@ -44,6 +44,7 @@ TEST_OBJ = $(patsubst %.c,%.o,\ ...@@ -44,6 +44,7 @@ TEST_OBJ = $(patsubst %.c,%.o,\
$(wildcard tests/t[0-9][0-9][0-9][0-9]-*.c)) $(wildcard tests/t[0-9][0-9][0-9][0-9]-*.c))
TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ)) TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ))
TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE)) TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE))
TEST_VAL = $(patsubst %.exe,%.val,$(TEST_EXE))
ifndef NO_OPENSSL ifndef NO_OPENSSL
SHA1_HEADER = <openssl/sha.h> SHA1_HEADER = <openssl/sha.h>
...@@ -82,6 +83,9 @@ apidocs: ...@@ -82,6 +83,9 @@ apidocs:
test: $(GIT_LIB) test: $(GIT_LIB)
@$(MAKE) -C tests --no-print-directory test @$(MAKE) -C tests --no-print-directory test
valgrind: $(GIT_LIB)
@$(MAKE) -C tests --no-print-directory valgrind
sparse: sparse:
cgcc -no-compile $(ALL_CFLAGS) $(SPARSE_FLAGS) $(SRC_C) cgcc -no-compile $(ALL_CFLAGS) $(SPARSE_FLAGS) $(SRC_C)
...@@ -116,7 +120,7 @@ $(GIT_LIB): $(OBJS) ...@@ -116,7 +120,7 @@ $(GIT_LIB): $(OBJS)
$(AR) $(GIT_LIB) $(OBJS) $(AR) $(GIT_LIB) $(OBJS)
$(RANLIB) $(GIT_LIB) $(RANLIB) $(GIT_LIB)
$(TEST_OBJ) $(TEST_EXE) $(TEST_RUN): $(TEST_OBJ) $(TEST_EXE) $(TEST_RUN) $(TEST_VAL):
@$(MAKE) -C tests --no-print-directory \ @$(MAKE) -C tests --no-print-directory \
OS=$(OS) NO_OPENSSL=$(NO_OPENSSL) $(@F) OS=$(OS) NO_OPENSSL=$(NO_OPENSSL) $(@F)
...@@ -125,7 +129,7 @@ libgit2.pc: libgit2.pc.in ...@@ -125,7 +129,7 @@ libgit2.pc: libgit2.pc.in
.PHONY: all .PHONY: all
.PHONY: clean .PHONY: clean
.PHONY: test $(TEST_RUN) $(TEST_EXE) $(TEST_OBJ) .PHONY: test $(TEST_VAL) $(TEST_RUN) $(TEST_EXE) $(TEST_OBJ)
.PHONY: apidocs .PHONY: apidocs
.PHONY: install-headers .PHONY: install-headers
.PHONY: install uninstall .PHONY: install uninstall
......
...@@ -9,6 +9,8 @@ CFLAGS = -g -O2 -Wall ...@@ -9,6 +9,8 @@ CFLAGS = -g -O2 -Wall
LIBS = -L.. -lgit2 -lz LIBS = -L.. -lgit2 -lz
OS = unix OS = unix
VFLAGS = -q --error-exitcode=1 --leak-check=yes --suppressions=../tests.supp
CRYPTO_LIB = -lcrypto CRYPTO_LIB = -lcrypto
EXTRA_LIBS = EXTRA_LIBS =
...@@ -21,6 +23,7 @@ TEST_OBJ = $(patsubst %.c,%.o,\ ...@@ -21,6 +23,7 @@ TEST_OBJ = $(patsubst %.c,%.o,\
$(wildcard t[0-9][0-9][0-9][0-9]-*.c)) $(wildcard t[0-9][0-9][0-9][0-9]-*.c))
TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ)) TEST_EXE = $(patsubst %.o,%.exe,$(TEST_OBJ))
TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE)) TEST_RUN = $(patsubst %.exe,%.run,$(TEST_EXE))
TEST_VAL = $(patsubst %.exe,%.val,$(TEST_EXE))
ifndef NO_OPENSSL ifndef NO_OPENSSL
EXTRA_LIBS += $(CRYPTO_LIB) EXTRA_LIBS += $(CRYPTO_LIB)
...@@ -40,6 +43,8 @@ clean: ...@@ -40,6 +43,8 @@ clean:
test: $(TEST_RUN) test: $(TEST_RUN)
valgrind: $(TEST_VAL)
.c.o: .c.o:
$(CC) $(ALL_CFLAGS) -c $< -o $@ $(CC) $(ALL_CFLAGS) -c $< -o $@
...@@ -79,6 +84,15 @@ $(TEST_RUN): %.run: %.exe ...@@ -79,6 +84,15 @@ $(TEST_RUN): %.run: %.exe
else rmdir $$t; exit 1; \ else rmdir $$t; exit 1; \
fi fi
$(TEST_VAL): %.val: %.exe
@t=trash-$(<F) && \
mkdir $$t && \
if (cd $$t && valgrind $(VFLAGS) ../$<); \
then rm -rf $$t; \
else rmdir $$t; exit 1; \
fi
.PHONY: all .PHONY: all
.PHONY: clean .PHONY: clean
.PHONY: test $(TEST_RUN) .PHONY: test $(TEST_RUN)
.PHONY: $(TEST_VAL)
{
ignore-zlib-cond
Memcheck:Cond
obj:*libz.so*
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment