tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test-linux.sh (11234B)


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