#
#   userver -- a fairly simple web server designed for experimentation.
#   Copyright (C) 2003  Hewlett-Packard Company
#   Contributed by Tim Brecht <brecht@cs.uwaterloo.ca>
#   Partially based on servers by: 
#      David Mosberger <david.mosberger@hp.com> and
#      Abhishek Chandra <abhishek@cs.umass.edu>
#   See AUTHORS file for list of contributions.
#
#   This file is part of userver, a simple web server designed for
#   performance experiments.
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License as
#   published by the Free Software Foundation; either version 2 of the
#   License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
#   02111-1307 USA
#


include Makefile.base

MAKE-GPROF      = Makefile.gprof
MAKE-NOGPROF    = Makefile.nogprof
MAKE-SEND       = Makefile.send
MAKE-SEND-GPROF = Makefile.send-gprof
BIN             = $(HOME)/bin

PGMS =  userver userver-gprof userver-send

cur: userver docs
# cur: userver-send docs

all: userver docs man

man: userver.txt userver.ps userver.pdf userver.html

userver.txt: userver.1
	groff -man -Tascii userver.1 > userver.txt

userver.ps: userver.1
	groff -man -Tps userver.1 > userver.ps

userver.pdf: userver.ps
	ps2pdf userver.ps userver.pdf

userver.html: userver.1
	man2html userver.1 > userver.html

os: FORCE
	echo os = $(OS)

userver-gprof: FORCE
	$(MAKE) -f $(MAKE-GPROF) userver-gprof

userver-send: FORCE
	$(MAKE) -f $(MAKE-SEND) userver-send

userver-send-gprof: FORCE
	$(MAKE) -f $(MAKE-SEND-GPROF) userver-send-gprof

predepend:
	touch .depend

depend: predepend userver-depend

userver-depend: predepend FORCE
	$(MAKE) -f $(MAKE-NOGPROF) userver-depend

userver-send-depend: FORCE
	$(MAKE) -f $(MAKE-SEND) userver-send-depend

userver: FORCE
	$(MAKE) -f $(MAKE-NOGPROF) userver

test: test-1.0 testall testspecial
testall: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 test11

OPTS = -D 0x0

# NOTE: because the client and server are both running on
# the same machine we have to leave a bit of extra time for
# the server to start before starting the client and a bit
# of extra time for the server to finish dumping stats, events,
# etc. after it has been killed and before starting the next
# test (otherwise the server can't bind the ip addr / port combo

test1: FORCE
	@echo "Running Basic Test Subset"
	@echo "Running test 1 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver $(OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 |& egrep 'Reply status:|Errors:'"
	@./scripts/kill-server
	sleep 4
	@echo ""

test2:  FORCE
	@echo "Running test 2 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver -C $(OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 |& egrep 'Reply status:|Errors:'"
	@./scripts/kill-server
	sleep 4
	@echo ""

test3:  FORCE
	@echo "Running test 3 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver -C --use-sendfile --use-tcp-cork $(OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 |& egrep 'Reply status:|Errors:'"
	@./scripts/kill-server
	sleep 4
	@echo ""

test4:  FORCE
	@echo "Running test 4 - should get 5000 replies and 0 errors in about 10 seconds"
	$(CSH) -c "./userver -C --use-sendfile --use-tcp-cork -c 450 -f 1000 $(OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 500 5000 |& egrep 'Reply status:|Errors:'"
	@./scripts/kill-server
	sleep 4
	@echo ""

test5:  FORCE
	@echo "Running test 5 - should get 1000 replies and 0 errors in about 10 seconds"
	$(CSH) -c "./userver -C --use-sendfile --use-tcp-cork -m 0 -e 10 -c 450 -f 1000 $(OPTS) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 100 1000 |& egrep 'Reply status:|Errors:'"
	@./scripts/kill-server
	sleep 4
	@echo ""

test6:  FORCE
	@echo "Running test 6 - should get 4000 replies and 0 errors in about 10 seconds"
	$(CSH) -c "./userver -C --use-sendfile --use-tcp-cork -m 0 -c 450 -f 1000 --use-poll $(OPTS) >& test6.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 400 4000 |& egrep 'Reply status:|Errors:'"
	@./scripts/kill-server
	sleep 4
	@echo ""

test7:  FORCE
	@echo "Running IP Address Subset"
	@echo "Running test 7 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver --ip-addr 127.0.0.1 $(OPTS) >& test7.out &"
	sleep 8
	$(CSH) -c "./scripts/run 100 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server
	sleep 8
	@echo ""

test8:  FORCE
	@echo "Running test 8 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver --ip-addr 0.0.0.0 $(OPTS) >& test8.out &"
	sleep 8
	$(CSH) -c "./scripts/run 100 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server
	sleep 8
	@echo ""

test9:  FORCE
	@echo "Running test 9 - should get 10 replies and 0 errors"
	$(CSH) -c "./userver --ip-addr 127.0.0.1:6802 $(OPTS) >& test9.out &"
	sleep 8
	$(CSH) -c "./scripts/runaddrport 127.0.0.1 6802 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server
	sleep 8
	@echo ""

test10:  FORCE
	@echo "Running test 10 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver $(OPTS) -C -c 10 -f 500 >& test10.out &"
	sleep 8
	$(CSH) -c "./scripts/runrate 100 1000 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server
	sleep 8
	@echo ""

test11:  FORCE
	@echo "Running test 11 - should get 2000 replies and 0 errors"
	$(CSH) -c "./userver $(OPTS) -C -c 100 -f 1000 >& test11.out &"
	sleep 8
	$(CSH) -c "./scripts/runrate 200 2000 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server
	sleep 8
	@echo ""

testidle: testidle1 testidle2 testidle3 testidle4

