# HG changeset patch # User Julien Cristau # Date 1330020336 -3600 # Node ID d4d9c88d4a5f9e03b19762b407ab04112ff90115 # Parent d54fc706d623f1b0458893096f481cd4909d480d [devtools] make a copy of the xvfb-run script so we can kill it properly Since changeset a3d3bdd46463 we don't run firefox directly but through a wrapper script. This meant that on stopping the test, we would kill that wrapper script but leave the Xvfb server and firefox processes running. So make a local copy of xvfb-run, and make it kill Xvfb when it goes down, not just when its client exits. diff -r d54fc706d623 -r d4d9c88d4a5f MANIFEST.in --- a/MANIFEST.in Thu Feb 23 11:57:35 2012 +0100 +++ b/MANIFEST.in Thu Feb 23 19:05:36 2012 +0100 @@ -12,7 +12,7 @@ include web/views/*.pt recursive-include web/data external_resources *.js *.css *.py *.png *.gif *.ico *.ttf recursive-include web/wdoc *.rst *.png *.xml ChangeLog* -recursive-include devtools/data *.js *.css +recursive-include devtools/data *.js *.css *.sh recursive-include i18n *.pot *.po recursive-include schemas *.py *.sql diff -r d54fc706d623 -r d4d9c88d4a5f devtools/data/xvfb-run.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/devtools/data/xvfb-run.sh Thu Feb 23 19:05:36 2012 +0100 @@ -0,0 +1,191 @@ +#!/bin/sh + +# $Id: xvfb-run 2027 2004-11-16 14:54:16Z branden $ + +# This script starts an instance of Xvfb, the "fake" X server, runs a command +# with that server available, and kills the X server when done. The return +# value of the command becomes the return value of this script. +# +# If anyone is using this to build a Debian package, make sure the package +# Build-Depends on xvfb, xbase-clients, and xfonts-base. + +set -e + +PROGNAME=xvfb-run +SERVERNUM=99 +AUTHFILE= +ERRORFILE=/dev/null +STARTWAIT=3 +XVFBARGS="-screen 0 640x480x8" +LISTENTCP="-nolisten tcp" +XAUTHPROTO=. + +# Query the terminal to establish a default number of columns to use for +# displaying messages to the user. This is used only as a fallback in the event +# the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the +# script is running, and this cannot, only being calculated once.) +DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true +if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then + DEFCOLUMNS=80 +fi + +# Display a message, wrapping lines at the terminal width. +message () { + echo "$PROGNAME: $*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} +} + +# Display an error message. +error () { + message "error: $*" >&2 +} + +# Display a usage message. +usage () { + if [ -n "$*" ]; then + message "usage error: $*" + fi + cat <>"$ERRORFILE" 2>&1 + fi + if [ -n "$XVFB_RUN_TMPDIR" ]; then + if ! rm -r "$XVFB_RUN_TMPDIR"; then + error "problem while cleaning up temporary directory" + exit 5 + fi + fi + if [ -n "$XVFBPID" ]; then + kill $XVFBPID + fi +} + +# Parse the command line. +ARGS=$(getopt --options +ae:f:hn:lp:s:w: \ + --long auto-servernum,error-file:,auth-file:,help,server-num:,listen-tcp,xauth-protocol:,server-args:,wait: \ + --name "$PROGNAME" -- "$@") +GETOPT_STATUS=$? + +if [ $GETOPT_STATUS -ne 0 ]; then + error "internal error; getopt exited with status $GETOPT_STATUS" + exit 6 +fi + +eval set -- "$ARGS" + +while :; do + case "$1" in + -a|--auto-servernum) SERVERNUM=$(find_free_servernum); AUTONUM="yes" ;; + -e|--error-file) ERRORFILE="$2"; shift ;; + -f|--auth-file) AUTHFILE="$2"; shift ;; + -h|--help) SHOWHELP="yes" ;; + -n|--server-num) SERVERNUM="$2"; shift ;; + -l|--listen-tcp) LISTENTCP="" ;; + -p|--xauth-protocol) XAUTHPROTO="$2"; shift ;; + -s|--server-args) XVFBARGS="$2"; shift ;; + -w|--wait) STARTWAIT="$2"; shift ;; + --) shift; break ;; + *) error "internal error; getopt permitted \"$1\" unexpectedly" + exit 6 + ;; + esac + shift +done + +if [ "$SHOWHELP" ]; then + usage + exit 0 +fi + +if [ -z "$*" ]; then + usage "need a command to run" >&2 + exit 2 +fi + +if ! which xauth >/dev/null; then + error "xauth command not found" + exit 3 +fi + +# tidy up after ourselves +trap clean_up EXIT + +# If the user did not specify an X authorization file to use, set up a temporary +# directory to house one. +if [ -z "$AUTHFILE" ]; then + XVFB_RUN_TMPDIR="$(mktemp -d -t $PROGNAME.XXXXXX)" + # Create empty file to avoid xauth warning + AUTHFILE=$(tempfile -n "$XVFB_RUN_TMPDIR/Xauthority") +fi + +# Start Xvfb. +MCOOKIE=$(mcookie) +tries=10 +while [ $tries -gt 0 ]; do + tries=$(( $tries - 1 )) + XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1 +add :$SERVERNUM $XAUTHPROTO $MCOOKIE +EOF + XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" 2>&1 & + XVFBPID=$! + + sleep "$STARTWAIT" + if kill -0 $XVFBPID 2>/dev/null; then + break + elif [ -n "$AUTONUM" ]; then + # The display is in use so try another one (if '-a' was specified). + SERVERNUM=$((SERVERNUM + 1)) + SERVERNUM=$(find_free_servernum) + continue + fi + error "Xvfb failed to start" >&2 + exit 1 +done + +# Start the command and save its exit status. +set +e +DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1 +RETVAL=$? +set -e + +# Return the executed command's exit status. +exit $RETVAL + +# vim:set ai et sts=4 sw=4 tw=80: diff -r d54fc706d623 -r d4d9c88d4a5f devtools/qunit.py --- a/devtools/qunit.py Thu Feb 23 11:57:35 2012 +0100 +++ b/devtools/qunit.py Thu Feb 23 19:05:36 2012 +0100 @@ -72,7 +72,7 @@ stderr = TemporaryFile() self.firefox_cmd = ['firefox', '-no-remote'] if os.name == 'posix': - self.firefox_cmd = ['xvfb-run', '-a'] + self.firefox_cmd + self.firefox_cmd = [osp.join(osp.dirname(__file__), 'data', 'xvfb-run.sh'), '-a'] + self.firefox_cmd try: home = osp.expanduser('~') user = getlogin()