]> git.pond.sub.org Git - empserver/blob - tests/smoke-test
Make smoke test check the final empdump -x
[empserver] / tests / smoke-test
1 #!/bin/sh -e
2 # Smoke test for Empire
3
4 if [ $# -ne 1 ]
5 then echo "Usage: $0 SRCDIR" >&2; exit 1
6 fi
7
8 srcdir="$1"
9
10 export EMPIREHOST=127.0.0.1 LOGNAME=tester
11
12 if [ -x ./config.status ] && ./config.status --version | grep -q '^Wolfpack Empire'
13 then :
14 else echo "$0: Must be run in root of build tree" >&2; exit 1
15 fi
16
17 #
18 # Currently expected to work only with thread package LWP and a
19 # random() that behaves exactly like the one on my development system,
20 # because:
21
22 # - Thread scheduling is reliably deterministic only with LWP
23 # - The PRN sequence produced by random() isn't portable
24 # - Shell builtin kill appears not to do the job in MinGW
25 # - The Windows server tries to run as service when -d isn't
26 #   specified
27 #
28 # TODO address these shortcomings.
29 #
30 if [ "`uname -s`" != "Linux" ]  # lame approx. of "random() behaves like mine"
31 then echo "Warning: smoke test not expected to work on this system!" >&2
32 elif [ `sed -n 's/empthread *:= *\(.*\)/\1/p' <GNUmakefile` != LWP ]
33 then echo "Warning: smoke test not expected to work with this thread package!" >&2
34 fi
35
36 # Create sandbox
37 rm -rf sandbox
38 mkdir -p sandbox/etc/empire sandbox/share/empire/builtin sandbox/var/empire
39 touch sandbox/etc/empire/schedule
40 cat >sandbox/etc/empire/econfig <<EOF
41 data "../../var/empire"
42 info "../../../../info.nr"
43 builtin "../../share/empire/builtin"
44 listen_addr "$EMPIREHOST"
45 keep_journal 1
46 EOF
47 cp "$srcdir"/src/lib/global/*.config sandbox/share/empire/builtin
48
49 exec 3>sandbox/smoke.out
50
51 pid=
52 trap 'if [ "$pid" ]; then kill "$pid" 2>/dev/null || true; fi' EXIT
53
54 # Create world and start server
55 src/util/files -e sandbox/etc/empire/econfig -f >&3
56 src/util/fairland -e sandbox/etc/empire/econfig -q -s sandbox/newcap_script -R 1 10 30
57 src/server/emp_server -e sandbox/etc/empire/econfig -R 1
58 while src/client/empire red herring 2>&1 | grep -q "Connection refused"
59 do :                            # FIXME hangs here if server crashes on startup
60 done
61 pid=`cat sandbox/var/empire/server.pid`
62 src/client/empire POGO peter <sandbox/newcap_script >/dev/null
63
64 # Feed player input
65 need_update=
66 for i in "$srcdir"/tests/smoke/[0-9]*
67 do
68     t="${i##*/}"
69     if [ "$need_update" ]
70     then
71         echo "Update Turn $t starting" >&3
72         src/client/empire POGO peter <<EOF >&3
73 power new
74 report *
75 cen * ?own#0
76 comm * ?own#0
77 reso * ?own#0
78 force
79 EOF
80         echo "Update Turn $t completed successfully" >&3
81     fi
82     for j in "$i"/*
83     do
84         p="${j##*/}"
85         echo "Player $p Turn $t starting" >&3
86         if [ $p -eq 0 ]
87         then c=POGO r=peter
88         else c="${p#0}"; r="$c"
89         fi
90         src/client/empire "$c" "$r" <$j >&3
91         echo "Player $p Turn $t completed successfully" >&3
92     done
93     need_update=y
94 done
95
96 # Stop server
97 kill "$pid"
98 while kill -0 "$pid" 2>/dev/null
99 do :                            # FIXME hangs here if server fails to exit
100 done
101
102 exec 3>&-
103
104 src/util/empdump -e sandbox/etc/empire/econfig -x >sandbox/smoke.xdump
105
106 # Smoke test completed; compare results
107
108 cmp_out()
109 {
110     local opt exp act nrm msg ret=0
111     for i
112     do
113         case "$i" in
114             */journal.log) opt=-j ;;
115             */server.log)  opt=-s ;;
116             *)             opt= ;;
117         esac
118         exp="$srcdir/tests/smoke/${i##*/}"
119         act="sandbox/$i"
120         nrm="sandbox/normalized-${i##*/}"
121         perl "$srcdir"/tests/normalize.pl $opt "$act" >"$nrm"
122         if msg=`diff -q "$exp" "$nrm"`
123         then
124             echo "$exp OK"
125         else
126             ret=$?
127             echo "$exp FAIL"
128             echo $msg
129         fi
130     done
131     return $ret
132 }
133
134 cmp_out smoke.out var/empire/server.log var/empire/journal.log smoke.xdump