1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
#! /bin/bash -xe
set -x -e
echo "running as" $(id)
# Detect distribution
. /etc/os-release
if [ "${ID}" == "ubuntu" ]; then
DISTRIBUTION="Ubuntu"
elif [ "${ID}" == "debian" ]; then
DISTRIBUTION="Debian"
else
DISTRIBUTION="Unknown"
fi
# Detect release version if supported
FILE="/etc/lsb-release"
if [ -e $FILE ] ; then
. /etc/lsb-release
RELEASE="${DISTRIB_RELEASE}"
else
RELEASE="unknown"
fi
####
# Taskcluster friendly wrapper for performing fx desktop tests via mozharness.
####
# Inputs, with defaults
: GECKO_PATH ${GECKO_PATH}
: MOZHARNESS_PATH ${MOZHARNESS_PATH}
: MOZHARNESS_URL ${MOZHARNESS_URL}
: MOZHARNESS_SCRIPT ${MOZHARNESS_SCRIPT}
: MOZHARNESS_CONFIG ${MOZHARNESS_CONFIG}
: MOZHARNESS_OPTIONS ${MOZHARNESS_OPTIONS}
: MOZ_ENABLE_WAYLAND ${MOZ_ENABLE_WAYLAND}
: NEED_XVFB ${NEED_XVFB:=true}
: NEED_WINDOW_MANAGER ${NEED_WINDOW_MANAGER:=false}
: NEED_PULSEAUDIO ${NEED_PULSEAUDIO:=false}
: NEED_PIPEWIRE ${NEED_PIPEWIRE:=false}
: NEED_COMPIZ ${NEED_COPMPIZ:=false}
: START_VNC ${START_VNC:=false}
: TASKCLUSTER_INTERACTIVE ${TASKCLUSTER_INTERACTIVE:=false}
: mozharness args "${@}"
: WORKING_DIR ${WORKING_DIR:=$(pwd)}
: WORKSPACE ${WORKSPACE:=${WORKING_DIR%/}/workspace}
set -v
mkdir -p "$WORKSPACE"
cd "$WORKSPACE"
fail() {
echo # make sure error message is on a new line
echo "[test-linux.sh:error]" "${@}"
exit 1
}
# start pulseaudio
maybe_start_pulse() {
if $NEED_PULSEAUDIO; then
# call pulseaudio for Ubuntu only
if [ $DISTRIBUTION == "Ubuntu" ]; then
pulseaudio --daemonize --log-level=4 --log-time=1 --log-target=stderr --start --fail -vvvvv --exit-idle-time=-1 --cleanup-shm --dump-conf
fi
fi
if $NEED_PIPEWIRE; then
pw_pids=()
pipewire &
pw_pids+=($!)
SOCKET="$XDG_RUNTIME_DIR/pipewire-0"
attempts=5
sleep_time=1
while [ ! -S "$SOCKET" ] && [ $attempts -gt 0 ]; do
sleep $sleep_time
sleep_time=$((sleep_time * 2))
attempts=$((attempts - 1))
done
if [ ! -S "$SOCKET" ]; then
ps auxf || :
echo "error: no pipewire socket, retrying the task" >&2
exit 4
fi
wireplumber &
pw_pids+=($!)
pipewire-pulse &
pw_pids+=($!)
fi
}
cleanup_pipewire() {
if [ -n "$pw_pids" ] && [ $TASKCLUSTER_INTERACTIVE = false ]; then
kill "${pw_pids[@]}"
fi
}
# test required parameters are supplied
if [ -z "${MOZHARNESS_PATH}" -a -z "${MOZHARNESS_URL}" ]; then
fail "MOZHARNESS_PATH or MOZHARNESS_URL must be defined";
fi
if [[ -z ${MOZHARNESS_SCRIPT} ]]; then fail "MOZHARNESS_SCRIPT is not set"; fi
if [[ -z ${MOZHARNESS_CONFIG} ]]; then fail "MOZHARNESS_CONFIG is not set"; fi
if [ $MOZ_ENABLE_WAYLAND ]; then
NEED_XVFB=true
NEED_WINDOW_MANAGER=true
fi
# make sure artifact directories exist
mkdir -p "$WORKSPACE/logs"
mkdir -p "$WORKING_DIR/artifacts/public"
mkdir -p "$WORKSPACE/build/blobber_upload_dir"
cleanup_mutter() {
local mutter_pids=`ps aux | grep 'mutter --wayland' | grep -v grep | awk '{print $2}'`
if [ "$mutter_pids" != "" ]; then
echo "Killing the following Mutter processes: $mutter_pids"
sudo kill $mutter_pids
else
echo "No Mutter processes to kill"
fi
}
cleanup() {
local rv=$?
if $NEED_PIPEWIRE; then
cleanup_pipewire
fi
if [ $MOZ_ENABLE_WAYLAND ]; then
cleanup_mutter
fi
if $NEED_XVFB; then
cleanup_xvfb
fi
exit $rv
}
trap cleanup EXIT INT
# Download mozharness with exponential backoff
# curl already applies exponential backoff, but not for all
# failed cases, apparently, as we keep getting failed downloads
# with 404 code.
download_mozharness() {
local max_attempts=10
local timeout=1
local attempt=0
echo "Downloading mozharness"
while [[ $attempt < $max_attempts ]]; do
if curl --fail -o mozharness.zip --retry 10 -L $MOZHARNESS_URL; then
rm -rf mozharness
if unzip -q mozharness.zip -d mozharness; then
return 0
fi
echo "error unzipping mozharness.zip" >&2
else
echo "failed to download mozharness zip" >&2
fi
echo "Download failed, retrying in $timeout seconds..." >&2
sleep $timeout
timeout=$((timeout*2))
attempt=$((attempt+1))
done
fail "Failed to download and unzip mozharness"
}
# Download mozharness if we're told to.
if [ ${MOZHARNESS_URL} ]; then
download_mozharness
rm mozharness.zip
if ! [ -d mozharness ]; then
fail "mozharness zip did not contain mozharness/"
fi
MOZHARNESS_PATH=`pwd`/mozharness
fi
# run XVfb in the background, if necessary
if $NEED_XVFB; then
# note that this file is not available when run under native-worker
. $HOME/scripts/xvfb.sh
start_xvfb '1600x1200x24' 0
fi
if $START_VNC; then
x11vnc > "$WORKING_DIR/artifacts/public/x11vnc.log" 2>&1 &
fi
if $NEED_WINDOW_MANAGER; then
# This is read by xsession to select the window manager
. /etc/lsb-release
if [ $DISTRIBUTION == "Ubuntu" ]; then
xsession_args=()
if [ $RELEASE = "18.04" ]; then
echo export XDG_CURRENT_DESKTOP=GNOME > $HOME/.xsessionrc
elif [ $RELEASE = "24.04" ]; then
# taken from /usr/share/xsessions/ubuntu.desktop
echo export XDG_CURRENT_DESKTOP=ubuntu:GNOME > $HOME/.xsessionrc
echo export GNOME_SHELL_SESSION_MODE=ubuntu >> $HOME/.xsessionrc
xsession_args=("/usr/bin/gnome-session --session=ubuntu")
fi
if [ $MOZ_ENABLE_WAYLAND ]; then
echo export XDG_SESSION_TYPE=wayland >> $HOME/.xsessionrc
else
echo export XDG_SESSION_TYPE=x11 >> $HOME/.xsessionrc
fi
else
:
fi
export XDG_RUNTIME_DIR=$WORKING_DIR
# Start a session bus early instead of leaving it to Xsession, so that we
# can use it for access to e.g. gnome-keyring or the screencast API
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
# if not found, launch a new one
eval `dbus-launch --sh-syntax`
fi
# DISPLAY has already been set above
# XXX: it would be ideal to add a semaphore logic to make sure that the
# window manager is ready
(
# if env var is >8K, we have a seg fault in xsession
unset MOZHARNESS_TEST_PATHS
/etc/X11/Xsession "${xsession_args[@]}" 2>&1 &
)
# Turn off the screen saver and screen locking
gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.desktop.screensaver lock-delay 3600
# Disable the screen saver
xset s off s reset
# This starts the gnome-keyring-daemon with an unlocked login keyring. libsecret uses this to
# store secrets. Firefox uses libsecret to store a key that protects sensitive information like
# credit card numbers.
eval `echo '' | /usr/bin/gnome-keyring-daemon -r -d --unlock --components=secrets`
mount || :
df -h || :
# Wait for gnome-shell to start up
retry_count=10
while ! dbus-send --print-reply=literal --session --dest=org.gnome.Shell --type=method_call /org/gnome/Shell org.freedesktop.DBus.Properties.Get string:org.gnome.Shell string:OverviewActive; do
ps auxf || :
if [ $retry_count = 0 ]; then
echo "gnome-shell still not up, retrying the task" >&2
exit 4
fi
retry_count=$((retry_count - 1))
sleep 5
done
# Sometimes gnome-shell starts up in overview even though the ubuntu-dock
# extension is supposed to disable that. When that happens we never get
# focus and the test harness times out. So tell gnome-shell to get out of
# overview before anything else.
if dbus-send --print-reply=literal --session --dest=org.gnome.Shell --type=method_call /org/gnome/Shell org.freedesktop.DBus.Properties.Get string:org.gnome.Shell string:OverviewActive | grep true; then
dbus-send --session --dest=org.gnome.Shell --type=method_call /org/gnome/Shell org.freedesktop.DBus.Properties.Set string:org.gnome.Shell string:OverviewActive variant:boolean:false
sleep 2
if dbus-send --print-reply=literal --session --dest=org.gnome.Shell --type=method_call /org/gnome/Shell org.freedesktop.DBus.Properties.Get string:org.gnome.Shell string:OverviewActive | grep true; then
echo "gnome-shell didn't get out of overview, retrying the task" >&2
exit 4
fi
fi
# Run mutter as nested wayland compositor to provide Wayland environment
# on top of XVfb.
if [ $MOZ_ENABLE_WAYLAND ]; then
env | grep "DISPLAY"
mutter --display=:0 --wayland --nested &
export WAYLAND_DISPLAY=wayland-0
retry_count=0
max_retries=5
until [ $retry_count -gt $max_retries ]; do
if [ -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]; then
retry_count=$(($max_retries + 1))
else
retry_count=$(($retry_count + 1))
echo "Waiting for Mutter, retry: $retry_count"
sleep 2
fi
done
fi
fi
if [[ $NEED_COMPIZ == true ]] && [[ $RELEASE == 16.04 ]]; then
compiz 2>&1 &
elif [[ $NEED_COMPIZ == true ]] && [[ $RELEASE == 18.04 ]]; then
compiz --replace 2>&1 &
fi
# Bug 1607713 - set cursor position to 0,0 to avoid odd libx11 interaction
if $NEED_WINDOW_MANAGER && [ $DISPLAY == ':0' ]; then
xwit -root -warp 0 0
fi
maybe_start_pulse
# support multiple, space delimited, config files
config_cmds=""
for cfg in $MOZHARNESS_CONFIG; do
config_cmds="${config_cmds} --config-file ${MOZHARNESS_PATH}/configs/${cfg}"
done
if [ -n "$MOZHARNESS_OPTIONS" ]; then
options=""
for option in $MOZHARNESS_OPTIONS; do
options="$options --$option"
done
fi
# Save the computed mozharness command to a binary which is useful for
# interactive mode.
mozharness_bin="$HOME/bin/run-mozharness"
mkdir -p $(dirname $mozharness_bin)
echo -e "#!/usr/bin/env bash
# Some mozharness scripts assume base_work_dir is in
# the current working directory, see bug 1279237
cd "$WORKSPACE"
cmd=\"${PYTHON:-python3} ${MOZHARNESS_PATH}/scripts/${MOZHARNESS_SCRIPT} ${config_cmds} ${options} ${@} \${@}\"
echo \"Running: \${cmd}\"
exec \${cmd}" > ${mozharness_bin}
chmod +x ${mozharness_bin}
# In interactive mode, the user will be prompted with options for what to do.
if ! $TASKCLUSTER_INTERACTIVE; then
# run the given mozharness script and configs, but pass the rest of the
# arguments in from our own invocation
${mozharness_bin};
fi
# Run a custom mach command (this is typically used by action tasks to run
# harnesses in a particular way)
if [ "$CUSTOM_MACH_COMMAND" ]; then
eval "'$WORKSPACE/build/venv/bin/python' '$WORKSPACE/build/tests/mach' ${CUSTOM_MACH_COMMAND} ${@}"
exit $?
fi
|