Store architecture for each binary package.
[tails.git] / run_test_suite
blobcba6f4d24d43d88986475b78d5a9fc2f6c8d8d04
1 #!/bin/bash
3 set -e
4 set -u
5 set -o pipefail
7 NAME=$(basename ${0})
9 GENERAL_DEPENDENCIES="
10 cucumber
11 devscripts
12 dnsmasq-base
13 gawk
14 git
15 i18nspector
16 libav-tools
17 libcap2-bin
18 libsikuli-script-java
19 libvirt-clients
20 libvirt-daemon-system
21 libvirt-dev
22 libvirt0
23 openjdk-7-jre
24 openssh-server
25 ovmf
26 python-jabberbot
27 python-potr
28 qemu-kvm
29 qemu-system-x86
30 ruby-guestfs
31 ruby-json
32 ruby-libvirt
33 ruby-net-irc
34 ruby-packetfu
35 ruby-rb-inotify
36 ruby-rjb
37 ruby-rspec
38 ruby-test-unit
39 seabios
40 tcpdump
41 unclutter
42 virt-viewer
43 xvfb
46 usage() {
47 echo "Usage: $NAME [OPTION]... [--] [CUCUMBER_ARGS]...
48 Sets up an appropriate environment and invokes cucumber. Note that this script
49 must be run from the Tails source directory root.
51 Options for '@product' features:
52 --artifacts-base-uri URI
53 Pretend that the artifact is located at URI when printing
54 its location during a scenario failure. This is useful if
55 you intend to serve the artifacts via the web, for
56 instance.
57 --capture Captures failed scenarios into videos stored in the
58 temporary directory (see --tmpdir below) using x264
59 encoding. Requires x264.
60 --capture-all Keep videos for all scenarios, including those that
61 succeed (implies --capture).
62 --pause-on-fail On failure, pause test suite until pressing Enter. This is
63 useful for investigating the state of the VM guest to see
64 exactly why a test failed.
65 --keep-snapshots Don't ever delete any snapshots (including ones marked as
66 temporary). This can be a big time saver when debugging new
67 features.
68 --retry-find Print a warning whenever Sikuli fails to find an image
69 and allow *one* retry after pressing ENTER. This is useful
70 for updating outdated images.
71 --tmpdir Directory where various temporary files are written
72 during a test, e.g. VM snapshots and memory dumps,
73 failure screenshots, pcap files and disk images
74 (default is TMPDIR in the environment, and if unset,
75 /tmp/TailsToaster).
76 --view Shows the test session in a windows. Requires x11vnc
77 and xtightvncviewer.
78 --vnc-server-only Starts a VNC server for the test session. Requires x11vnc.
79 --iso IMAGE Test '@product' features using IMAGE.
80 --old-iso IMAGE For some '@product' features (e.g. usb_install) we need
81 an older version of Tails, which this options sets to
82 IMAGE. If none is given, it defaults to the same IMAGE
83 given by --iso, which will be good enough for most testing
84 purposes.
86 Note that '@source' features has no relevant options.
88 CUCUMBER_ARGS can be used to specify which features to be run, but also any
89 cucumber option, although then you must pass \`--\` first to let this wrapper
90 script know that we're done with *its* options. For debugging purposes, a
91 'debug' formatter has been added so pretty debugging can be enabled with
92 \`--format debug\`. You could even combine the default (pretty) formatter with
93 pretty debugging printed to a file with \`--format pretty --format debug
94 --out debug.log\`.
98 error() {
99 echo "${NAME}: error: ${*}" >&2
100 usage
101 exit 1
104 package_installed() {
105 local ret
106 set +o pipefail
107 if dpkg -s "${1}" 2>/dev/null | grep -q "^Status:.*installed"; then
108 ret=0
109 else
110 ret=1
112 set -o pipefail
113 return ${ret}
116 check_dependencies() {
117 while [ -n "${1:-}" ]; do
118 if ! which "${1}" >/dev/null && ! package_installed "${1}" ; then
119 error "'${1}' is missing, please install it and run again."
121 shift
122 done
125 display_in_use() {
126 [ -e "/tmp/.X${1#:}-lock" ] || [ -e "/tmp/.X11-unix/X${1#:}" ]
129 next_free_display() {
130 display_nr=0
131 while display_in_use ":${display_nr}"; do
132 display_nr=$((display_nr+1))
133 done
134 echo ":${display_nr}"
137 test_suite_cleanup() {
138 (kill -0 ${XVFB_PID} 2>/dev/null && kill ${XVFB_PID}) || /bin/true
141 start_xvfb() {
142 Xvfb $TARGET_DISPLAY -screen 0 1024x768x24+32 >/dev/null 2>&1 &
143 XVFB_PID=$!
144 # Wait for Xvfb to run on TARGET_DISPLAY
145 until display_in_use $TARGET_DISPLAY; do
146 sleep 1
147 done
148 echo "Virtual X framebuffer started on display ${TARGET_DISPLAY}"
149 # Hide the mouse cursor so it won't mess up Sikuli's screen scanning
150 unclutter -display $TARGET_DISPLAY -root -idle 0 >/dev/null 2>&1 &
153 start_vnc_server() {
154 check_dependencies x11vnc
155 VNC_SERVER_PORT="$(x11vnc -listen localhost -display ${TARGET_DISPLAY} \
156 -bg -nopw -forever 2>&1 | \
157 grep -m 1 "^PORT=[0-9]\+" | sed 's/^PORT=//')"
158 echo "VNC server running on: localhost:${VNC_SERVER_PORT}"
161 start_vnc_viewer() {
162 check_dependencies xtightvncviewer
163 xtightvncviewer -viewonly localhost:${VNC_SERVER_PORT} 1>/dev/null 2>&1 &
166 capture_session() {
167 check_dependencies libvpx1
168 echo "Capturing guest display into ${CAPTURE_FILE}"
169 avconv -f x11grab -s 1024x768 -r 15 -i ${TARGET_DISPLAY}.0 -an \
170 -vcodec libvpx -y "${CAPTURE_FILE}" >/dev/null 2>&1 &
173 # main script
175 # Unset all environment variables used by this script to pass options
176 # to cucumber, except TMPDIR since we explicitly want to support
177 # setting it that way.
178 ARTIFACTS_BASE_URI=
179 CAPTURE=
180 CAPTURE_ALL=
181 LOG_FILE=
182 VNC_VIEWER=
183 VNC_SERVER=
184 PAUSE_ON_FAIL=
185 KEEP_SNAPSHOTS=
186 SIKULI_RETRY_FINDFAILED=
187 TAILS_ISO=
188 OLD_TAILS_ISO=
190 LONGOPTS="artifacts-base-uri:,view,vnc-server-only,capture,capture-all,help,tmpdir:,keep-snapshots,retry-find,iso:,old-iso:,pause-on-fail"
191 OPTS=$(getopt -o "" --longoptions $LONGOPTS -n "${NAME}" -- "$@")
192 eval set -- "$OPTS"
193 while [ $# -gt 0 ]; do
194 case $1 in
195 --artifacts-base-uri)
196 shift
197 export ARTIFACTS_BASE_URI="${1}"
199 --view)
200 VNC_VIEWER=yes
201 VNC_SERVER=yes
203 --vnc-server-only)
204 VNC_VIEWER=
205 VNC_SERVER=yes
207 --capture)
208 check_dependencies x264
209 export CAPTURE="yes"
211 --capture-all)
212 check_dependencies x264
213 export CAPTURE="yes"
214 export CAPTURE_ALL="yes"
216 --pause-on-fail)
217 export PAUSE_ON_FAIL="yes"
219 --keep-snapshots)
220 export KEEP_SNAPSHOTS="yes"
222 --retry-find)
223 export SIKULI_RETRY_FINDFAILED="yes"
225 --tmpdir)
226 shift
227 export TMPDIR="$(readlink -f $1)"
229 --iso)
230 shift
231 export TAILS_ISO="$(readlink -f $1)"
233 --old-iso)
234 shift
235 export OLD_TAILS_ISO="$(readlink -f $1)"
237 --help)
238 usage
239 exit 0
242 shift
243 break
245 esac
246 shift
247 done
249 trap "test_suite_cleanup" EXIT HUP INT QUIT TERM
251 check_dependencies ${GENERAL_DEPENDENCIES}
253 TARGET_DISPLAY=$(next_free_display)
255 start_xvfb
257 if [ -n "${VNC_SERVER:-}" ]; then
258 start_vnc_server
260 if [ -n "${VNC_VIEWER:-}" ]; then
261 start_vnc_viewer
264 export SIKULI_HOME="/usr/share/java"
265 export DISPLAY=${TARGET_DISPLAY}
267 cucumber ${@}