testidle1:
	@echo "Running test 1 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "deadconns $(SERVER) 6800 10 >& test1-deadconns.out"
	$(CSH) -c "./scripts/runaddr $(SERVER) 1 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

test-1.0: testnew1 testnew2 testnew3 testnew4

testnew1:
	@echo "Running test 1 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 1 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testnew2:
	@echo "Running test 2 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 10 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testnew3:
	@echo "Running test 3 - should get 100 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 100 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testnew4:
	@echo "Running test 4 - should get 1000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 1000 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

SPECIAL_OPTS = -D 0x0

testspecial: testspecial1 testspecial2 testspecial3 testspecial4 \
             testspecial5 testspecial6 testspecial7 testspecial8 \
             testspecial9 testspecial10

testspecial1:
	@echo "Running test 1 - should get 1 Not found (4xx=1) and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddruri $(SERVER) BOGUS.txt 1 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial2:
	@echo "Running test 2 - should get 1 Not found (4xx=1) and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddruri-1.0 $(SERVER) BOGUS.txt 1 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial3:
	@echo "Running test 3 - should get 10 Not found (4xx=10) and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddruri $(SERVER) BOGUS.txt 10 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial4:
	@echo "Running test 4 - should get 10 Not found (4xx=10) and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddruri-1.0 $(SERVER) BOGUS.txt 10 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial5:
	@echo "Running test 5 - should get 1 reply and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrhead $(SERVER) 1 >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial6:
	@echo "Running test 6 - should get 1 reply and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test6.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrhead-1.0 $(SERVER) 1 >& test6-httperf.out"
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial7:
	@echo "Running test 7 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test7.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrhead $(SERVER) 10 >& test7-httperf.out"
	@egrep 'Reply status:|Errors:' test7-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial8:
	@echo "Running test 8 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(SPECIAL_OPTS) >& test8.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrhead-1.0 $(SERVER) 10 >& test8-httperf.out"
	@egrep 'Reply status:|Errors:' test8-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial9:
	@echo "Running test 9 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(SPECIAL_OPTS) >& test9.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrhead $(SERVER) 10 >& test9-httperf.out"
	@egrep 'Reply status:|Errors:' test9-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspecial10:
	@echo "Running test 10 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(SPECIAL_OPTS) >& test10.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrhead-1.0 $(SERVER) 10 >& test10-httperf.out"
	@egrep 'Reply status:|Errors:' test10-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

EPOLL_BASE = -D 0x1

testepoll: testepoll1 testepoll2 testepoll3 testepoll4 testepoll5 testepoll6

testepoll1:
	@echo "Running test 1 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C --use-epoll $(EPOLL_BASE) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr $(SERVER) 10 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepoll2:
	@echo "Running test 2 - should get 1000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 200 -f 300 -m 0 -C --use-epoll $(EPOLL_BASE) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 100 1000 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepoll3:
	@echo "Running test 3 - should get 1000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 200 -f 300 -m 0 -C --use-epoll2 $(EPOLL_BASE) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 100 1000 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepoll4:
	@echo "Running test 4 - should get 15000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-epoll2 $(EPOLL_BASE) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 500 15000 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepoll5:
	@echo "Running test 5 - should get 25000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-sendfile --use-tcp-cork --use-epoll $(EPOLL_BASE) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 500 25000 >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepoll6:
	@echo "Running test 6 - should get 25000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-sendfile --use-tcp-cork --use-epoll2 $(EPOLL_BASE) >& test6.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 500 25000 >& test6-httperf.out"
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepollctlv: testepollctlv1 testepollctlv2 testepollctlv3

testepollctlv1:
	@echo "Running test 1 - should get 15000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-epoll2 --use-epoll-ctlv $(EPOLL_BASE) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 500 15000 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepollctlv2:
	@echo "Running test 2 - should get 35000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-sendfile --use-tcp-cork --use-epoll2 --use-epoll-ctlv $(EPOLL_BASE) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 750 35000 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepollctlv3:
	@echo "Running test 3 - should get 25000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 10 -C --use-sendfile --use-tcp-cork --use-epoll2 --use-epoll-ctlv $(EPOLL_BASE) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate $(SERVER) 500 25000 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testepollctlv4:
	@echo "Running test 4 - should get 2000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-sendfile --use-tcp-cork --use-epoll2 --use-epoll-ctlv $(EPOLL_BASE) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate1K $(SERVER) 100 2000 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet: testet1 testet2 testet3 testet4 testet5 testet6 testet7 testet8

testet1:
	@echo "Running test 1 - should get 1 reply and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr $(SERVER) 1 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet2:
	@echo "Running test 2 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr $(SERVER) 10 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet3:
	@echo "Running test 3 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddruri $(SERVER) docs/100K.txt 10 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet4:
	@echo "Running test 4 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 0 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddruri $(SERVER) docs/100K.txt 10 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet5:
	@echo "Running test 5 - should get 3000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 200 -f 300 -m 0 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrateuri $(SERVER) 300 3000 docs/100K.txt >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet6:
	@echo "Running test 6 - should get 1000 replies (twice) and 0 errors"
	$(CSH) -c "$(USERVER) -c 200 -f 300 -m 0 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test6.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrpersist $(SERVER) 1000 >& test6-httperf.out"
	$(CSH) -c "./scripts/runaddrpersist $(SERVER) 1000 >>& test6-httperf.out"
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet7:
	@echo "Running test 7 - should get ???? replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 200 -f 300 -m 0 -C --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test7.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrsesslog $(SERVER) 200 2000 httpspec99.log >& test7-httperf.out"
	@egrep 'Reply status:|Errors:' test7-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testet8:
	@echo "Running test 8 - should get ???? replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 200 -f 300 -m 0 -C --use-sendfile --use-tcp-cork --use-epoll2 --epoll-edge-triggered $(EPOLL_BASE) >& test8.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrsesslog $(SERVER) 300 3000 httpspec99.log >& test8-httperf.out"
	@egrep 'Reply status:|Errors:' test8-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

