Build doc: fix typos.
[tails.git] / run_test_suite
blob5e4655f07bb6e82df558cabddd92d40e6949db29
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 obfs4proxy
24 openssh-server
25 ovmf
26 pry
27 python-jabberbot
28 python-potr
29 qemu-kvm
30 qemu-system-x86
31 redir
32 ruby-guestfs
33 ruby-json
34 ruby-libvirt
35 ruby-net-irc
36 ruby-packetfu
37 ruby-rb-inotify
38 ruby-rjb
39 ruby-rspec
40 ruby-test-unit
41 seabios
42 tcpdump
43 tor
44 unclutter
45 virt-viewer
46 xvfb
49 usage() {
50 echo "Usage: $NAME [OPTION]... [--] [CUCUMBER_ARGS]...
51 Sets up an appropriate environment and invokes cucumber. Note that this script
52 must be run from the Tails source directory root.
54 Options for '@product' features:
55 --artifacts-base-uri URI
56 Pretend that the artifact is located at URI when printing
57 its location during a scenario failure. This is useful if
58 you intend to serve the artifacts via the web, for
59 instance.
60 --capture Captures failed scenarios into videos stored in the
61 temporary directory (see --tmpdir below) using x264
62 encoding. Requires x264.
63 --capture-all Keep videos for all scenarios, including those that
64 succeed (implies --capture).
65 --interactive-debugging
66 On failure, pause test suite until pressing Enter. Also
67 offer the option to open an interactive Ruby shell (pry)
68 in the Cucumber world's context.
69 --keep-snapshots Don't ever delete any snapshots (including ones marked as
70 temporary). This can be a big time saver when debugging new
71 features.
72 --retry-find Print a warning whenever Sikuli fails to find an image
73 and allow *one* retry after pressing ENTER. This is useful
74 for updating outdated images.
75 --tmpdir Directory where various temporary files are written
76 during a test, e.g. VM snapshots and memory dumps,
77 failure screenshots, pcap files and disk images
78 (default is TMPDIR in the environment, and if unset,
79 /tmp/TailsToaster).
80 --view Shows the test session in a windows. Requires x11vnc
81 and tigervnc-viewer.
82 --vnc-server-only Starts a VNC server for the test session. Requires x11vnc.
83 --iso IMAGE Test '@product' features using IMAGE.
84 --old-iso IMAGE For some '@product' features (e.g. usb_install) we need
85 an older version of Tails, which this options sets to
86 IMAGE. If none is given, it defaults to the same IMAGE
87 given by --iso, which will be good enough for most testing
88 purposes.
90 Note that '@source' features has no relevant options.
92 CUCUMBER_ARGS can be used to specify which features to be run, but also any
93 cucumber option, although then you must pass \`--\` first to let this wrapper
94 script know that we're done with *its* options. For debugging purposes, a
95 'debug' formatter has been added so pretty debugging can be enabled with
96 \`--format debug\`. You could even combine the default (pretty) formatter with
97 pretty debugging printed to a file with \`--format pretty --format debug
98 --out debug.log\`.
102 error() {
103 echo "${NAME}: error: ${*}" >&2
104 usage
105 exit 1
108 package_installed() {
109 local ret
110 set +o pipefail
111 if dpkg -s "${1}" 2>/dev/null | grep -q "^Status:.*installed"; then
112 ret=0
113 else
114 ret=1
116 set -o pipefail
117 return ${ret}
120 check_dependencies() {
121 while [ -n "${1:-}" ]; do
122 if ! which "${1}" >/dev/null && ! package_installed "${1}" ; then
123 error "'${1}' is missing, please install it and run again."
125 shift
126 done
129 display_in_use() {
130 [ -e "/tmp/.X${1#:}-lock" ] || [ -e "/tmp/.X11-unix/X${1#:}" ]
133 next_free_display() {
134 display_nr=0
135 while display_in_use ":${display_nr}"; do
136 display_nr=$((display_nr+1))
137 done
138 echo ":${display_nr}"
141 test_suite_cleanup() {
142 (kill -0 ${XVFB_PID} 2>/dev/null && kill ${XVFB_PID}) || /bin/true
145 start_xvfb() {
146 Xvfb $TARGET_DISPLAY -screen 0 1024x768x24+32 >/dev/null 2>&1 &
147 XVFB_PID=$!
148 # Wait for Xvfb to run on TARGET_DISPLAY
149 until display_in_use $TARGET_DISPLAY; do
150 sleep 1
151 done
152 echo "Virtual X framebuffer started on display ${TARGET_DISPLAY}"
153 # Hide the mouse cursor so it won't mess up Sikuli's screen scanning
154 unclutter -display $TARGET_DISPLAY -root -idle 0.1 >/dev/null 2>&1 &
157 start_vnc_server() {
158 check_dependencies x11vnc
159 VNC_SERVER_PORT="$(x11vnc -listen localhost -display ${TARGET_DISPLAY} \
160 -bg -nopw -forever 2>&1 | \
161 grep -m 1 "^PORT=[0-9]\+" | sed 's/^PORT=//')"
162 echo "VNC server running on: localhost:${VNC_SERVER_PORT}"
165 start_vnc_viewer() {
166 check_dependencies tigervnc-viewer
167 xtigervncviewer -nojpeg -viewonly localhost:${VNC_SERVER_PORT} 1>/dev/null 2>&1 &
170 capture_session() {
171 check_dependencies libvpx1
172 echo "Capturing guest display into ${CAPTURE_FILE}"
173 avconv -f x11grab -s 1024x768 -r 15 -i ${TARGET_DISPLAY}.0 -an \
174 -vcodec libvpx -y "${CAPTURE_FILE}" >/dev/null 2>&1 &
177 # main script
179 # Unset all environment variables used by this script to pass options
180 # to cucumber, except TMPDIR since we explicitly want to support
181 # setting it that way.
182 ARTIFACTS_BASE_URI=
183 CAPTURE=
184 CAPTURE_ALL=
185 LOG_FILE=
186 VNC_VIEWER=
187 VNC_SERVER=
188 INTERACTIVE_DEBUGGING=
189 KEEP_SNAPSHOTS=
190 SIKULI_RETRY_FINDFAILED=
191 TAILS_ISO=
192 OLD_TAILS_ISO=
194 LONGOPTS="artifacts-base-uri:,view,vnc-server-only,capture,capture-all,help,tmpdir:,keep-snapshots,retry-find,iso:,old-iso:,interactive-debugging"
195 OPTS=$(getopt -o "" --longoptions $LONGOPTS -n "${NAME}" -- "$@")
196 eval set -- "$OPTS"
197 while [ $# -gt 0 ]; do
198 case $1 in
199 --artifacts-base-uri)
200 shift
201 export ARTIFACTS_BASE_URI="${1}"
203 --view)
204 VNC_VIEWER=yes
205 VNC_SERVER=yes
207 --vnc-server-only)
208 VNC_VIEWER=
209 VNC_SERVER=yes
211 --capture)
212 check_dependencies x264
213 export CAPTURE="yes"
215 --capture-all)
216 check_dependencies x264
217 export CAPTURE="yes"
218 export CAPTURE_ALL="yes"
220 --interactive-debugging)
221 export INTERACTIVE_DEBUGGING="yes"
223 --keep-snapshots)
224 export KEEP_SNAPSHOTS="yes"
226 --retry-find)
227 export SIKULI_RETRY_FINDFAILED="yes"
229 --tmpdir)
230 shift
231 export TMPDIR="$(readlink -f $1)"
233 --iso)
234 shift
235 export TAILS_ISO="$(readlink -f $1)"
237 --old-iso)
238 shift
239 export OLD_TAILS_ISO="$(readlink -f $1)"
241 --help)
242 usage
243 exit 0
246 shift
247 break
249 esac
250 shift
251 done
253 trap "test_suite_cleanup" EXIT HUP INT QUIT TERM
255 check_dependencies ${GENERAL_DEPENDENCIES}
257 TARGET_DISPLAY=$(next_free_display)
259 start_xvfb
261 if [ -n "${VNC_SERVER:-}" ]; then
262 start_vnc_server
264 if [ -n "${VNC_VIEWER:-}" ]; then
265 start_vnc_viewer
268 export SIKULI_HOME="/usr/share/java"
269 export DISPLAY=${TARGET_DISPLAY}
271 cucumber ${@}