Capitalize title
[tails-test.git] / run_test_suite
blob030413addbb80977dcad934d782a004c692e177b
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 --temp-dir Directory where various temporary files are written
21 during a test, e.g. VM snapshots and memory dumps,
22 failure screenshots, pcap files and disk images
23 (default is /tmp/TailsToaster).
24 --view Shows the test session in a windows. Requires x11vnc
25 and xtightvncviewer.
26 --vnc-server-only Starts a VNC server for the test session. Requires x11vnc.
27 --iso IMAGE Test '@product' features using IMAGE. If none is given,
28 the ISO with most recent creation date (according to the
29 ISO's label) in the current directory will be used.
30 --old-iso IMAGE For some '@product' features (e.g. usb_install) we need
31 an older version of Tails, which this options sets to
32 IMAGE. If none is given, the ISO with the least recent
33 creation date will be used.
35 Note that '@source' features has no relevant options.
39 error() {
40 echo "${NAME}: error: ${*}" >&2
41 usage
42 exit 1
45 check_dependency() {
46 if ! which "${1}" >/dev/null && \
47 ! dpkg -s "${1}" 2>/dev/null | grep -q "^Status:.*installed"; then
48 error "'${1}' is missing, please install it and run again. Aborting..."
52 display_in_use() {
53 [ -e "/tmp/.X${1#:}-lock" ] || [ -e "/tmp/.X11-unix/X${1#:}" ]
56 next_free_display() {
57 display_nr=0
58 while display_in_use ":${display_nr}"; do
59 display_nr=$((display_nr+1))
60 done
61 echo ":${display_nr}"
64 start_xvfb() {
65 Xvfb $TARGET_DISPLAY -screen 0 1024x768x24+32 >/dev/null 2>&1 &
66 XVFB_PID=$!
67 trap "kill -0 ${XVFB_PID} 2>/dev/null && kill -9 ${XVFB_PID}; \
68 rm -f /tmp/.X${TARGET_DISPLAY#:}-lock" EXIT
69 # Wait for Xvfb to run on TARGET_DISPLAY
70 until display_in_use $TARGET_DISPLAY; do
71 sleep 1
72 done
73 echo "Virtual X framebuffer started on display ${TARGET_DISPLAY}"
74 # Hide the mouse cursor so it won't mess up Sikuli's screen scanning
75 unclutter -display $TARGET_DISPLAY -root -idle 0 >/dev/null 2>&1 &
78 start_vnc_server() {
79 check_dependency x11vnc
80 VNC_SERVER_PORT="$(x11vnc -listen localhost -display ${TARGET_DISPLAY} \
81 -bg -nopw 2>&1 | \
82 grep -m 1 "^PORT=[0-9]\+" | sed 's/^PORT=//')"
83 echo "VNC server running on: localhost:${VNC_SERVER_PORT}"
86 start_vnc_viewer() {
87 check_dependency xtightvncviewer
88 xtightvncviewer -viewonly localhost:${VNC_SERVER_PORT} 1>/dev/null 2>&1 &
91 capture_session() {
92 check_dependency ffmpeg
93 check_dependency libvpx1
94 echo "Capturing guest display into ${CAPTURE_FILE}"
95 ffmpeg -f x11grab -s 1024x768 -r 15 -i ${TARGET_DISPLAY}.0 -an \
96 -vcodec libvpx -y "${CAPTURE_FILE}" >/dev/null 2>&1 &
99 # main script
101 CAPTURE_FILE=
102 VNC_VIEWER=
103 VNC_SERVER=
104 DEBUG=
105 KEEP_SNAPSHOTS=
106 TEMP_DIR=
107 ISO=
108 OLD_ISO=
110 SHORTOPTS="a:c"
111 LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,iso:,old-iso:,debug"
112 OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "${NAME}" -- "$@")
113 eval set -- "$OPTS"
114 while [ $# -gt 0 ]; do
115 case $1 in
116 --view)
117 VNC_VIEWER=yes
118 VNC_SERVER=yes
120 --vnc-server-only)
121 VNC_VIEWER=
122 VNC_SERVER=yes
124 --capture)
125 shift
126 CAPTURE_FILE="$1"
128 --debug)
129 export DEBUG="yes"
131 --keep-snapshots)
132 export KEEP_SNAPSHOTS="yes"
134 --temp-dir)
135 shift
136 export TEMP_DIR="$(readlink -f $1)"
138 --iso)
139 shift
140 export ISO="$(readlink -f $1)"
142 --old-iso)
143 shift
144 export OLD_ISO="$(readlink -f $1)"
146 --help)
147 usage
148 exit 0
151 shift
152 break
154 esac
155 shift
156 done
158 for dep in git libvirt-bin libvirt-dev virt-viewer libsikuli-script-java \
159 tcpdump xvfb; do
160 check_dependency "${dep}"
161 done
163 TARGET_DISPLAY=$(next_free_display)
165 start_xvfb
167 if [ -n "${CAPTURE_FILE}" ]; then
168 capture_session
170 if [ -n "${VNC_SERVER}" ]; then
171 start_vnc_server
173 if [ -n "${VNC_VIEWER}" ]; then
174 start_vnc_viewer
177 export JAVA_HOME="/usr/lib/jvm/java-6-openjdk-amd64"
178 export SIKULI_HOME="/usr/share/java"
179 export DISPLAY=${TARGET_DISPLAY}
180 check_dependency cucumber
181 if [ -z "${*}" ]; then
182 cucumber --format ExtraHooks::Pretty features
183 else
184 cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${*}