SPEC_BASE = -D 0x0

testspec: testspec1 testspec2 testspec3

testspec1:
	@echo "Running test 1 - should get about 7200 or 7300 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-epoll --use-sendfile --use-tcp-cork $(SPEC_BASE) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrsesslog $(SERVER) 200 2000 httpspec99.log >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspec2:
	@echo "Running test 2 - should get about 7200 or 7300 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-epoll2 --use-sendfile --use-tcp-cork $(SPEC_BASE) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrsesslog $(SERVER) 200 2000 httpspec99.log >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspec3:
	@echo "Running test 3 - should get about 7200 or 7300 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-epoll2 --use-epoll-ctlv --use-sendfile --use-tcp-cork $(SPEC_BASE) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrsesslog $(SERVER) 200 2000 httpspec99.log >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testspec4:
	@echo "Running test 4 - should get about 7200 or 7300 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 500 -f 1000 -m 0 -C --use-epoll --use-epoll-ctlv --use-sendfile --use-tcp-cork $(SPEC_BASE) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrsesslog $(SERVER) 200 2000 httpspec99.log >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testsend: testsend1 testsend2 testsend3 testsend4 testsend5


testsend1: FORCE
	@echo "Running SEND Test Subset"
	@echo "Running test 1 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver-send -B -E -Y -U -N $(OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""


testsend2: FORCE
	@echo "Running test 2 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver-send -C -B -E -Y -U -N $(OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""

testsend3: FORCE
	@echo "Running test 3 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver-send -C --use-sendfile --use-tcp-cork -B -E -Y -U -N $(OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""

testsend4: FORCE
	@echo "Running test 4 - should get 5000 replies and 0 errors in about 10 seconds"
	$(CSH) -c "./userver-send -C --use-sendfile --use-tcp-cork -c 450 -f 1000 -B -E -Y -U -N $(OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 500 5000 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""

testsend5: FORCE
	@echo "Running test 5 - should get 4000 replies and 0 errors in about 10 seconds"
	$(CSH) -c "./userver-send -C --use-sendfile --use-tcp-cork -m 0 -c 450 -f 1000 -B -E -Y -U -N $(OPTS) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 400 4000 >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""


testaperture: testaperture1 testaperture2

testaperture1: FORCE
	@echo "Running test 1 - should get 10 replies and 0 errors"
	$(CSH) -c "./userver-send -C -B -E -Y -U -N $(OPTS) --auto-accept-aperture=1 >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/run 10 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""

testaperture2: FORCE
	@echo "Running test 2 - should get 4000 replies and 0 errors in about 10 seconds"
	$(CSH) -c "./userver-send -C --use-sendfile --use-tcp-cork -m 0 -c 450 -f 1000 -B -E -Y -U -N $(OPTS) --auto-accept-aperture=10 >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 400 4000 |& egrep 'Reply status:|Errors:'"
	sleep 2
	@./scripts/kill-server-send
	sleep 2
	@echo ""


# AIO_OPTS = --ignore-fd-setsize --use-socket-aio --aio-accept-thold=10 -D 0x0 # --use-aio-wait
AIO_OPTS = --ignore-fd-setsize --aio-read-before-write --aio-read-before-accept --use-socket-aio --aio-accept-thold=10 -D 0x0 # --use-aio-wait
# AIO_OPTS =  --use-socket-aio --aio-accept-thold=10 -D 0x0

# Which client to use for remote AIO tests
# CLIENT = 15.0.119.22
CLIENT = localhost
# Which server the client will send requests to
# SERVER = 15.0.117.3
SERVER = localhost
# Where to find the userver directory
SHOME = .
# Temporary directory to store scripts on client host.
CHOME = /tmp/testaio
# CHOME = ./scripts
# No need to change this if SHOME is set.
USERVER = $(SHOME)/userver

# Test aio with headers stored in the file.
testaio_w_header: aio_w_header1 aio_w_header2 aio_w_header3 aio_w_header4

DO_CLIENT=
# DO_CLIENT=ssh $(CLIENT)

aio_w_header1:
	@echo "Running test 1 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(AIO_OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddruri $(SERVER) docs/10B-w-header.txt 1' >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

aio_w_header2:
	@echo "Running test 2 - should get 100 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(AIO_OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddruri $(SERVER) docs/10B-w-header.txt 100' >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

aio_w_header3:
	@echo "Running test 3 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(AIO_OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddruri $(SERVER) docs/10B-w-header.txt 1' >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

aio_w_header4:
	@echo "Running test 4 - should get 100 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(AIO_OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddruri $(SERVER) docs/10B-w-header.txt 100' >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio: rtaio1 rtaio2 rtaio3 rtaio4 rtaio5 rtaio6 rtaio7 rtaio8 rtaio9 rtaio10 \
       rtaio11 rtaio12 rtaio13 rtaio14 rtaio15

rtsetup:
	@ssh $(CLIENT) '/bin/rm -rf $(CHOME)'
	@ssh $(CLIENT) 'mkdir $(CHOME)'
	scp scripts/runaddr $(CLIENT):$(CHOME)
	scp scripts/runaddrrate $(CLIENT):$(CHOME)
	scp scripts/runaddrpersist $(CLIENT):$(CHOME)
	scp scripts/runaddrport $(CLIENT):$(CHOME)
	scp scripts/runaddruri $(CLIENT):$(CHOME)
	scp scripts/runaddrsesslog $(CLIENT):$(CHOME)
	ssh $(CLIENT) 'chmod -R 777 $(CHOME)'

