]> git.pond.sub.org Git - empserver/blob - tests/smoke-test
Factor tests/test-common.sh out of tests/smoke-test
[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 . "$srcdir"/tests/test-common.sh
11
12 #
13 # Currently expected to work only with thread package LWP and a
14 # random() that behaves exactly like the one on my development system,
15 # because:
16
17 # - Thread scheduling is reliably deterministic only with LWP
18 # - The PRN sequence produced by random() isn't portable
19 # - Shell builtin kill appears not to do the job in MinGW
20 # - The Windows server tries to run as service when -d isn't
21 #   specified
22 #
23 # TODO address these shortcomings.
24 #
25 if [ "`uname -s`" != "Linux" ]  # lame approx. of "random() behaves like mine"
26 then echo "Warning: smoke test not expected to work on this system!" >&2
27 elif [ `sed -n 's/empthread *:= *\(.*\)/\1/p' <GNUmakefile` != LWP ]
28 then echo "Warning: smoke test not expected to work with this thread package!" >&2
29 fi
30
31 create_sandbox
32
33 exec 3>sandbox/smoke.out
34
35 # Create world and start server
36 src/util/files -e sandbox/etc/empire/econfig -f >&3
37 src/util/fairland -e sandbox/etc/empire/econfig -q -s sandbox/newcap_script -R 1 10 30
38 start_server
39 src/client/empire POGO peter <sandbox/newcap_script >/dev/null
40
41 # Feed player input
42 need_update=
43 for i in "$srcdir"/tests/smoke/[0-9]*
44 do
45     t="${i##*/}"
46     if [ "$need_update" ]
47     then
48         echo "Update Turn $t starting" >&3
49         src/client/empire POGO peter <<EOF >&3
50 power new
51 report *
52 cen * ?own#0
53 comm * ?own#0
54 reso * ?own#0
55 force
56 EOF
57         echo "Update Turn $t completed successfully" >&3
58     fi
59     for j in "$i"/*
60     do
61         p="${j##*/}"
62         echo "Player $p Turn $t starting" >&3
63         if [ $p -eq 0 ]
64         then c=POGO r=peter
65         else c="${p#0}"; r="$c"
66         fi
67         src/client/empire "$c" "$r" <$j >&3
68         echo "Player $p Turn $t completed successfully" >&3
69     done
70     need_update=y
71 done
72
73 # Stop server
74 stop_server
75
76 exec 3>&-
77
78 src/util/empdump -e sandbox/etc/empire/econfig -x >sandbox/smoke.xdump
79
80 # Smoke test completed; compare results
81 cmp_out smoke.out var/empire/server.log var/empire/journal.log smoke.xdump