Merge lp:~jibel/autopilot/autopilot-sandbox-run into lp:autopilot

Proposed by Jean-Baptiste Lallement
Status: Superseded
Proposed branch: lp:~jibel/autopilot/autopilot-sandbox-run
Merge into: lp:autopilot
Diff against target: 202 lines (+180/-1)
3 files modified
bin/autopilot-sandbox-run (+178/-0)
debian/python-autopilot.install (+1/-0)
setup.py (+1/-1)
To merge this branch: bzr merge lp:~jibel/autopilot/autopilot-sandbox-run
Reviewer Review Type Date Requested Status
Jean-Baptiste Lallement Approve
Martin Pitt (community) Approve
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+185527@code.launchpad.net

This proposal supersedes a proposal from 2013-09-13.

This proposal has been superseded by a proposal from 2013-09-16.

Commit message

Added autopilot-sandbox-run to run autopilot tests in a 'fake' X server.
Xephyr and Xvfb are supported.

Description of the change

Added autopilot-sandbox-run to run autopilot tests in a 'fake' X server.
Xephyr and Xvfb are supported.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Martin Pitt (pitti) wrote : Posted in a previous version of this proposal

JB, you need to add the new script to scripts=[...] in setup.py.

> 4 +XEPHYR_CMD="$(which Xephyr)"

This will fail if Xephyr isn't installed, as the script is set -e. You should ignore that error without -x (similarly with "which Xvfb"), as further down the script already gives a proper error message if it's not installed.

> SERVERNUM=$(shuf -n1 -i5-99)

This should loop until ! [ -e /tmp/.X${SERVERNUM}-lock ]

> sleep 1 # Waits from fake X to settle

I think this can be done more robustly with a loop which sleeps 0.1 until [ -e /tmp/.X${SERVERNUM}-lock ]

Merci beaucoup !

review: Needs Fixing
Revision history for this message
Martin Pitt (pitti) wrote : Posted in a previous version of this proposal

Also, I don't immediately see anything which requires bash in the script, did I miss anything? It could be /bin/sh.

It's generally better to do

#!/bin/sh
set -eu

instead of "#!/bin/sh -eu"; with the latter, the -eu will be silently not happen if you run the script with e. g. "sh -x bin/autopilot-sandbox'run", but with the former the set -eu will always be considered.

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote : Posted in a previous version of this proposal

Thanks for your review.

I updated the MP with your comments and added 2 functions:
* find_free_servernum to find first free server number instead of picking a random server number
* wait_for_x to wait for the start of X server and timeout after 10S instead of a static sleep

review: Needs Resubmitting
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:326
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~jibel/autopilot/autopilot-sandbox-run/+merge/185506/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/autopilot-ci/218/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-saucy-amd64-ci/146
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-saucy-armhf-ci/146

Click here to trigger a rebuild:
http://s-jenkins:8080/job/autopilot-ci/218/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

LGTM, would like pitti to review this before merging it.

review: Approve
Revision history for this message
Martin Pitt (pitti) wrote :

LGTM now, thanks for the fixes!

review: Approve
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

approving my own MP :)