rtaio0:
	@echo "Running test 0 - should get 1000 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 40000 -f 50000 -m 1 -C --ignore-fd-setsize $(AIO_OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddr $(SERVER) 1000' >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio1:
	@echo "****** WARNING: MAKE SURE YOU'VE RUN make rtsetup first **********"
	@echo "Running test 1 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(AIO_OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddr $(SERVER) 1' >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio2:
	@echo "Running test 2 - should get 2 replies and 0 errors"
	$(CSH) -c "./userver -c 10 -f 40 -m 1 -C $(AIO_OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddr $(SERVER) 2' >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio3:
	@echo "Running test 3 - should get 10 replies and 0 errors"
	$(CSH) -c "./userver -c 20 -f 60 -m 1 $(AIO_OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddr $(SERVER) 10' >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio4:
	@echo "Running test 4 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver -c 2 -f 30 -m 1 -C $(AIO_OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddr $(SERVER) 100' >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio5:
	@echo "Running test 5 - should get 500 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 -C $(AIO_OPTS) >& test5.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 50 500' >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio6:
	@echo "Running test 6 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 -C $(AIO_OPTS) >& test6.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrpersist $(SERVER) 1000' >& test6-httperf.out"
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio7:
	@echo "Running test 7 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 -C $(AIO_OPTS) >& test7.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddr $(SERVER) 100' >& test7-httperf.out"
	@egrep 'Reply status:|Errors:' test7-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio8:
	@echo "Running test 8 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 -C $(AIO_OPTS) >& test8.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 100 1000' >& test8-httperf.out"
	@egrep 'Reply status:|Errors:' test8-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio9:
	@echo "Running test 9 - should get 10000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 -C $(AIO_OPTS) >& test9.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 100 10000' >& test9-httperf.out"
	@egrep 'Reply status:|Errors:' test9-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2


rtaio10:
	@echo "Running test 10 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test10.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 100 1000' >& test10-httperf.out"
	@egrep 'Reply status:|Errors:' test10-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio11:
	@echo "Running test 11 - should get 8000 replies and 0 errors"
	$(CSH) -c "./userver -c 500 -f 1024 -m 10 -C $(AIO_OPTS) >& test11.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 200 8000' >& test11-httperf.out"
	@egrep 'Reply status:|Errors:' test11-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio12:
	@echo "Running test 12 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 15000 -f 32000 -m 1 -C $(AIO_OPTS) >& test12.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 100 1000' >& test12-httperf.out"
	@egrep 'Reply status:|Errors:' test12-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio13:
	@echo "Running test 13 - should get 9000 replies and 0 errors"
	$(CSH) -c "./userver -c 15000 -f 32000 -m 1 -C $(AIO_OPTS) >& test13.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 1000 9000' >& test13-httperf.out"
	@egrep 'Reply status:|Errors:' test13-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaio14:
	@echo "Running test 14 - should get 20000 replies and 0 errors"
	$(CSH) -c "./userver -c 15000 -f 32000 -m 1 -C $(AIO_OPTS) >& test14.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 5000 50000' >& test14-httperf.out"
	@egrep 'Reply status:|Errors:' test14-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

NEW_AIO_OPTS= -C -c 1500 -f 3200 --ignore-fd-setsize \
	      --accept-count=0 --use-socket-aio \
	      --aio-read-before-write --aio-read-before-accept \
	      --aio-accept-thold=0 -D 0x0 \
	      --stats-interval=1

rtaio15:
	@echo "Running test 15 - should get 40000 replies and 0 errors"
	$(CSH) -c "./userver $(NEW_AIO_OPTS) >& test15.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrrate $(SERVER) 2000 40000' >& test15-httperf.out"
	@egrep 'Reply status:|Errors:' test15-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaionew: rtaionew1 rtaionew2 rtaionew3 rtaionew4 rtaionew5 rtaionew6

rtaionew1:
	@echo "****** WARNING: MAKE SURE YOU'VE RUN make rtsetup first **********"
	@echo "Running test 1 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(AIO_OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 1 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaionew2:
	@echo "Running test 2 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 $(AIO_OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 10 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaionew3:
	@echo "Running test 3 - should get 1 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(AIO_OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 1 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaionew4:
	@echo "Running test 4 - should get 10 replies and 0 errors"
	$(CSH) -c "$(USERVER) -c 2 -f 30 -m 1 -C $(AIO_OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddr-1.0 $(SERVER) 10 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaionew5:
	@echo "Running test 5 - should get 500 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate-1.0 $(SERVER) 50 500 >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaionew6:
	@echo "Running test 6 - should get 500 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 -C $(AIO_OPTS) >& test6.out &"
	sleep 4
	$(CSH) -c "./scripts/runaddrrate-1.0 $(SERVER) 50 500 >& test6-httperf.out"
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2


#AIO_SPEC = --max-conns 2000 --max-fds 4000 --accept-count 0 \
#          --caching-on --cache-table-size=300 --cache-max-load-factor=1.5 \
#          --cache-max-file-size=1048576 --cache-max-bytes=10000000 \
#          --cache-table-print \
#          --ignore-fd-setsize --use-socket-aio \
#          --aio-read-before-write --aio-read-before-accept \
#          --aio-accept-thold=0 -D 0x1  \
#          --stats-interval=1
AIO_SPEC = --max-conns 7000 --max-fds 15000 --accept-count 0 \
          --caching-on --cache-table-size=300 --cache-max-load-factor=1.5 \
          --cache-max-file-size=1048576 --cache-max-bytes=10000000 \
          --cache-table-print \
          --ignore-fd-setsize --use-socket-aio \
          --aio-read-before-write --aio-read-before-accept \
          --aio-accept-thold=0

