GTESTER = gtester

TEST_PROGS =

test: all
	@test -z "$(TEST_PROGS)" || \
	 G_SLICE=debug-blocks $(GTESTER) --verbose $(TEST_PROGS)

if GDB_ENABLED

test-gdb: all
	@test -z "$(TEST_PROGS)" || \
	 for test_prog in $(TEST_PROGS) ; do \
	   G_SLICE=debug-blocks $(GTESTER) --verbose $$test_prog || { \
	     G_SLICE=debug-blocks \
	       libtool --mode=execute gdb --ex "run --verbose" $$test_prog ; \
	     exit 1 ; \
	   } \
	 done

else

test-gdb:
	@echo "You need GDB"

endif # GDB_ENABLED

if VALGRIND_ENABLED

test-valgrind: all
	@test -z "$(TEST_PROGS)" || \
	 for test_prog in $(TEST_PROGS) ; do \
	   if test -e valgrind-$${test_prog}.log; then \
	     unlink valgrind-$${test_prog}.log; \
	   fi ; \
	   G_SLICE=always-malloc G_DEBUG=gc-friendly,resident-modules \
	     libtool --mode=execute valgrind --leak-check=full \
	     --leak-resolution=high --num-callers=20 \
	     --suppressions=$(top_srcdir)/tests/valgrind.suppressions \
	     --log-file=valgrind-$${test_prog}.log $$test_prog || exit 1 ; \
	 done

test-callgrind: all
	@test -z "$(TEST_PROGS)" || \
	 for test_prog in $(TEST_PROGS) ; do \
	   if test -e callgrind-$${test_prog}.log; then \
	     unlink callgrind-$${test_prog}.log; \
	   fi ; \
	   libtool --mode=execute valgrind --tool=callgrind \
	     --callgrind-out-file=callgrind-$${test_prog}.log \
	     --log-file=/dev/null $$test_prog || exit 1 ; \
	 done

else

test-valgrind test-callgrind:
	@echo "You need Valgrind"

endif # VALGRIND_ENABLED

generate-report: all
	@test -z "$(TEST_PROGS)" || \
	 G_SLICE=debug-blocks $(GTESTER) $(GTESTER_ARGS) $(TEST_PROGS)

CLEANFILES = callgrind-*.log valgrind-*.log

.PHONY: test test-gdb test-valgrind test-callgrind generate-report
