From 1f447688bc8e078e3af640502f595321c40abbae Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 2 Dec 2016 18:10:13 +1030 Subject: [PATCH] test: make generic driver for unit tests. Not just in daemon. This fixes 'make check' when it tries to run 'make wire-tests' Signed-off-by: Rusty Russell --- Makefile | 12 ++++++++++-- bitcoin/Makefile | 6 ++---- daemon/test/Makefile | 6 +----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 86d2183fb..79c152307 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,11 @@ BOLTVERSION := master # If you don't have (working) valgrind. #NO_VALGRIND := 1 +ifneq ($(NO_VALGRIND),1) +VALGRIND=valgrind -q --error-exitcode=7 +VALGRIND_TEST_ARGS = --track-origins=yes --leak-check=full --show-reachable=yes +endif + # This is where we add new features as bitcoin adds them. FEATURES := @@ -192,14 +197,14 @@ $(CCAN_OBJS) $(CDUMP_OBJS) $(HELPER_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o) c $(HELPER_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o): $(BITCOIN_HEADERS) $(CORE_HEADERS) $(CCAN_HEADERS) $(GEN_HEADERS) test-protocol: test/test_protocol - set -e; TMP=`mktemp`; [ -n "$(NO_VALGRIND)" ] || PREFIX="valgrind -q --error-exitcode=7"; for f in test/commits/*.script; do if ! $$PREFIX test/test_protocol < $$f > $$TMP; then echo "test/test_protocol < $$f FAILED" >&2; exit 1; fi; diff -u $$TMP $$f.expected; done; rm $$TMP + set -e; TMP=`mktemp`; for f in test/commits/*.script; do if ! $(VALGRIND) test/test_protocol < $$f > $$TMP; then echo "test/test_protocol < $$f FAILED" >&2; exit 1; fi; diff -u $$TMP $$f.expected; done; rm $$TMP doc/protocol-%.svg: test/test_protocol test/test_protocol --svg < test/commits/$*.script > $@ protocol-diagrams: $(patsubst %.script, doc/protocol-%.svg, $(notdir $(wildcard test/commits/*.script))) -check: test-protocol bitcoin-tests +check: test-protocol include bitcoin/Makefile include wire/Makefile @@ -329,6 +334,9 @@ clean: daemon-clean wire-clean include daemon/Makefile +unittest/%: % + $(VALGRIND) $(VALGRIND_TEST_ARGS) $* + ccan-tal.o: $(CCANDIR)/ccan/tal/tal.c $(CC) $(CFLAGS) -c -o $@ $< ccan-tal-str.o: $(CCANDIR)/ccan/tal/str/str.c diff --git a/bitcoin/Makefile b/bitcoin/Makefile index b066db0a5..28e67a968 100644 --- a/bitcoin/Makefile +++ b/bitcoin/Makefile @@ -11,8 +11,6 @@ $(BITCOIN_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_TEST_OBJS): $(CCAN_HEADERS) $(BITCOIN_HEADERS) $(BITCOIN_SRC) -VALGRIND=valgrind -q --error-exitcode=99 -VALGRIND_TEST_ARGS = --track-origins=yes --leak-check=full --show-reachable=yes +check: bitcoin-tests -bitcoin-tests: $(BITCOIN_TEST_PROGRAMS) - set -e; for f in $(BITCOIN_TEST_PROGRAMS); do $(VALGRIND) $(VALGRIND_TEST_ARGS) $$f; done +bitcoin-tests: $(BITCOIN_TEST_PROGRAMS:%=unittest/%) diff --git a/daemon/test/Makefile b/daemon/test/Makefile index 58e18bbd2..b3b38d5ee 100644 --- a/daemon/test/Makefile +++ b/daemon/test/Makefile @@ -82,11 +82,7 @@ $(DAEMON_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) libsecp256k1.a utils.o $(DAEMON_TEST_OBJS): $(DAEMON_HEADERS) $(DAEMON_JSMN_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(DAEMON_GEN_HEADERS) $(CCAN_HEADERS) -VALGRIND=valgrind -q --error-exitcode=99 -VALGRIND_TEST_ARGS = --track-origins=yes --leak-check=full --show-reachable=yes - -daemon-unit-tests: $(DAEMON_TEST_PROGRAMS) - set -e; for f in $(DAEMON_TEST_PROGRAMS); do $(VALGRIND) $(VALGRIND_TEST_ARGS) $$f; done +daemon-unit-tests: $(DAEMON_TEST_PROGRAMS:%=unittest/%) daemon-tests: daemon-unit-tests daemon-all-test