Description: Start up daemon for test to run
 Upstream runs a couple of test on make check. This command is both dangerous
 (it would run vanish on localhost) and will not on a build server.
 .
 We start up the daemon automatically and make sure it has been launched. AS
 soon as we exit the script, the daemon will be brought down again.
Author: Örjan Persson <orange@fobie.net>
Last-Update: 2010-02-14
Index: tokyotyrant/Makefile.in
===================================================================
--- tokyotyrant.orig/Makefile.in	2010-02-15 01:03:24.000000000 +0100
+++ tokyotyrant/Makefile.in	2010-02-15 01:40:41.000000000 +0100
@@ -61,6 +61,11 @@
 RUNENV = @MYLDLIBPATHENV@=.
 POSTCMD = @MYPOSTCMD@
 
+# Test configuration
+test_start_stop = 1
+test_host = /tmp/ttserver-test.sock
+test_port = 0
+test_pid = /tmp/ttserver-test.pid
 
 
 #================================================================
@@ -168,48 +173,62 @@
 
 
 check :
-	$(RUNENV) $(RUNCMD) ./tcrmgr version
-	$(RUNENV) $(RUNCMD) ./tcrtest write -cnum 5 -tout 5 -rnd 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrtest write -cnum 5 -tout 5 -nr -rnd 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrtest write -cnum 5 -tout 5 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrtest read -cnum 5 -tout 5 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrtest read -cnum 5 -tout 5 -mul 5 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrtest remove -cnum 5 -tout 5 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrtest rcat -cnum 5 -tout 5 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrtest rcat -cnum 5 -tout 5 -shl 50 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrmgr vanish 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrtest rcat -cnum 5 -tout 5 -dad 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrtest rcat -cnum 5 -tout 5 -ext putcat -xlr 127.0.0.1 50000
-	$(RUNENV) $(RUNCMD) ./tcrtest misc -cnum 5 -tout 5 127.0.0.1 5000
-	$(RUNENV) $(RUNCMD) ./tcrtest wicked -cnum 5 -tout 5 127.0.0.1 5000
-	$(RUNENV) $(RUNCMD) ./tcrmgr inform 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrmgr vanish 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrmttest write -tnum 5 127.0.0.1 5000
-	$(RUNENV) $(RUNCMD) ./tcrmttest read -tnum 5 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrmttest remove -tnum 5 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrmttest write -tnum 5 -ext putcat -rnd 127.0.0.1 5000
-	$(RUNENV) $(RUNCMD) ./tcrmttest typical -tnum 5 127.0.0.1 5000
-	$(RUNENV) $(RUNCMD) ./tcrmgr vanish 127.0.0.1
-	$(RUNENV) $(RUNCMD) ./tcrmgr put 127.0.0.1 one first
-	$(RUNENV) $(RUNCMD) ./tcrmgr put 127.0.0.1 two second
-	$(RUNENV) $(RUNCMD) ./tcrmgr put -dk 127.0.0.1 three third
-	$(RUNENV) $(RUNCMD) ./tcrmgr put -dc 127.0.0.1 three third
-	$(RUNENV) $(RUNCMD) ./tcrmgr put -dc 127.0.0.1 three third
-	$(RUNENV) $(RUNCMD) ./tcrmgr put -dc 127.0.0.1 three third
-	$(RUNENV) $(RUNCMD) ./tcrmgr put 127.0.0.1 four fourth
-	$(RUNENV) $(RUNCMD) ./tcrmgr put -dk 127.0.0.1 five fifth
-	$(RUNENV) $(RUNCMD) ./tcrmgr out 127.0.0.1 one
-	$(RUNENV) $(RUNCMD) ./tcrmgr out 127.0.0.1 two
-	$(RUNENV) $(RUNCMD) ./tcrmgr get 127.0.0.1 three > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr get 127.0.0.1 four > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr get 127.0.0.1 five > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr mget 127.0.0.1 one two three four five > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr misc 127.0.0.1 putlist six sixth seven seventh
-	$(RUNENV) $(RUNCMD) ./tcrmgr misc 127.0.0.1 outlist six
-	$(RUNENV) $(RUNCMD) ./tcrmgr misc 127.0.0.1 getlist three four five six > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr list -pv 127.0.0.1 > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr list -pv -fm f 127.0.0.1 > check.out
-	$(RUNENV) $(RUNCMD) ./tcrmgr http -ih http://127.0.0.1:1978/five > check.out
+	if [ $(test_start_stop) -eq 1 ]; then \
+		$(RUNENV); \
+		export LD_LIBRARY_PATH; \
+		start-stop-daemon -v -S -p $(test_pid) -d `pwd` --exec `pwd`/ttserver \
+			-- -host $(test_host) -port $(test_port) \
+			   -ld -dmn -pid $(test_pid) || exit 1; \
+		\
+		trap "start-stop-daemon -v -K -R TERM/30/KILL/5 -p $(test_pid) && rm -f $(test_pid)" 0; \
+	fi; \
+	\
+	for i in `seq 5`; do \
+		$(RUNENV) ./tcrmgr inform -port $(test_port) $(test_host) > /dev/null && break; \
+		sleep $$i; \
+	done; \
+	\
+	$(RUNENV) $(RUNCMD) ./tcrmgr version; \
+	$(RUNENV) $(RUNCMD) ./tcrtest write -port $(test_port) -cnum 5 -tout 5 -rnd $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest write -port $(test_port) -cnum 5 -tout 5 -nr -rnd $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest write -port $(test_port) -cnum 5 -tout 5 $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest read -port $(test_port) -cnum 5 -tout 5 $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrtest read -port $(test_port) -cnum 5 -tout 5 -mul 5 $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrtest remove -port $(test_port) -cnum 5 -tout 5 $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrtest rcat -port $(test_port) -cnum 5 -tout 5 $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest rcat -port $(test_port) -cnum 5 -tout 5 -shl 50 $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr vanish -port $(test_port) $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrtest rcat -port $(test_port) -cnum 5 -tout 5 -dad $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest rcat -port $(test_port) -cnum 5 -tout 5 -ext putcat -xlr $(test_host) 50000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest misc -port $(test_port) -cnum 5 -tout 5 $(test_host) 5000; \
+	$(RUNENV) $(RUNCMD) ./tcrtest wicked -port $(test_port) -cnum 5 -tout 5 $(test_host) 5000; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr inform -port $(test_port) $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrmgr vanish -port $(test_port) $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrmttest write -port $(test_port) -tnum 5 $(test_host) 5000; \
+	$(RUNENV) $(RUNCMD) ./tcrmttest read -port $(test_port) -tnum 5 $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrmttest remove -port $(test_port) -tnum 5 $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrmttest write -port $(test_port) -tnum 5 -ext putcat -rnd $(test_host) 5000; \
+	$(RUNENV) $(RUNCMD) ./tcrmttest typical -port $(test_port) -tnum 5 $(test_host) 5000; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr vanish -port $(test_port) $(test_host); \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) $(test_host) one first; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) $(test_host) two second; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) -dk $(test_host) three third; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) -dc $(test_host) three third; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) -dc $(test_host) three third; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) -dc $(test_host) three third; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) $(test_host) four fourth; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr put -port $(test_port) -dk $(test_host) five fifth; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr out -port $(test_port) $(test_host) one; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr out -port $(test_port) $(test_host) two; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr get -port $(test_port) $(test_host) three > check.out; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr get -port $(test_port) $(test_host) four > check.out; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr get -port $(test_port) $(test_host) five > check.out; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr mget -port $(test_port) $(test_host) one two three four five > check.out; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr misc -port $(test_port) $(test_host) putlist six sixth seven seventh; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr misc -port $(test_port) $(test_host) outlist six; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr misc -port $(test_port) $(test_host) getlist three four five six > check.out; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr list -port $(test_port) -pv $(test_host) > check.out; \
+	$(RUNENV) $(RUNCMD) ./tcrmgr list -port $(test_port) -pv -fm f $(test_host) > check.out; \
 	rm -rf ulog ; mkdir -p ulog
 	$(RUNENV) $(RUNCMD) ./ttultest write -lim 10000 ulog 5000
 	$(RUNENV) $(RUNCMD) ./ttultest write -lim 10000 -as ulog 5000