rtaiospec: rtaiospec1 timewait rtaiospec2 timewait \
           rtaiospec3 timewait rtaiospec4

timewait:
	sleep 90

rtaioserver:
	@echo "Running test 1 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& OUTPUT &"


rtaiospec1:
	@echo "Running test 1 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& test1.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(SERVER) 200 20000 $(CHOME)/httpspec99-d-1.log' >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server2 $(USERVER) $(AIO_SPEC)
	sleep 2

rtaiospec2:
	@echo "Running test 2 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& test2.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(SERVER) 400 40000 $(CHOME)/httpspec99-d-1.log' >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec3:
	@echo "Running test 3 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& test3.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(SERVER) 800 40000 $(CHOME)/httpspec99-d-1.log' >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec4:
	@echo "Running test 4 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& test4.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(SERVER) 1000 40000 $(CHOME)/httpspec99-d-1.log' >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2


rtaiospec5:
	@echo "Running test 5 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& test5.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(SERVER) 1100 40000 $(CHOME)/httpspec99-d-1.log' >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

# Talks to the server on the same subnet/IP as CLIENT.
CLIENT2=15.0.119.21

rtaiospec6:
	@echo "Running test 6 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) >& test6.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(SERVER) 1000 40000 $(CHOME)/httpspec99-d-1.log' >& test6a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT2) '$(CHOME)/runaddrsesslog $(SERVER) 1000 40000 $(CHOME)/httpspec99-d-1.log' >& test6b-httperf.out"
	sleep 10
	@egrep 'Reply status:|Errors:' test6a-httperf.out
	@egrep 'Reply status:|Errors:' test6b-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

# Talks to the server on different subnet/IP from CLIENT.
CLIENT3=15.0.119.23
CLIENT4=15.0.119.25
CLIENT5=15.0.119.27
IP1=15.0.117.3
IP2=15.0.117.19
IP3=15.0.117.35
IP4=15.0.117.51

rtaiospec7:
	@echo "Running test 7 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) --ip-addr $(IP1) --ip-addr $(IP2) >& test7.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(IP1) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test7a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT3) '$(CHOME)/runaddrsesslog $(IP2) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test7b-httperf.out"
	sleep 10
	@egrep 'Reply status:|Errors:' test7a-httperf.out
	@egrep 'Reply status:|Errors:' test7b-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec8:
	@echo "Running test 8 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) --ip-addr $(IP1) --ip-addr $(IP2) >& test8.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT) '$(CHOME)/runaddrsesslog $(IP1) 1000 40000 $(CHOME)/httpspec99-d-1.log' >& test8a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT3) '$(CHOME)/runaddrsesslog $(IP2) 1000 40000 $(CHOME)/httpspec99-d-1.log' >& test8b-httperf.out"
	sleep 10
	@egrep 'Reply status:|Errors:' test8a-httperf.out
	@egrep 'Reply status:|Errors:' test8b-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec9:
	@echo "Running test 9 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) \
            --ip-addr $(IP1) --ip-addr $(IP2) --ip-addr $(IP3) >& test9.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT)  '$(CHOME)/runaddrsesslog $(IP1) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test9a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT3) '$(CHOME)/runaddrsesslog $(IP2) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test9b-httperf.out&"
	$(CSH) -c "ssh $(CLIENT4) '$(CHOME)/runaddrsesslog $(IP3) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test9c-httperf.out"
	sleep 15
	@egrep 'Reply status:|Errors:' test9a-httperf.out
	@egrep 'Reply status:|Errors:' test9b-httperf.out
	@egrep 'Reply status:|Errors:' test9c-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec10:
	@echo "Running test 10 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) \
           --ip-addr $(IP1) --ip-addr $(IP2) --ip-addr $(IP3) >& test10.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT)  '$(CHOME)/runaddrsesslog $(IP1) 750 10000 $(CHOME)/httpspec99-d-1.log' >& test10a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT3) '$(CHOME)/runaddrsesslog $(IP2) 750 10000 $(CHOME)/httpspec99-d-1.log' >& test10b-httperf.out&"
	$(CSH) -c "ssh $(CLIENT4) '$(CHOME)/runaddrsesslog $(IP3) 750 10000 $(CHOME)/httpspec99-d-1.log' >& test10c-httperf.out"
	sleep 15
	@egrep 'Reply status:|Errors:' test10a-httperf.out
	@egrep 'Reply status:|Errors:' test10b-httperf.out
	@egrep 'Reply status:|Errors:' test10c-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec11:
	@echo "Running test 11 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x0 \
            --ip-addr $(IP4) --ip-addr $(IP3) --ip-addr $(IP2) --ip-addr $(IP1) >& test11.out &"
	sleep 4
	$(CSH) -c "ssh $(CLIENT)  '$(CHOME)/runaddrsesslog $(IP1) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test11a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT3) '$(CHOME)/runaddrsesslog $(IP2) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test11b-httperf.out&"
	$(CSH) -c "ssh $(CLIENT4) '$(CHOME)/runaddrsesslog $(IP3) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test11c-httperf.out&"
	$(CSH) -c "ssh $(CLIENT5) '$(CHOME)/runaddrsesslog $(IP4) 500 10000 $(CHOME)/httpspec99-d-1.log' >& test11d-httperf.out"
	sleep 15
	@egrep 'Reply status:|Errors:' test11a-httperf.out
	@egrep 'Reply status:|Errors:' test11b-httperf.out
	@egrep 'Reply status:|Errors:' test11c-httperf.out
	@egrep 'Reply status:|Errors:' test11d-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

