test-ubuntu.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #! /bin/bash -xe
  2. set -x -e
  3. echo "running as" $(id)
  4. # Detect release version.
  5. . /etc/lsb-release
  6. if [ "${DISTRIB_RELEASE}" == "12.04" ]; then
  7. UBUNTU_1204=1
  8. elif [ "${DISTRIB_RELEASE}" == "16.04" ]; then
  9. UBUNTU_1604=1
  10. fi
  11. . /home/worker/scripts/xvfb.sh
  12. ####
  13. # Taskcluster friendly wrapper for performing fx desktop tests via mozharness.
  14. ####
  15. # Inputs, with defaults
  16. : MOZHARNESS_PATH ${MOZHARNESS_PATH}
  17. : MOZHARNESS_URL ${MOZHARNESS_URL}
  18. : MOZHARNESS_SCRIPT ${MOZHARNESS_SCRIPT}
  19. : MOZHARNESS_CONFIG ${MOZHARNESS_CONFIG}
  20. : NEED_XVFB ${NEED_XVFB:=true}
  21. : NEED_WINDOW_MANAGER ${NEED_WINDOW_MANAGER:=false}
  22. : NEED_PULSEAUDIO ${NEED_PULSEAUDIO:=false}
  23. : START_VNC ${START_VNC:=false}
  24. : TASKCLUSTER_INTERACTIVE ${TASKCLUSTER_INTERACTIVE:=false}
  25. : WORKSPACE ${WORKSPACE:=/home/worker/workspace}
  26. : mozharness args "${@}"
  27. set -v
  28. cd $WORKSPACE
  29. fail() {
  30. echo # make sure error message is on a new line
  31. echo "[test-linux.sh:error]" "${@}"
  32. exit 1
  33. }
  34. maybe_start_pulse() {
  35. if $NEED_PULSEAUDIO; then
  36. pulseaudio --fail --daemonize --start
  37. pactl load-module module-null-sink
  38. fi
  39. }
  40. # test required parameters are supplied
  41. if [ -z "${MOZHARNESS_PATH}" -a -z "${MOZHARNESS_URL}" ]; then
  42. fail "MOZHARNESS_PATH or MOZHARNESS_URL must be defined";
  43. fi
  44. if [[ -z ${MOZHARNESS_SCRIPT} ]]; then fail "MOZHARNESS_SCRIPT is not set"; fi
  45. if [[ -z ${MOZHARNESS_CONFIG} ]]; then fail "MOZHARNESS_CONFIG is not set"; fi
  46. mkdir -p ~/artifacts/public
  47. cleanup() {
  48. local rv=$?
  49. if [[ -s /home/worker/.xsession-errors ]]; then
  50. # To share X issues
  51. cp /home/worker/.xsession-errors ~/artifacts/public/xsession-errors.log
  52. fi
  53. cleanup_xvfb
  54. exit $rv
  55. }
  56. trap cleanup EXIT INT
  57. # Download mozharness with exponential backoff
  58. # curl already applies exponential backoff, but not for all
  59. # failed cases, apparently, as we keep getting failed downloads
  60. # with 404 code.
  61. download_mozharness() {
  62. local max_attempts=10
  63. local timeout=1
  64. local attempt=0
  65. echo "Downloading mozharness"
  66. while [[ $attempt < $max_attempts ]]; do
  67. if curl --fail -o mozharness.zip --retry 10 -L $MOZHARNESS_URL; then
  68. rm -rf mozharness
  69. if unzip -q mozharness.zip; then
  70. return 0
  71. fi
  72. echo "error unzipping mozharness.zip" >&2
  73. else
  74. echo "failed to download mozharness zip" >&2
  75. fi
  76. echo "Download failed, retrying in $timeout seconds..." >&2
  77. sleep $timeout
  78. timeout=$((timeout*2))
  79. attempt=$((attempt+1))
  80. done
  81. fail "Failed to download and unzip mozharness"
  82. }
  83. # Download mozharness if we're told to.
  84. if [ ${MOZHARNESS_URL} ]; then
  85. download_mozharness
  86. rm mozharness.zip
  87. if ! [ -d mozharness ]; then
  88. fail "mozharness zip did not contain mozharness/"
  89. fi
  90. MOZHARNESS_PATH=`pwd`/mozharness
  91. fi
  92. # pulseaudio daemon must be started before xvfb on Ubuntu 12.04.
  93. if [ "${UBUNTU_1204}" ]; then
  94. maybe_start_pulse
  95. fi
  96. # run XVfb in the background, if necessary
  97. if $NEED_XVFB; then
  98. start_xvfb '1600x1200x24' 0
  99. fi
  100. if $START_VNC; then
  101. x11vnc > ~/artifacts/public/x11vnc.log 2>&1 &
  102. fi
  103. if $NEED_WINDOW_MANAGER; then
  104. # This is read by xsession to select the window manager
  105. echo DESKTOP_SESSION=ubuntu > /home/worker/.xsessionrc
  106. # note that doing anything with this display before running Xsession will cause sadness (like,
  107. # crashes in compiz). Make sure that X has enough time to start
  108. sleep 15
  109. # DISPLAY has already been set above
  110. # XXX: it would be ideal to add a semaphore logic to make sure that the
  111. # window manager is ready
  112. /etc/X11/Xsession 2>&1 &
  113. # Turn off the screen saver and screen locking
  114. gsettings set org.gnome.desktop.screensaver idle-activation-enabled false
  115. gsettings set org.gnome.desktop.screensaver lock-enabled false
  116. gsettings set org.gnome.desktop.screensaver lock-delay 3600
  117. # Disable the screen saver
  118. xset s off s reset
  119. if [ "${UBUNTU_1604}" ]; then
  120. # start compiz for our window manager
  121. compiz 2>&1 &
  122. #TODO: how to determine if compiz starts correctly?
  123. fi
  124. fi
  125. if [ "${UBUNTU_1604}" ]; then
  126. maybe_start_pulse
  127. fi
  128. # For telemetry purposes, the build process wants information about the
  129. # source it is running; tc-vcs obscures this a little, but we can provide
  130. # it directly.
  131. export MOZ_SOURCE_REPO="${GECKO_HEAD_REPOSITORY}"
  132. export MOZ_SOURCE_CHANGESET="${GECKO_HEAD_REV}"
  133. # support multiple, space delimited, config files
  134. config_cmds=""
  135. for cfg in $MOZHARNESS_CONFIG; do
  136. config_cmds="${config_cmds} --config-file ${MOZHARNESS_PATH}/configs/${cfg}"
  137. done
  138. mozharness_bin="/home/worker/bin/run-mozharness"
  139. # Save the computed mozharness command to a binary which is useful
  140. # for interactive mode.
  141. echo -e "#!/usr/bin/env bash
  142. # Some mozharness scripts assume base_work_dir is in
  143. # the current working directory, see bug 1279237
  144. cd $WORKSPACE
  145. cmd=\"python2.7 ${MOZHARNESS_PATH}/scripts/${MOZHARNESS_SCRIPT} ${config_cmds} ${@} \${@}\"
  146. echo \"Running: \${cmd}\"
  147. exec \${cmd}" > ${mozharness_bin}
  148. chmod +x ${mozharness_bin}
  149. # In interactive mode, the user will be prompted with options for what to do.
  150. if ! $TASKCLUSTER_INTERACTIVE; then
  151. # run the given mozharness script and configs, but pass the rest of the
  152. # arguments in from our own invocation
  153. ${mozharness_bin};
  154. fi