Add placeholder in changelog so that we don't forget it.
[tails-test.git] / run_test_suite
blob9f6d70aad2c41d58dd3cee8a32c97995e392f2ae
1 #!/bin/sh
3 set -e
4 set -u
6 NAME=$(basename ${0})
8 usage() {
9 echo "Usage: $NAME [OPTION]... [FEATURE]...
10 Sets up an appropriate environment and tests FEATUREs (all by default). Note
11 that this script must be run from the Tails source directory root.
13 Options for '@product' features:
14 --capture FILE Captures the test session into FILE using VP8 encoding.
15 Requires ffmpeg and libvpx1.
16 --debug Display various debugging information while running the
17 test suite.
18 --keep-snapshots Don't ever delete the background snapshots. This can a big
19 time saver when debugging new features.
20 --retry-find Print a warning whenever Sikuli fails to find an image
21 and allow *one* retry after pressing ENTER. This is useful
22 for updating outdated images.
23 --temp-dir Directory where various temporary files are written
24 during a test, e.g. VM snapshots and memory dumps,
25 failure screenshots, pcap files and disk images
26 (default is /tmp/TailsToaster).
27 --view Shows the test session in a windows. Requires x11vnc
28 and xtightvncviewer.
29 --vnc-server-only Starts a VNC server for the test session. Requires x11vnc.
30 --iso IMAGE Test '@product' features using IMAGE. If none is given,
31 the ISO with most recent creation date (according to the
32 ISO's label) in the current directory will be used.
33 --old-iso IMAGE For some '@product' features (e.g. usb_install) we need
34 an older version of Tails, which this options sets to
35 IMAGE. If none is given, the ISO with the least recent
36 creation date will be used.
38 Note that '@source' features has no relevant options.
42 error() {
43 echo "${NAME}: error: ${*}" >&2
44 usage
45 exit 1
48 check_dependency() {
49 if ! which "${1}" >/dev/null && \
50 ! dpkg -s "${1}" 2>/dev/null | grep -q "^Status:.*installed"; then
51 error "'${1}' is missing, please install it and run again. Aborting..."
55 display_in_use() {
56 [ -e "/tmp/.X${1#:}-lock" ] || [ -e "/tmp/.X11-unix/X${1#:}" ]
59 next_free_display() {
60 display_nr=0
61 while display_in_use ":${display_nr}"; do
62 display_nr=$((display_nr+1))
63 done
64 echo ":${display_nr}"
67 start_xvfb() {
68 Xvfb $TARGET_DISPLAY -screen 0 1024x768x24+32 >/dev/null 2>&1 &
69 XVFB_PID=$!
70 trap "kill -0 ${XVFB_PID} 2>/dev/null && kill -9 ${XVFB_PID}; \
71 rm -f /tmp/.X${TARGET_DISPLAY#:}-lock" EXIT
72 # Wait for Xvfb to run on TARGET_DISPLAY
73 until display_in_use $TARGET_DISPLAY; do
74 sleep 1
75 done
76 echo "Virtual X framebuffer started on display ${TARGET_DISPLAY}"
77 # Hide the mouse cursor so it won't mess up Sikuli's screen scanning
78 unclutter -display $TARGET_DISPLAY -root -idle 0 >/dev/null 2>&1 &
81 start_vnc_server() {
82 check_dependency x11vnc
83 VNC_SERVER_PORT="$(x11vnc -listen localhost -display ${TARGET_DISPLAY} \
84 -bg -nopw 2>&1 | \
85 grep -m 1 "^PORT=[0-9]\+" | sed 's/^PORT=//')"
86 echo "VNC server running on: localhost:${VNC_SERVER_PORT}"
89 start_vnc_viewer() {
90 check_dependency xtightvncviewer
91 xtightvncviewer -viewonly localhost:${VNC_SERVER_PORT} 1>/dev/null 2>&1 &
94 capture_session() {
95 check_dependency ffmpeg
96 check_dependency libvpx1
97 echo "Capturing guest display into ${CAPTURE_FILE}"
98 ffmpeg -f x11grab -s 1024x768 -r 15 -i ${TARGET_DISPLAY}.0 -an \
99 -vcodec libvpx -y "${CAPTURE_FILE}" >/dev/null 2>&1 &
102 # main script
104 CAPTURE_FILE=
105 VNC_VIEWER=
106 VNC_SERVER=
107 DEBUG=
108 KEEP_SNAPSHOTS=
109 SIKULI_RETRY_FINDFAILED=
110 TEMP_DIR=
111 ISO=
112 OLD_ISO=
114 LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,retry-find,iso:,old-iso:,debug"
115 OPTS=$(getopt -o "" --longoptions $LONGOPTS -n "${NAME}" -- "$@")
116 eval set -- "$OPTS"
117 while [ $# -gt 0 ]; do
118 case $1 in
119 --view)
120 VNC_VIEWER=yes
121 VNC_SERVER=yes
123 --vnc-server-only)
124 VNC_VIEWER=
125 VNC_SERVER=yes
127 --capture)
128 shift
129 CAPTURE_FILE="$1"
131 --debug)
132 export DEBUG="yes"
134 --keep-snapshots)
135 export KEEP_SNAPSHOTS="yes"
137 --retry-find)
138 export SIKULI_RETRY_FINDFAILED="yes"
140 --temp-dir)
141 shift
142 export TEMP_DIR="$(readlink -f $1)"
144 --iso)
145 shift
146 export ISO="$(readlink -f $1)"
148 --old-iso)
149 shift
150 export OLD_ISO="$(readlink -f $1)"
152 --help)
153 usage
154 exit 0
157 shift
158 break
160 esac
161 shift
162 done
164 for dep in git libvirt-bin libvirt-dev virt-viewer libsikuli-script-java \
165 tcpdump xvfb; do
166 check_dependency "${dep}"
167 done
169 TARGET_DISPLAY=$(next_free_display)
171 start_xvfb
173 if [ -n "${CAPTURE_FILE}" ]; then
174 capture_session
176 if [ -n "${VNC_SERVER}" ]; then
177 start_vnc_server
179 if [ -n "${VNC_VIEWER}" ]; then
180 start_vnc_viewer
183 export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
184 export SIKULI_HOME="/usr/share/java"
185 export DISPLAY=${TARGET_DISPLAY}
186 check_dependency cucumber
187 if [ -z "${*}" ]; then
188 cucumber --format ExtraHooks::Pretty features
189 else
190 cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${*}