1 export EMPIREHOST=127.0.0.1 LOGNAME=tester
3 if [ -x ./config.status ] && ./config.status --version | grep -q '^Wolfpack Empire'
5 else echo "$0: Must be run in root of build tree" >&2; exit 1
12 trap 'if [ "$pid" ]; then kill -9 "$pid" 2>/dev/null || true; fi; [ "$failed" ] && exit 1' EXIT
15 testdir="$srcdir/tests/$test"
16 econfig=sandbox/etc/empire/econfig
17 schedule=sandbox/etc/empire/schedule
18 data=sandbox/var/empire
19 empdump="src/util/empdump -e $econfig"
20 files="src/util/files -e $econfig"
21 fairland="src/util/fairland -e $econfig"
23 # GNU libc memory allocation checking, see mallopt(3)
24 # $RANDOM isn't portable
25 malloc_perturb=${EMPIRE_CHECK_MALLOC_PERTURB:-$(perl -e 'print int(rand(255))')}
26 env="MALLOC_CHECK_=3 MALLOC_PERTURB_=$malloc_perturb"
28 empthread=`sed -n 's/empthread *:= *\(.*\)/\1/p' <GNUmakefile`
33 if [ "$warn_empthread" ] && [ "$empthread" != "LWP" ]
35 echo "Warning: test not expected to work with thread package $empthread!" >&2
43 mkdir -p sandbox/etc/empire sandbox/share/empire/builtin $data
44 echo $malloc_perturb >sandbox/malloc-perturb
47 data "../../var/empire"
48 info "../../../../info.nr"
49 builtin "../../share/empire/builtin"
50 listen_addr "$EMPIREHOST"
55 cp `perl "$srcdir"/src/scripts/ls-sources.pl "$srcdir"/src/lib/global '\.config$'` sandbox/share/empire/builtin
63 do [ -e sandbox/etc/empire/"$t".config ] || cp "$srcdir"/src/lib/global/$t.config sandbox/etc/empire
67 # sed -i isn't portable...
73 do sed "$script" "$i" >sandbox/$$ && mv sandbox/$$ "$i"
85 sed_i '/"c" .* "capital"/d;/^#.*"c" .* "city"/s/^#/ /;/"c" .* norm/d;/^#.*"c" .* cana/s/^#/ /' sandbox/etc/empire/sect.config
89 sed_i '/"ts trade ship"//^#/ /' sandbox/etc/empire/ship.config
92 echo "custom_tables \"`cd sandbox/etc/empire && echo *.config`\"" >>$econfig
106 env $env "$@" >>sandbox/$name.out 2>>sandbox/$name.err
109 echo $ret >>sandbox/$name.status
114 # date +%s isn't portable...
115 perl -e 'printf "%s\n", time'
120 local pidfile=$data/server.pid
124 # Currently expected to work only with thread package LWP,
127 # - Thread scheduling is reliably deterministic only with LWP
128 # - Shell builtin kill appears not to do the job in MinGW
129 # - The Windows server tries to run as service when -d isn't
131 # - The Windows server does not implement -E crash-dump
133 # TODO address these shortcomings.
138 env $env src/server/emp_server -e $econfig -R 1 -s -E crash-dump
140 until pid=`cat $pidfile 2>/dev/null` && [ -n "$pid" ]
142 if [ `now` -gt $timeout ]
144 echo "Timed out waiting for server to create $pidfile" >&2
148 while src/client/empire red herring 2>&1 | grep -q "Connection refused"
150 if [ `now` -gt $timeout ]
152 echo "Timed out waiting for server to accept connections" >&2
163 while kill -0 "$pid" 2>/dev/null
165 if [ `now` -gt $timeout ]
167 echo "Timed out waiting for server to terminate" >&2
178 sed '/^|/d' "$@" | src/client/empire "$c" "$r" >/dev/null
188 r=`echo $c | sed 's/^POGO$/peter/'`
189 feed_input "$c" "$r" "$i"
195 feed_files `perl "$srcdir"/src/scripts/ls-sources.pl "$@" '/[0-9][0-9]-[^/]*$'`
209 if [ -z "$xd" ] || [ "$#" -ne 0 ]
211 cp -r $data/tel $data/empty.tel
214 then feed_input POGO peter
217 echo 'edit c * ?tgms>0 t 0' | feed_input POGO peter
219 mv $data/tel $data/setup.tel
220 mv $data/empty.tel $data/tel
221 mv $data/news $data/setup.news
223 mv $data/lostitems $data/setup.lostitems
225 mv $data/journal.log $data/setup.journal.log
226 normalize sandbox/var/empire/setup.journal.log
227 mv $data/server.log $data/setup.server.log
228 normalize sandbox/var/empire/setup.server.log
236 $empdump -x >sandbox/final.xdump
245 for j in status out err
253 cmp_out var/empire/server.log var/empire/journal.log final.xdump
268 local nrm="${2-sandbox/normalized-${1##*/}}"
272 perl "$srcdir"/tests/normalize.pl -j "$act" ;;
274 perl "$srcdir"/tests/normalize.pl -s "$act" ;;
276 perl "$srcdir"/tests/normalize.pl "$act" ;;
278 perl -pe 's/\s+$/\n/;' -e "s,\Q$srcdir/tests\E,tests," "$act" ;;
280 perl -pe 's/\s+$/\n/;' "$act" ;;
286 local i=$1 master="${2-$testdir/${1##*/}}"
288 local act="sandbox/$i"
289 local nrm="sandbox/normalized-${i##*/}"
295 exp=sandbox/ok.status
296 echo 0 >sandbox/ok.status
299 [ ! -e "$act" ] && return
305 normalize "$act" "$nrm"
306 if diff -u "$exp" "$nrm" >"$nrm.diff"
309 elif [ "$EMPIRE_CHECK_ACCEPT" ]