test-b2g.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #! /bin/bash -xe
  2. set -x -e
  3. echo "running as" $(id)
  4. ####
  5. # Taskcluster friendly wrapper for performing fx desktop tests via mozharness.
  6. ####
  7. # Inputs, with defaults
  8. : MOZHARNESS_URL ${MOZHARNESS_URL}
  9. : MOZHARNESS_SCRIPT ${MOZHARNESS_SCRIPT}
  10. : MOZHARNESS_CONFIG ${MOZHARNESS_CONFIG}
  11. : NEED_XVFB ${NEED_XVFB:=true}
  12. : NEED_PULSEAUDIO ${NEED_PULSEAUDIO:=false}
  13. : NEED_PULL_GAIA ${NEED_PULL_GAIA:=false}
  14. : SKIP_MOZHARNESS_RUN ${SKIP_MOZHARNESS_RUN:=false}
  15. : WORKSPACE ${WORKSPACE:=/home/worker/workspace}
  16. : mozharness args "${@}"
  17. set -v
  18. cd $WORKSPACE
  19. # test required parameters are supplied
  20. if [[ -z ${MOZHARNESS_URL} ]]; then exit 1; fi
  21. if [[ -z ${MOZHARNESS_SCRIPT} ]]; then exit 1; fi
  22. if [[ -z ${MOZHARNESS_CONFIG} ]]; then exit 1; fi
  23. mkdir -p ~/artifacts/public
  24. cleanup() {
  25. if [ -n "$xvfb_pid" ]; then
  26. kill $xvfb_pid || true
  27. fi
  28. }
  29. trap cleanup EXIT INT
  30. # Unzip the mozharness ZIP file created by the build task
  31. curl --fail -o mozharness.zip --retry 10 -L $MOZHARNESS_URL
  32. rm -rf mozharness
  33. unzip -q mozharness.zip
  34. rm mozharness.zip
  35. if ! [ -d mozharness ]; then
  36. echo "mozharness zip did not contain mozharness/"
  37. exit 1
  38. fi
  39. # start up the pulseaudio daemon. Note that it's important this occur
  40. # before the Xvfb startup.
  41. if $NEED_PULSEAUDIO; then
  42. pulseaudio --fail --daemonize --start
  43. pactl load-module module-null-sink
  44. fi
  45. # run XVfb in the background, if necessary
  46. if $NEED_XVFB; then
  47. Xvfb :0 -nolisten tcp -screen 0 1600x1200x24 \
  48. > ~/artifacts/public/xvfb.log 2>&1 &
  49. export DISPLAY=:0
  50. xvfb_pid=$!
  51. # Only error code 255 matters, because it signifies that no
  52. # display could be opened. As long as we can open the display
  53. # tests should work. We'll retry a few times with a sleep before
  54. # failing.
  55. retry_count=0
  56. max_retries=2
  57. xvfb_test=0
  58. until [ $retry_count -gt $max_retries ]; do
  59. xvinfo || xvfb_test=$?
  60. if [ $xvfb_test != 255 ]; then
  61. retry_count=$(($max_retries + 1))
  62. else
  63. retry_count=$(($retry_count + 1))
  64. echo "Failed to start Xvfb, retry: $retry_count"
  65. sleep 2
  66. fi done
  67. if [ $xvfb_test == 255 ]; then exit 255; fi
  68. fi
  69. gaia_cmds=""
  70. if $NEED_PULL_GAIA; then
  71. # test required parameters are supplied
  72. if [[ -z ${GAIA_BASE_REPOSITORY} ]]; then exit 1; fi
  73. if [[ -z ${GAIA_HEAD_REPOSITORY} ]]; then exit 1; fi
  74. if [[ -z ${GAIA_REV} ]]; then exit 1; fi
  75. if [[ -z ${GAIA_REF} ]]; then exit 1; fi
  76. tc-vcs checkout \
  77. ${WORKSPACE}/gaia \
  78. ${GAIA_BASE_REPOSITORY} \
  79. ${GAIA_HEAD_REPOSITORY} \
  80. ${GAIA_REV} \
  81. ${GAIA_REF}
  82. gaia_cmds="--gaia-dir=${WORKSPACE}"
  83. fi
  84. # support multiple, space delimited, config files
  85. config_cmds=""
  86. for cfg in $MOZHARNESS_CONFIG; do
  87. config_cmds="${config_cmds} --config-file ${cfg}"
  88. done
  89. if [ ${SKIP_MOZHARNESS_RUN} == true ]; then
  90. # Skipping Mozharness is to allow the developer start the window manager
  91. # properly and letting them change the execution of Mozharness without
  92. # exiting the container
  93. echo "We skipped running Mozharness."
  94. echo "Make sure you export DISPLAY=:0 before calling Mozharness."
  95. echo "Don't forget to call it with 'sudo -E -u worker'."
  96. else
  97. # run the given mozharness script and configs, but pass the rest of the
  98. # arguments in from our own invocation
  99. python2.7 $WORKSPACE/${MOZHARNESS_SCRIPT} ${config_cmds} ${gaia_cmds} "${@}"
  100. fi