empserver/tests/smoke-test
Markus Armbruster 39c26f4238 Switch PRNG from BSD random() to Mersenne Twister
random() may yield different pseudo-random number sequences for the
same seed on another system.  For instance, at least some versions of
MinGW provide a random() in -liberty that differs from traditional BSD
(see commit c8231b12).  Rather inconvenient for regression testing.

MT19937 Mersenne Twister is a proven, high-quality PRNG.  Actual code
is reference code provided by the inventors[*].  Quick tests show
performance comparable to random().

Like random(), MT is not cryptographically secure: observing enough of
its output permits guessing its state, and thus its future output.  I
don't think players can do that.

Drop the copy of BSD random() we added for Windows.

Like the previous commit, this changes the server's die rolls, and
makes fairland create a different random map for the same seed.  Update
expected smoke test results accordingly.

[*] mt19937ar.sep.tgz downloaded from
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
2013-05-08 06:55:21 +02:00

76 lines
1.7 KiB
Bash
Executable file

#!/bin/sh -e
# Smoke test for Empire
if [ $# -ne 1 ]
then echo "Usage: $0 SRCDIR" >&2; exit 1
fi
srcdir="$1"
. "$srcdir"/tests/test-common.sh
#
# Currently expected to work only with thread package LWP, because:
#
# - Thread scheduling is reliably deterministic only with LWP
# - Shell builtin kill appears not to do the job in MinGW
# - The Windows server tries to run as service when -d isn't
# specified
#
# TODO address these shortcomings.
#
if [ `sed -n 's/empthread *:= *\(.*\)/\1/p' <GNUmakefile` != LWP ]
then echo "Warning: smoke test not expected to work with this thread package!" >&2
fi
create_sandbox
exec 3>sandbox/smoke.out
# Create world and start server
src/util/files -e sandbox/etc/empire/econfig -f >&3
src/util/empdump -e sandbox/etc/empire/econfig -i "$srcdir"/tests/smoke/fairland.xdump
start_server
src/client/empire POGO peter <"$srcdir"/tests/smoke/newcap_script >/dev/null
# Feed player input
need_update=
for i in "$srcdir"/tests/smoke/[0-9]*
do
t="${i##*/}"
if [ "$need_update" ]
then
echo "Update Turn $t starting" >&3
src/client/empire POGO peter <<EOF >&3
power new
report *
cen * ?own#0
comm * ?own#0
reso * ?own#0
force
EOF
echo "Update Turn $t completed successfully" >&3
fi
for j in "$i"/*
do
p="${j##*/}"
echo "Player $p Turn $t starting" >&3
if [ $p -eq 0 ]
then c=POGO r=peter
else c="${p#0}"; r="$c"
fi
src/client/empire "$c" "$r" <$j >&3
echo "Player $p Turn $t completed successfully" >&3
done
need_update=y
done
# Stop server
stop_server
exec 3>&-
src/util/empdump -e sandbox/etc/empire/econfig -x >sandbox/smoke.xdump
# Smoke test completed; compare results
cmp_out smoke.out var/empire/server.log var/empire/journal.log smoke.xdump