rtaiospec12:
	@echo "Running test 12 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x0 \
            --ip-addr $(IP1) --ip-addr $(IP2) >& test12a.out &"
	sleep 2
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x0 \
            --ip-addr $(IP3) --ip-addr $(IP4) >& test12b.out &"
	sleep 10
	$(CSH) -c "ssh $(CLIENT)  '$(CHOME)/runaddrsesslog $(IP1) 150 10000 $(CHOME)/httpspec99-d-1.log' >& test12a-httperf.out&" 
	$(CSH) -c "ssh $(CLIENT3) '$(CHOME)/runaddrsesslog $(IP2) 150 10000 $(CHOME)/httpspec99-d-1.log' >& test12b-httperf.out&"
	$(CSH) -c "ssh $(CLIENT4) '$(CHOME)/runaddrsesslog $(IP3) 150 10000 $(CHOME)/httpspec99-d-1.log' >& test12c-httperf.out&"
	$(CSH) -c "ssh $(CLIENT5) '$(CHOME)/runaddrsesslog $(IP4) 150 10000 $(CHOME)/httpspec99-d-1.log' >& test12d-httperf.out"
	sleep 15
	@egrep 'Reply status:|Errors:' test12a-httperf.out
	@egrep 'Reply status:|Errors:' test12b-httperf.out
	@egrep 'Reply status:|Errors:' test12c-httperf.out
	@egrep 'Reply status:|Errors:' test12d-httperf.out
	sleep 2
	@./scripts/kill-server2
	sleep 2

LSNP1_STD = 15.0.119.21
LSNP2_STD = 15.0.119.22
LSNP3_STD = 15.0.119.23
LSNP4_STD = 15.0.119.24
LSNP5_STD = 15.0.119.25
LSNP6_STD = 15.0.119.26
LSNP7_STD = 15.0.119.27
LSNP8_STD = 15.0.119.28

LSNP1_TO_SVR = 15.0.117.3
LSNP2_TO_SVR = 15.0.117.3
LSNP3_TO_SVR = 15.0.117.19
LSNP4_TO_SVR = 15.0.117.19
LSNP5_TO_SVR = 15.0.117.35
LSNP6_TO_SVR = 15.0.117.35
LSNP7_TO_SVR = 15.0.117.51
LSNP8_TO_SVR = 15.0.117.51

rtaioip: rtaioip1 rtaioip2 rtaioip3 rtaioip4 \
         rtaioip5 rtaioip6 rtaioip7 rtaioip8

rtaioip1:
	@echo "Running test 1 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP1_TO_SVR) >& test1.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP1_STD) '$(CHOME)/runaddrsesslog $(LSNP1_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test1-httperf.out" 
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip2:
	@echo "Running test 2 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP2_TO_SVR) >& test2.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP2_STD)  '$(CHOME)/runaddrsesslog $(LSNP2_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test2-httperf.out" 
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip3:
	@echo "Running test 3 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP3_TO_SVR) >& test3.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP3_STD)  '$(CHOME)/runaddrsesslog $(LSNP3_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test3-httperf.out" 
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip4:
	@echo "Running test 4 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP4_TO_SVR) >& test4.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP4_STD)  '$(CHOME)/runaddrsesslog $(LSNP4_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test4-httperf.out" 
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip5:
	@echo "Running test 5 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP5_TO_SVR) >& test5.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP5_STD)  '$(CHOME)/runaddrsesslog $(LSNP5_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test5-httperf.out" 
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip6:
	@echo "Running test 6 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP6_TO_SVR) >& test6.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP6_STD)  '$(CHOME)/runaddrsesslog $(LSNP6_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test6-httperf.out" 
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip7:
	@echo "Running test 7 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP7_TO_SVR) >& test7.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP7_STD)  '$(CHOME)/runaddrsesslog $(LSNP7_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test7-httperf.out" 
	@egrep 'Reply status:|Errors:' test7-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

rtaioip8:
	@echo "Running test 8 - should get 0 errors"
	$(CSH) -c "$(USERVER) $(AIO_SPEC) -D 0x1 \
            --ip-addr $(LSNP8_TO_SVR) >& test8.out &"
	sleep 4
	$(CSH) -c "ssh $(LSNP8_STD)  '$(CHOME)/runaddrsesslog $(LSNP8_TO_SVR) 5 10 $(CHOME)/httpspec99-d-1.log' >& test8-httperf.out" 
	@egrep 'Reply status:|Errors:' test8-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio: rtaionew testaiolist

testaiolist: testaio1 testaio2 testaio3 testaio4 testaio5 testaio6 testaio7 \
         testaio8 testaio9 testaio10 testaio11 testaio12 testaio13 testaio14

