empserver/tests/test-common.sh
Markus Armbruster 9ca3fa95b8 tests: Capture player output via journal instead of client
Capturing the client's output tests both client and server, which is
nice.  However, player input isn't visible in the resulting file,
which makes it more difficult to understand.

Route player output to journal (econfig key "keep_journal 2"), and
ignore client output.

Separate tests for the client would be useful.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-05-31 10:52:50 +02:00

97 lines
2 KiB
Bash

export EMPIREHOST=127.0.0.1 LOGNAME=tester
if [ -x ./config.status ] && ./config.status --version | grep -q '^Wolfpack Empire'
then :
else echo "$0: Must be run in root of build tree" >&2; exit 1
fi
test=${0##*/}
test=${test%-test}
create_sandbox()
{
rm -rf sandbox
mkdir -p sandbox/etc/empire sandbox/share/empire/builtin sandbox/var/empire
touch sandbox/etc/empire/schedule
cat >sandbox/etc/empire/econfig <<EOF
data "../../var/empire"
info "../../../../info.nr"
builtin "../../share/empire/builtin"
listen_addr "$EMPIREHOST"
keep_journal 2
EOF
cp "$srcdir"/src/lib/global/*.config sandbox/share/empire/builtin
}
now()
{
# date +%s isn't portable...
perl -e 'printf "%s\n", time'
}
start_server()
{
local pidfile=sandbox/var/empire/server.pid
local timeout
pid=
trap 'if [ "$pid" ]; then kill -9 "$pid" 2>/dev/null || true; fi' EXIT
src/server/emp_server -e sandbox/etc/empire/econfig -R 1 -s
timeout=$((`now`+5))
until pid=`cat $pidfile 2>/dev/null` && [ -n "$pid" ]
do
if [ `now` -gt $timeout ]
then
echo "Timed out waiting for server to create $pidfile" >&2
exit 1
fi
done
while src/client/empire red herring 2>&1 | grep -q "Connection refused"
do
if [ `now` -gt $timeout ]
then
echo "Timed out waiting for server to accept connections" >&2
exit 1
fi
done
}
stop_server()
{
local timeout
kill "$pid"
timeout=$((`now`+5))
while kill -0 "$pid" 2>/dev/null
do
if [ `now` -gt $timeout ]
then
echo "Timed out waiting for server to terminate" >&2
exit 1
fi
done
}
cmp_out()
{
local opt exp act nrm msg ret=0
for i
do
case "$i" in
*/journal.log) opt=-j ;;
*/server.log) opt=-s ;;
*) opt= ;;
esac
exp="$srcdir/tests/$test/${i##*/}"
act="sandbox/$i"
nrm="sandbox/normalized-${i##*/}"
perl "$srcdir"/tests/normalize.pl $opt "$act" >"$nrm"
if msg=`diff -q "$exp" "$nrm"`
then
echo "$exp OK"
else
ret=$?
echo "$exp FAIL"
echo $msg
fi
done
return $ret
}