"new identity" looses the content of the clipboard (#7709)
[tails/matsa.git] / run_test_suite
blobcf7abeb92c8b5445c1ec27cb3ec5da0a136da3af
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 --pause-on-fail On failure, pause test suite until pressing Enter. This is
19 useful for investigating the state of the VM guest to see
20 exactly why a test failed.
21 --keep-snapshots Don't ever delete the background snapshots. This can a big
22 time saver when debugging new features.
23 --retry-find Print a warning whenever Sikuli fails to find an image
24 and allow *one* retry after pressing ENTER. This is useful
25 for updating outdated images.
26 --temp-dir Directory where various temporary files are written
27 during a test, e.g. VM snapshots and memory dumps,
28 failure screenshots, pcap files and disk images
29 (default is /tmp/TailsToaster).
30 --view Shows the test session in a windows. Requires x11vnc
31 and xtightvncviewer.
32 --vnc-server-only Starts a VNC server for the test session. Requires x11vnc.
33 --iso IMAGE Test '@product' features using IMAGE. If none is given,
34 the ISO with most recent creation date (according to the
35 ISO's label) in the current directory will be used.
36 --old-iso IMAGE For some '@product' features (e.g. usb_install) we need
37 an older version of Tails, which this options sets to
38 IMAGE. If none is given, the ISO with the least recent
39 creation date will be used.
41 Note that '@source' features has no relevant options.
45 error() {
46 echo "${NAME}: error: ${*}" >&2
47 usage
48 exit 1
51 check_dependency() {
52 if ! which "${1}" >/dev/null && \
53 ! dpkg -s "${1}" 2>/dev/null | grep -q "^Status:.*installed"; then
54 error "'${1}' is missing, please install it and run again. Aborting..."
58 display_in_use() {
59 [ -e "/tmp/.X${1#:}-lock" ] || [ -e "/tmp/.X11-unix/X${1#:}" ]
62 next_free_display() {
63 display_nr=0
64 while display_in_use ":${display_nr}"; do
65 display_nr=$((display_nr+1))
66 done
67 echo ":${display_nr}"
70 start_xvfb() {
71 Xvfb $TARGET_DISPLAY -screen 0 1024x768x24+32 >/dev/null 2>&1 &
72 XVFB_PID=$!
73 trap "kill -0 ${XVFB_PID} 2>/dev/null && kill -9 ${XVFB_PID}; \
74 rm -f /tmp/.X${TARGET_DISPLAY#:}-lock" EXIT
75 # Wait for Xvfb to run on TARGET_DISPLAY
76 until display_in_use $TARGET_DISPLAY; do
77 sleep 1
78 done
79 echo "Virtual X framebuffer started on display ${TARGET_DISPLAY}"
80 # Hide the mouse cursor so it won't mess up Sikuli's screen scanning
81 unclutter -display $TARGET_DISPLAY -root -idle 0 >/dev/null 2>&1 &
84 start_vnc_server() {
85 check_dependency x11vnc
86 VNC_SERVER_PORT="$(x11vnc -listen localhost -display ${TARGET_DISPLAY} \
87 -bg -nopw 2>&1 | \
88 grep -m 1 "^PORT=[0-9]\+" | sed 's/^PORT=//')"
89 echo "VNC server running on: localhost:${VNC_SERVER_PORT}"
92 start_vnc_viewer() {
93 check_dependency xtightvncviewer
94 xtightvncviewer -viewonly localhost:${VNC_SERVER_PORT} 1>/dev/null 2>&1 &
97 capture_session() {
98 echo "Capturing guest display into ${CAPTURE_FILE}"
99 ffmpeg -f x11grab -s 1024x768 -r 15 -i ${TARGET_DISPLAY}.0 -an \
100 -vcodec libvpx -y "${CAPTURE_FILE}" >/dev/null 2>&1 &
103 # main script
105 CAPTURE_FILE=
106 VNC_VIEWER=
107 VNC_SERVER=
108 DEBUG=
109 PAUSE_ON_FAIL=
110 KEEP_SNAPSHOTS=
111 SIKULI_RETRY_FINDFAILED=
112 TEMP_DIR=
113 ISO=
114 OLD_ISO=
116 LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,retry-find,iso:,old-iso:,debug,pause-on-fail"
117 OPTS=$(getopt -o "" --longoptions $LONGOPTS -n "${NAME}" -- "$@")
118 eval set -- "$OPTS"
119 while [ $# -gt 0 ]; do
120 case $1 in
121 --view)
122 VNC_VIEWER=yes
123 VNC_SERVER=yes
125 --vnc-server-only)
126 VNC_VIEWER=
127 VNC_SERVER=yes
129 --capture)
130 shift
131 CAPTURE_FILE="$1"
133 --debug)
134 export DEBUG="yes"
136 --pause-on-fail)
137 export PAUSE_ON_FAIL="yes"
139 --keep-snapshots)
140 export KEEP_SNAPSHOTS="yes"
142 --retry-find)
143 export SIKULI_RETRY_FINDFAILED="yes"
145 --temp-dir)
146 shift
147 export TEMP_DIR="$(readlink -f $1)"
149 --iso)
150 shift
151 export ISO="$(readlink -f $1)"
153 --old-iso)
154 shift
155 export OLD_ISO="$(readlink -f $1)"
157 --help)
158 usage
159 exit 0
162 shift
163 break
165 esac
166 shift
167 done
169 for dep in ffmpeg git libvirt-bin libvirt-dev libavcodec-extra-53 libvpx1 \
170 virt-viewer libsikuli-script-java ovmf tcpdump xvfb; do
171 check_dependency "${dep}"
172 done
174 TARGET_DISPLAY=$(next_free_display)
176 start_xvfb
178 if [ -n "${CAPTURE_FILE}" ]; then
179 capture_session
181 if [ -n "${VNC_SERVER}" ]; then
182 start_vnc_server
184 if [ -n "${VNC_VIEWER}" ]; then
185 start_vnc_viewer
188 export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
189 export SIKULI_HOME="/usr/share/java"
190 export DISPLAY=${TARGET_DISPLAY}
191 check_dependency cucumber
192 if [ -z "${*}" ]; then
193 cucumber --format ExtraHooks::Pretty features
194 else
195 cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${*}