Improve "Leak prevention" section.
[tails/pzajda.git] / run_test_suite
blob3edfafcdc04c1bd8a1e92b66d7f50bc6c75367e8
1 #!/bin/bash
2 # Note that we must use bash since we are gonna source files
3 # that have bashisms in them.
5 set -e
7 NAME=$(basename ${0})
9 usage() {
10 echo "Usage: $NAME [OPTION]... [FEATURE]...
11 Sets up an appropriate environment and tests FEATUREs (all by default). Note
12 that this script must be run from the Tails source directory root.
14 Options for '@product' features:
15 --capture=FILE Captures the test session into FILE using VP8 encoding.
16 Requires ffmpeg and libvpx1.
17 --debug Display various debugging information while running the
18 test suite.
19 --keep-snapshots Don't ever delete the background snapshots. This can a big
20 time saver when debugging new features.
21 --temp-dir Directory where various temporary files are written
22 during a test, e.g. VM snapshots and memory dumps,
23 failure screenshots, pcap files and disk images
24 (default is /tmp/TailsToaster).
25 --view Shows the test session in a windows. Requires x11vnc
26 and xtightvncviewer.
27 --vnc-server-only Starts a VNC server for the test session. Requires x11vnc.
28 --iso=IMAGE Test '@product' features using IMAGE. If none is given,
29 the ISO with most recent creation date (according to the
30 ISO's label) in the current directory will be used.
31 --old-iso=IMAGE For some '@product' features (e.g. usb_install) we need
32 an older version of Tails, which this options sets to
33 IMAGE. If none is given, the ISO with the least recent
34 creation date will be used.
36 Note that '@source' features has no relevant options.
40 error() {
41 echo "${NAME}: error: ${*}" >&2
42 usage
43 exit 1
46 check_dependency() {
47 if ! which "${1}" >/dev/null && \
48 ! dpkg -s "${1}" 2>/dev/null | grep -q "^Status:.*installed"; then
49 error "'${1}' is missing, please install it and run again. Aborting..."
53 display_in_use() {
54 [ -e "/tmp/.X${1#:}-lock" ] || [ -e "/tmp/.X11-unix/X${1#:}" ]
57 next_free_display() {
58 display_nr=0
59 while display_in_use ":${display_nr}"; do
60 display_nr=$((display_nr+1))
61 done
62 echo ":${display_nr}"
65 start_xvfb() {
66 Xvfb $TARGET_DISPLAY -screen 0 1024x768x24+32 >/dev/null 2>&1 &
67 XVFB_PID=$!
68 trap "kill -0 ${XVFB_PID} 2>/dev/null && kill -9 ${XVFB_PID}; \
69 rm -f /tmp/.X${TARGET_DISPLAY#:}-lock" EXIT
70 # Wait for Xvfb to run on TARGET_DISPLAY
71 until display_in_use $TARGET_DISPLAY; do
72 sleep 1
73 done
74 echo "Virtual X framebuffer started on display ${TARGET_DISPLAY}"
75 # Hide the mouse cursor so it won't mess up Sikuli's screen scanning
76 unclutter -display $TARGET_DISPLAY -root -idle 0 >/dev/null 2>&1 &
79 start_vnc_server() {
80 check_dependency x11vnc
81 VNC_SERVER_PORT="$(x11vnc -listen localhost -display ${TARGET_DISPLAY} \
82 -bg -nopw 2>&1 | \
83 grep -m 1 "^PORT=[0-9]\+" | sed 's/^PORT=//')"
84 echo "VNC server running on: localhost:${VNC_SERVER_PORT}"
87 start_vnc_viewer() {
88 check_dependency xtightvncviewer
89 xtightvncviewer -viewonly localhost:${VNC_SERVER_PORT} 1>/dev/null 2>&1 &
92 capture_session() {
93 check_dependency ffmpeg
94 check_dependency libvpx1
95 echo "Capturing guest display into ${CAPTURE_FILE}"
96 ffmpeg -f x11grab -s 1024x768 -r 15 -i ${TARGET_DISPLAY}.0 -an \
97 -vcodec libvpx -y "${CAPTURE_FILE}" >/dev/null 2>&1 &
100 # main script
102 unset CAPTURE_FILE VNC_VIEWER VNC_SERVER
103 unset DEBUG KEEP_SNAPSHOTS TEMP_DIR ISO OLD_ISO
104 SHORTOPTS="a:c"
105 LONGOPTS="view,vnc-server-only,capture:,help,temp-dir:,keep-snapshots,iso:,old-iso:,debug"
106 OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "${NAME}" -- "$@")
107 eval set -- "$OPTS"
108 while [ $# -gt 0 ]; do
109 case $1 in
110 --view)
111 VNC_VIEWER=yes
112 VNC_SERVER=yes
114 --vnc-server-only)
115 VNC_VIEWER=
116 VNC_SERVER=yes
118 --capture)
119 shift
120 CAPTURE_FILE="$1"
122 --debug)
123 export DEBUG="yes"
125 --keep-snapshots)
126 export KEEP_SNAPSHOTS="yes"
128 --temp-dir)
129 shift
130 export TEMP_DIR="$(readlink -f $1)"
132 --iso)
133 shift
134 export ISO="$(readlink -f $1)"
136 --old-iso)
137 shift
138 export OLD_ISO="$(readlink -f $1)"
140 --help)
141 usage
142 exit 0
145 shift
146 break
148 esac
149 shift
150 done
152 for dep in git libvirt-bin libvirt-dev virt-viewer libsikuli-script-java \
153 libxslt1-dev libxml2-dev tcpdump xvfb graphicsmagick-imagemagick-compat; do
154 check_dependency "${dep}"
155 done
157 TARGET_DISPLAY=$(next_free_display)
159 start_xvfb
161 if [ -n "${CAPTURE_FILE}" ]; then
162 capture_session
164 if [ -n "${VNC_SERVER}" ]; then
165 start_vnc_server
167 if [ -n "${VNC_VIEWER}" ]; then
168 start_vnc_viewer
171 export SIKULI_HOME="/usr/share/java"
172 export DISPLAY=${TARGET_DISPLAY}
173 . features/.rvmrc
174 check_dependency cucumber
175 if [ -z "${*}" ]; then
176 cucumber --format ExtraHooks::Pretty features
177 else
178 cucumber --format ExtraHooks::Pretty features/step_definitions features/support ${*}