#! /bin/sh
# $NetBSD: test-bigfile,v 1.1.1.1.30.3 2017/02/12 22:07:17 snj Exp $

test="$1"	# partial4000 or partial8000
bozohttpd="$2"
wget="$3"
datadir="$4"
verbose="$5"

tmperr="tmp.$test.err"

if [ "yes" = "$verbose" ]; then
	echo "Running test $test"
else
	exec 2>"$tmperr"
fi

bozotestport=11111

# copy beginning file
cp "${datadir}/bigfile.${test}" ./bigfile

# fire up bozohttpd
${bozohttpd} -b -b -I ${bozotestport} -n -s -f "${datadir}" &
bozopid=$!

"${wget}" -c http://localhost:${bozotestport}/bigfile

kill -9 $bozopid

if cmp ./bigfile "${datadir}/bigfile"; then
	rm -f ./bigfile
	exit 0
else
	rm -f ./bigfile
	if [ "yes" = "$verbose" ]; then
		echo "Failed test $test:"
		cat "$tmperr"
	fi
	exit 1
fi
