Bug 1874234 - don't run linux tests through `mach python`. r=ahal
[gecko.git] / taskcluster / scripts / tester / test-linux.sh
blob250ae40e10e3404185ceac1c5356a61073b96a7f
1 #! /bin/bash -xe
3 set -x -e
5 echo "running as" $(id)
7 # Detect distribution
8 . /etc/os-release
9 if [ "${ID}" == "ubuntu" ]; then
10 DISTRIBUTION="Ubuntu"
11 elif [ "${ID}" == "debian" ]; then
12 DISTRIBUTION="Debian"
13 else
14 DISTRIBUTION="Unknown"
17 # Detect release version if supported
18 FILE="/etc/lsb-release"
19 if [ -e $FILE ] ; then
20 . /etc/lsb-release
21 RELEASE="${DISTRIB_RELEASE}"
22 else
23 RELEASE="unknown"
26 ####
27 # Taskcluster friendly wrapper for performing fx desktop tests via mozharness.
28 ####
30 # Inputs, with defaults
32 : GECKO_PATH ${GECKO_PATH}
33 : MOZHARNESS_PATH ${MOZHARNESS_PATH}
34 : MOZHARNESS_URL ${MOZHARNESS_URL}
35 : MOZHARNESS_SCRIPT ${MOZHARNESS_SCRIPT}
36 : MOZHARNESS_CONFIG ${MOZHARNESS_CONFIG}
37 : MOZHARNESS_OPTIONS ${MOZHARNESS_OPTIONS}
38 : MOZ_ENABLE_WAYLAND ${MOZ_ENABLE_WAYLAND}
39 : NEED_XVFB ${NEED_XVFB:=true}
40 : NEED_WINDOW_MANAGER ${NEED_WINDOW_MANAGER:=false}
41 : NEED_PULSEAUDIO ${NEED_PULSEAUDIO:=false}
42 : NEED_COMPIZ ${NEED_COPMPIZ:=false}
43 : START_VNC ${START_VNC:=false}
44 : TASKCLUSTER_INTERACTIVE ${TASKCLUSTER_INTERACTIVE:=false}
45 : mozharness args "${@}"
46 : WORKING_DIR ${WORKING_DIR:=$(pwd)}
47 : WORKSPACE ${WORKSPACE:=${WORKING_DIR%/}/workspace}
49 set -v
50 mkdir -p "$WORKSPACE"
51 cd "$WORKSPACE"
53 fail() {
54 echo # make sure error message is on a new line
55 echo "[test-linux.sh:error]" "${@}"
56 exit 1
59 # start pulseaudio
60 maybe_start_pulse() {
61 if $NEED_PULSEAUDIO; then
62 # call pulseaudio for Ubuntu only
63 if [ $DISTRIBUTION == "Ubuntu" ]; then
64 pulseaudio --daemonize --log-level=4 --log-time=1 --log-target=stderr --start --fail -vvvvv --exit-idle-time=-1 --cleanup-shm --dump-conf
69 # test required parameters are supplied
70 if [ -z "${MOZHARNESS_PATH}" -a -z "${MOZHARNESS_URL}" ]; then
71 fail "MOZHARNESS_PATH or MOZHARNESS_URL must be defined";
74 if [[ -z ${MOZHARNESS_SCRIPT} ]]; then fail "MOZHARNESS_SCRIPT is not set"; fi
75 if [[ -z ${MOZHARNESS_CONFIG} ]]; then fail "MOZHARNESS_CONFIG is not set"; fi
77 if [ $MOZ_ENABLE_WAYLAND ]; then
78 NEED_XVFB=true
79 NEED_WINDOW_MANAGER=true
82 # make sure artifact directories exist
83 mkdir -p "$WORKSPACE/logs"
84 mkdir -p "$WORKING_DIR/artifacts/public"
85 mkdir -p "$WORKSPACE/build/blobber_upload_dir"
87 cleanup_mutter() {
88 local mutter_pids=`ps aux | grep 'mutter --wayland' | grep -v grep | awk '{print $2}'`
89 if [ "$mutter_pids" != "" ]; then
90 echo "Killing the following Mutter processes: $mutter_pids"
91 sudo kill $mutter_pids
92 else
93 echo "No Mutter processes to kill"
97 cleanup() {
98 local rv=$?
99 if [[ -s $HOME/.xsession-errors ]]; then
100 # To share X issues
101 cp "$HOME/.xsession-errors" "$WORKING_DIR/artifacts/public/xsession-errors.log"
103 if [ $MOZ_ENABLE_WAYLAND ]; then
104 cleanup_mutter
106 if $NEED_XVFB; then
107 cleanup_xvfb
109 exit $rv
111 trap cleanup EXIT INT
113 # Download mozharness with exponential backoff
114 # curl already applies exponential backoff, but not for all
115 # failed cases, apparently, as we keep getting failed downloads
116 # with 404 code.
117 download_mozharness() {
118 local max_attempts=10
119 local timeout=1
120 local attempt=0
122 echo "Downloading mozharness"
124 while [[ $attempt < $max_attempts ]]; do
125 if curl --fail -o mozharness.zip --retry 10 -L $MOZHARNESS_URL; then
126 rm -rf mozharness
127 if unzip -q mozharness.zip -d mozharness; then
128 return 0
130 echo "error unzipping mozharness.zip" >&2
131 else
132 echo "failed to download mozharness zip" >&2
134 echo "Download failed, retrying in $timeout seconds..." >&2
135 sleep $timeout
136 timeout=$((timeout*2))
137 attempt=$((attempt+1))
138 done
140 fail "Failed to download and unzip mozharness"
143 # Download mozharness if we're told to.
144 if [ ${MOZHARNESS_URL} ]; then
145 download_mozharness
146 rm mozharness.zip
148 if ! [ -d mozharness ]; then
149 fail "mozharness zip did not contain mozharness/"
152 MOZHARNESS_PATH=`pwd`/mozharness
155 # run XVfb in the background, if necessary
156 if $NEED_XVFB; then
157 # note that this file is not available when run under native-worker
158 . $HOME/scripts/xvfb.sh
159 start_xvfb '1600x1200x24' 0
162 if $START_VNC; then
163 x11vnc > "$WORKING_DIR/artifacts/public/x11vnc.log" 2>&1 &
166 if $NEED_WINDOW_MANAGER; then
167 # This is read by xsession to select the window manager
168 . /etc/lsb-release
169 if [ $DISTRIBUTION == "Ubuntu" ] && [ $RELEASE == "16.04" ]; then
170 echo DESKTOP_SESSION=ubuntu > $HOME/.xsessionrc
171 elif [ $DISTRIBUTION == "Ubuntu" ] && [ $RELEASE == "18.04" ]; then
172 echo export DESKTOP_SESSION=gnome > $HOME/.xsessionrc
173 echo export XDG_CURRENT_DESKTOP=GNOME > $HOME/.xsessionrc
174 if [ $MOZ_ENABLE_WAYLAND ]; then
175 echo export XDG_SESSION_TYPE=wayland >> $HOME/.xsessionrc
176 else
177 echo export XDG_SESSION_TYPE=x11 >> $HOME/.xsessionrc
179 else
183 # DISPLAY has already been set above
184 # XXX: it would be ideal to add a semaphore logic to make sure that the
185 # window manager is ready
186 /etc/X11/Xsession 2>&1 &
188 # Turn off the screen saver and screen locking
189 gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
190 gsettings set org.gnome.desktop.screensaver lock-enabled false
191 gsettings set org.gnome.desktop.screensaver lock-delay 3600
193 # Disable the screen saver
194 xset s off s reset
196 # This starts the gnome-keyring-daemon with an unlocked login keyring. libsecret uses this to
197 # store secrets. Firefox uses libsecret to store a key that protects sensitive information like
198 # credit card numbers.
199 if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
200 # if not found, launch a new one
201 eval `dbus-launch --sh-syntax`
203 eval `echo '' | /usr/bin/gnome-keyring-daemon -r -d --unlock --components=secrets`
205 # Run mutter as nested wayland compositor to provide Wayland environment
206 # on top of XVfb.
207 if [ $MOZ_ENABLE_WAYLAND ]; then
208 env | grep "DISPLAY"
209 export XDG_RUNTIME_DIR=$WORKING_DIR
210 mutter --display=:0 --wayland --nested &
211 export WAYLAND_DISPLAY=wayland-0
212 retry_count=0
213 max_retries=5
214 until [ $retry_count -gt $max_retries ]; do
215 if [ -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]; then
216 retry_count=$(($max_retries + 1))
217 else
218 retry_count=$(($retry_count + 1))
219 echo "Waiting for Mutter, retry: $retry_count"
220 sleep 2
222 done
226 if [[ $NEED_COMPIZ == true ]] && [[ $RELEASE == 16.04 ]]; then
227 compiz 2>&1 &
228 elif [[ $NEED_COMPIZ == true ]] && [[ $RELEASE == 18.04 ]]; then
229 compiz --replace 2>&1 &
232 # Bug 1607713 - set cursor position to 0,0 to avoid odd libx11 interaction
233 if [ $NEED_WINDOW_MANAGER ] && [ $DISPLAY == ':0' ]; then
234 xwit -root -warp 0 0
237 maybe_start_pulse
239 # For telemetry purposes, the build process wants information about the
240 # source it is running
241 export MOZ_SOURCE_REPO="${GECKO_HEAD_REPOSITORY}"
242 export MOZ_SOURCE_CHANGESET="${GECKO_HEAD_REV}"
244 # support multiple, space delimited, config files
245 config_cmds=""
246 for cfg in $MOZHARNESS_CONFIG; do
247 config_cmds="${config_cmds} --config-file ${MOZHARNESS_PATH}/configs/${cfg}"
248 done
250 if [ -n "$MOZHARNESS_OPTIONS" ]; then
251 options=""
252 for option in $MOZHARNESS_OPTIONS; do
253 options="$options --$option"
254 done
257 # Save the computed mozharness command to a binary which is useful for
258 # interactive mode.
259 mozharness_bin="$HOME/bin/run-mozharness"
260 mkdir -p $(dirname $mozharness_bin)
262 echo -e "#!/usr/bin/env bash
263 # Some mozharness scripts assume base_work_dir is in
264 # the current working directory, see bug 1279237
265 cd "$WORKSPACE"
266 cmd=\"${PYTHON:-python3} ${MOZHARNESS_PATH}/scripts/${MOZHARNESS_SCRIPT} ${config_cmds} ${options} ${@} \${@}\"
267 echo \"Running: \${cmd}\"
268 exec \${cmd}" > ${mozharness_bin}
269 chmod +x ${mozharness_bin}
271 # In interactive mode, the user will be prompted with options for what to do.
272 if ! $TASKCLUSTER_INTERACTIVE; then
273 # run the given mozharness script and configs, but pass the rest of the
274 # arguments in from our own invocation
275 ${mozharness_bin};
278 # Run a custom mach command (this is typically used by action tasks to run
279 # harnesses in a particular way)
280 if [ "$CUSTOM_MACH_COMMAND" ]; then
281 eval "'$WORKSPACE/build/venv/bin/python' '$WORKSPACE/build/tests/mach' ${CUSTOM_MACH_COMMAND} ${@}"
282 exit $?