testaio1:
	@echo "Running AIO Test Subset"
	@echo "Running test 1 - should get 1 replies and 0 errors"
	$(CSH) -c "./userver -c 2 -f 30 -m 1 $(AIO_OPTS) >& test1.out &"
	sleep 4
	$(CSH) -c "./scripts/run 1 >& test1-httperf.out"
	@egrep 'Reply status:|Errors:' test1-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio2:
	@echo "Running test 2 - should get 2 replies and 0 errors"
	$(CSH) -c "./userver -c 2 -f 30 -m 1 $(AIO_OPTS) >& test2.out &"
	sleep 4
	$(CSH) -c "./scripts/run 2 >& test2-httperf.out"
	@egrep 'Reply status:|Errors:' test2-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio3:
	@echo "Running test 3 - should get 10 replies and 0 errors"
	$(CSH) -c "./userver -c 2 -f 30 -m 1 $(AIO_OPTS) >& test3.out &"
	sleep 4
	$(CSH) -c "./scripts/run 10 >& test3-httperf.out"
	@egrep 'Reply status:|Errors:' test3-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio4:
	@echo "Running test 4 - should get 100 replies and 0 errors"
	$(CSH) -c "./userver -c 2 -f 30 -m 1 $(AIO_OPTS) >& test4.out &"
	sleep 4
	$(CSH) -c "./scripts/run 100 >& test4-httperf.out"
	@egrep 'Reply status:|Errors:' test4-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio5:
	@echo "Running test 5 - should get 500 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test5.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 50 500 >& test5-httperf.out"
	@egrep 'Reply status:|Errors:' test5-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio6:
	@echo "Running test 6 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test6.out &"
	sleep 4
	$(CSH) -c "./scripts/runpersist 1000 >& test6-httperf.out"
	@egrep 'Reply status:|Errors:' test6-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio7:
	@echo "Running test 7 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test7.out &"
	sleep 4
	$(CSH) -c "./scripts/run 1000 >& test7-httperf.out"
	@egrep 'Reply status:|Errors:' test7-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio8:
	@echo "Running test 8 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test8.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 100 1000 >& test8-httperf.out"
	@egrep 'Reply status:|Errors:' test8-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio9:
	@echo "Running test 9 - should get 10000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) >& test9.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 100 10000 >& test9-httperf.out"
	@egrep 'Reply status:|Errors:' test9-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2


testaio10:
	@echo "Running test 10 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 300 -f 500 -m 1 $(AIO_OPTS) -C >& test10.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 100 1000 >& test10-httperf.out"
	@egrep 'Reply status:|Errors:' test10-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio11:
	@echo "Running test 11 - should get 8000 replies and 0 errors"
	$(CSH) -c "./userver -c 500 -f 1024 -m 10 $(AIO_OPTS) >& test11.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 200 8000 >& test11-httperf.out"
	@egrep 'Reply status:|Errors:' test11-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio12:
	@echo "Running test 12 - should get 1000 replies and 0 errors"
	$(CSH) -c "./userver -c 15000 -f 32000 -m 1 $(AIO_OPTS) -C >& test12.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 100 1000 >& test12-httperf.out"
	@egrep 'Reply status:|Errors:' test12-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio13:
	@echo "Running test 13 - should get 9000 replies and 0 errors"
	$(CSH) -c "./userver -c 15000 -f 32000 -m 1 $(AIO_OPTS) -C >& test13.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 1000 9000 >& test13-httperf.out"
	@egrep 'Reply status:|Errors:' test13-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaio14:
	@echo "Running test 14 - should get 20000 replies and 0 errors"
	$(CSH) -c "./userver -c 15000 -f 32000 -m 1 $(AIO_OPTS) -C >& test14.out &"
	sleep 4
	$(CSH) -c "./scripts/runrate 5000 50000 >& test14-httperf.out"
	@egrep 'Reply status:|Errors:' test14-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

testaionew: testaionew1

AIO_NEW_OPTS = --use-socket-aio --aio-read-before-accept --aio-accept-thold=1 -D 0x0

testaionew1:
	$(CSH) -c "./userver -c 1 -f 20 $(AIO_NEW_OPTS) >& test1.out"

INTER_AIO_OPTS = --ignore-fd-setsize \
		 --aio-read-before-write \
		 --aio-read-before-accept \
		 --use-socket-aio

INTER_AIO_OPTS_BRIAN = --use-socket-aio -D 0x1

startaio1:
	$(CSH) -c "./userver -c 100 -f 210 $(INTER_AIO_OPTS) --stats-interval=1 -D 0x0"

startaio2:
	$(CSH) -c "./userver -c 10 -f 30 $(INTER_AIO_OPTS) --doc-root=/home/brecht -D 0x1"

startaio3:
	$(CSH) -c "./userver -c 11 -f 30 $(INTER_AIO_OPTS) --ip-addr 127.0.0.1 --ip-addr 192.168.0.5 -D 0x1 --aio-accept-thold=3"

start3:
	$(CSH) -c "./userver -c 11 -f 30 --ip-addr 127.0.0.1 --ip-addr 192.168.0.5 -D 0x1"

startaiobrian1:
	$(CSH) -c "./userver -c 10 -f 30 $(INTER_AIO_OPTS_BRIAN)"

startaiobrian2:
	$(CSH) -c "./userver --use-socket-aio -D 0x1"

startaiobrian3:
	$(CSH) -c "./userver --use-socket-aio -D 0x1 >& OUTPUT"

startaiobrian4:
	$(CSH) -c "./userver --use-socket-aio -D 0x0"

SERVERIP1 = 127.0.0.1
SERVERIP2 = 192.168.0.5

testip: ip1 ip2 ip3 ip4 ip5

ip1:
	@echo "Running test 1 - should get 200 replies and 0 errors"
	$(CSH) -c "./userver -c 11 -f 30 -C \
	    --ip-addr $(SERVERIP1) --ip-addr $(SERVERIP2) \
	    -D 0x1 >& test1.out &"
	sleep 5
	$(CSH) -c "./scripts/runaddr $(SERVERIP1) 100 >& test1a-httperf.out"
	$(CSH) -c "./scripts/runaddr $(SERVERIP2) 100 >& test1b-httperf.out"
	@egrep 'Reply status:|Errors:' test1a-httperf.out
	@egrep 'Reply status:|Errors:' test1b-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

ip2:
	@echo "Running test 2 - should get 200 replies and 0 errors"
	$(CSH) -c "./userver -c 11 -f 30 -C \
	    --ip-addr $(SERVERIP1) --ip-addr $(SERVERIP2) \
	    $(INTER_AIO_OPTS) -D 0x1 --aio-accept-thold=3 >& test2.out &"
	sleep 5
	$(CSH) -c "./scripts/runaddr $(SERVERIP1) 100 >& test2a-httperf.out"
	$(CSH) -c "./scripts/runaddr $(SERVERIP2) 100 >& test2b-httperf.out"
	@egrep 'Reply status:|Errors:' test2a-httperf.out
	@egrep 'Reply status:|Errors:' test2b-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