review: Approve

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/autopilot-sandbox-run'
2--- bin/autopilot-sandbox-run 1970-01-01 00:00:00 +0000
3+++ bin/autopilot-sandbox-run 2013-09-13 15:24:06 +0000
4@@ -0,0 +1,178 @@
5+#!/bin/sh
6+
7+#
8+# Runner to execute autopilot locally
9+#
10+# This scripts run autopilot in a "fake" X server, either headless with xvfb
11+# or nested with Xephyr
12+#
13+
14+# Copyright (C) 2013 Canonical
15+#
16+# Authors: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
17+#
18+# This program is free software; you can redistribute it and/or modify it # under
19+# the terms of the GNU General Public License as published by the Free # Software
20+# Foundation; version 3.
21+#
22+# This program is distributed in the hope that it will be useful, but WITHOUT
23+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS
24+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details.
25+#
26+# You should have received a copy of the GNU General Public License along with
27+# this program; if not, write to the Free Software Foundation, Inc.,
28+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29+set -eu
30+
31+# General Settings
32+RC=0 # Main return code
33+BINDIR=$(dirname $(readlink -f $0))
34+XEPHYR=0
35+XEPHYR_CMD="$(which Xephyr||true)"
36+XEPHYR_OPT="-ac -br -noreset"
37+
38+XVFB_CMD="$(which Xvfb||true)"
39+XVFB_OPT=""
40+
41+AP_CMD="$(which autopilot)"
42+AP_OPT=""
43+
44+SERVERNUM=5
45+SCREEN="1024x768x24"
46+
47+DBUS_SESSION_BUS_PID=""
48+X_PID=""
49+
50+usage() {
51+ # Display usage and exit with error
52+ cat<<EOF
53+Usage: $(basename $0) [OPTIONS...] TEST [TEST...]
54+Runs autopilot tests in a 'fake' Xserver with Xvfb or Xephyr. autopilot runs
55+in Xvfb by default.
56+
57+ TEST: autopilot tests to run
58+
59+Options:
60+ -h, --help This help
61+ -d, --debug Enable debug mode
62+ -a, --autopilot ARG Pass arguments ARG to 'autopilot run'
63+ -X, --xephyr Run in nested mode with Xephyr
64+ -s, --screen WxHxD Sets screen width, height, and depth to W, H, and D
65+ respectively (default: $SCREEN)
66+
67+EOF
68+ RC=1
69+ exit
70+}
71+
72+find_free_servernum() {
73+ # Find a free server number by looking at .X*-lock files in /tmp.
74+ # Inspired from xvfb-run
75+ #
76+ # Args:
77+ # None
78+ # Returns:
79+ # First free server number
80+ #
81+ snum=$SERVERNUM
82+ while [ -f /tmp/.X$snum-lock ]; do
83+ snum=$(($snum + 1))
84+ done
85+ echo $snum
86+}
87+
88+wait_for_x() {
89+ # Waits for start of fake X server and exit on timeout
90+ #
91+ # Args:
92+ # $1: Server number
93+ # Returns
94+ # None
95+ if [ $# -ne 1 ]; then
96+ echo "E: wait_for_x: Missing argument servernum"
97+ RC=1
98+ exit
99+ fi
100+ loops=100
101+ delay=.1
102+ snum=$1
103+ while [ ! -e /tmp/.X$snum-lock ]; do
104+ sleep $delay
105+ loops=$((loops - 1))
106+ if [ $loops -le 0 ]; then
107+ echo "E: X Server :$snum failed to come up. Aborting!"
108+ RC=1
109+ exit
110+ fi
111+ done
112+}
113+
114+on_exit() {
115+ # Exit handler
116+ for pid in "$DBUS_SESSION_BUS_PID" "$X_PID"; do
117+ [ -n "$pid" ] && kill $pid >/dev/null 2>&1 || true
118+ done
119+
120+ exit $RC
121+}
122+
123+trap on_exit EXIT INT QUIT ABRT PIPE TERM
124+
125+SHORTOPTS="hda:s:X"
126+LONGOPTS="help,debug,autopilot:,screen:,xephyr"
127+
128+TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@")
129+eval set -- "$TEMP"
130+
131+exec 2>&1
132+
133+while true ; do
134+ case "$1" in
135+ -h|--help)
136+ usage;;
137+ -d|--debug)
138+ set -x
139+ shift;;
140+ -a|--autopilot)
141+ AP_OPT=$2
142+ shift 2;;
143+ -s|-screen)
144+ SCREEN=$2
145+ shift 2;;
146+ -X|--xephyr)
147+ XEPHYR=1
148+ [ ! -x "$XEPHYR_CMD" ] && \
149+ echo "E: Xephyr executable not found. Please install Xephyr" &&\
150+ RC=1 && exit 1
151+ shift;;
152+ --) shift;
153+ break;;
154+ *) usage;;
155+ esac
156+done
157+
158+[ $# -eq 0 ] && usage
159+if [ $XEPHYR -eq 0 -a ! -x "$XVFB_CMD" ]; then
160+ echo "E: Xvfb executable not found. Please install xvfb"
161+ RC=1
162+ exit
163+fi
164+
165+TESTLIST="$@"
166+echo "I: Running tests $TESTLIST"
167+
168+SERVERNUM=$(find_free_servernum)
169+XCMD="$XVFB_CMD :$SERVERNUM $XVFB_OPT -screen 0 $SCREEN"
170+[ $XEPHYR -eq 1 ] && XCMD="$XEPHYR_CMD :$SERVERNUM $XEPHYR_OPT -screen $SCREEN"
171+
172+echo "I: Starting X Server: $XCMD"
173+$XCMD >/dev/null 2>&1 &
174+X_PID=$!
175+export DISPLAY=:${SERVERNUM}.0
176+
177+export XAUTHORITY=/dev/null
178+wait_for_x $SERVERNUM
179+echo "I: Starting autopilot"
180+dbus-launch --exit-with-session autopilot run $AP_OPT $TESTLIST
181+echo "I: autopilot tests done"
182+RC=$?
183
184=== modified file 'debian/python-autopilot.install'
185--- debian/python-autopilot.install 2013-05-04 01:01:06 +0000
186+++ debian/python-autopilot.install 2013-09-13 15:24:06 +0000
187@@ -1,2 +1,3 @@
188 usr/bin/autopilot /usr/bin/
189+usr/bin/autopilot-sandbox-run /usr/bin/
190 debian/61-autopilot-uinput.rules /lib/udev/rules.d
191
192=== modified file 'setup.py'
193--- setup.py 2013-07-24 05:56:06 +0000
194+++ setup.py 2013-09-13 15:24:06 +0000
195@@ -47,6 +47,6 @@
196 license='GPLv3',
197 packages=find_packages(),
198 test_suite='autopilot.tests',
199- scripts=['bin/autopilot'],
200+ scripts=['bin/autopilot', 'bin/autopilot-sandbox-run'],
201 ext_modules=[autopilot_tracepoint],
202 )

Subscribers

People subscribed via source and target branches