ip3:
	@echo "Running test 3 - should get 2000 replies and 0 errors"
	$(CSH) -c "./userver -c 11 -f 30 -C \
	    --ip-addr $(SERVERIP1) --ip-addr $(SERVERIP2) \
	    $(INTER_AIO_OPTS) -D 0x1 --aio-accept-thold=3 >& test3.out &"
	sleep 5
	$(CSH) -c "./scripts/runaddrrate $(SERVERIP1) 200 1000 >& test3a-httperf.out &"
	$(CSH) -c "./scripts/runaddrrate $(SERVERIP2) 200 1000 >& test3b-httperf.out"
	sleep 5
	@egrep 'Reply status:|Errors:' test3a-httperf.out
	@egrep 'Reply status:|Errors:' test3b-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2


ip4:
	@echo "Running test 4 - should get 8000 replies and 0 errors"
	$(CSH) -c "./userver -c 800 -f 900 -C \
	    --ip-addr $(SERVERIP1) --ip-addr $(SERVERIP2) \
	    --stats-interval=1 \
	    $(INTER_AIO_OPTS) -D 0x0 --aio-accept-thold=0 >& test4.out &"
	sleep 5
	$(CSH) -c "./scripts/runaddrrate $(SERVERIP1) 400 4000 >& test4a-httperf.out &"
	$(CSH) -c "./scripts/runaddrrate $(SERVERIP2) 400 4000 >& test4b-httperf.out"
	sleep 10
	@egrep 'Reply status:|Errors:' test4a-httperf.out
	@egrep 'Reply status:|Errors:' test4b-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2

ip5:
	@echo "Running test 5 - should get 8000 replies and 0 errors"
	$(CSH) -c "./userver -c 800 -f 900 -C \
	    --ip-addr $(SERVERIP1) --ip-addr $(SERVERIP2) \
	    $(INTER_AIO_OPTS) -D 0x0 --aio-accept-thold=0 >& test5.out &"
	sleep 5
	$(CSH) -c "./scripts/runaddrrate $(SERVERIP1) 400 4000 >& test5a-httperf.out &"
	$(CSH) -c "./scripts/runaddrrate $(SERVERIP2) 400 4000 >& test5b-httperf.out"
	sleep 10
	@egrep 'Reply status:|Errors:' test5a-httperf.out
	@egrep 'Reply status:|Errors:' test5b-httperf.out
	sleep 2
	@./scripts/kill-server
	sleep 2


install: FORCE
	mv $(PGMS) $(BIN)

clean: FORCE
	rm -f *.o

vclean: FORCE
	-rm -f *.o $(PGMS) makedocs core core.* .depend userver.trace \
		cscope.out userver.ps userver.pdf userver.txt userver.html \
		userver.exe userver.exe.stackdump userver.pid test*.out
	-rm -rf docs

ctags: FORCE
	ctags *.[ch]

tags: FORCE
	ctags *.[ch]

DIST_DEST = ../$(DIST_NAME)
SCRIPTS_DEST = ../$(DIST_NAME)/scripts
INCLUDE_DEST = ../$(DIST_NAME)

makedocs: makedocs.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -o makedocs makedocs.c

docs/1B.txt:
	rm -rf docs
	./makedocs

docs: makedocs docs/1B.txt

dist: docs userver.txt userver.ps userver.pdf userver.html
	-mkdir $(DIST_DEST)
	-mkdir $(SCRIPTS_DEST)
	-mkdir $(INCLUDE_DEST)
	cp -p $(DIST_LIST) $(DIST_DEST)
	cp -p $(SCRIPTS) $(SCRIPTS_DEST)
	cp -pr $(INCLUDE) $(INCLUDE_DEST)
	rm -rf $(INCLUDE_DEST)/include/CVS $(INCLUDE_DEST)/include/*/CVS $(INCLUDE_DEST)/include/*/*/CVS
	$(CSH) -c "cd .. ; pwd ; tar -czf $(DIST_NAME).tar.gz $(DIST_NAME)/"
	@echo "Don't forget to upload the distribution (make updist)"
	@echo "and tag the CVS tree (make cvstag) !!!"

updist:
	scp CHANGELOG bcr2.uwaterloo.ca:www/userver/src/CHANGELOG-$(DIST_VER).txt
	scp ../$(DIST_NAME).tar.gz bcr2.uwaterloo.ca:www/userver/src
	scp userver.pdf bcr2.uwaterloo.ca:www/userver/src/info/
	scp userver.ps bcr2.uwaterloo.ca:www/userver/src/info/
	scp userver.html bcr2.uwaterloo.ca:www/userver/src/info/
	ssh bcr2.uwaterloo.ca 'chmod a+r www/userver/src/info/*'
	ssh bcr2.uwaterloo.ca 'chmod a+r www/userver/src/*'
	@echo "Don't forget to tag the CVS tree!!!"

upman:
	make man
	scp userver.pdf bcr2.uwaterloo.ca:www/userver/src/info/
	scp userver.ps bcr2.uwaterloo.ca:www/userver/src/info/
	scp userver.html bcr2.uwaterloo.ca:www/userver/src/info/
	ssh bcr2.uwaterloo.ca 'chmod a+r www/userver/src/info/*'

cvstag:
	cvs tag Ver-$(CVS_TAG_VER)

# upindex:
#  	scp index.html bcr2:www/userver/src

FORCE:

