[Qa-jenkins-scm] [jenkins.debian.net] 01/07: torbrowser tests: add lots of comments to the code
Holger Levsen
holger at moszumanska.debian.org
Thu Nov 19 10:25:57 UTC 2015
This is an automated email from the git hooks/post-receive script.
holger pushed a commit to branch master
in repository jenkins.debian.net.
commit 7927a25449d82f85ce790c68da8940a1c0ace7b5
Author: Holger Levsen <holger at layer-acht.org>
Date: Thu Nov 19 00:54:18 2015 +0100
torbrowser tests: add lots of comments to the code
---
TODO | 5 +++++
bin/test_torbrowser-launcher.sh | 45 +++++++++++++++++++++++++++++++----------
2 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/TODO b/TODO
index 3f12964..fe8b7da 100644
--- a/TODO
+++ b/TODO
@@ -417,6 +417,11 @@ The following ideas should really only be implemented for the new 'lvc*' tests..
* notifications should go somewhere public, after a while of testing.
* debug why iceweasel is needed to be installed… and ca-certificates too.
* run this in qemu and enable apparmor too?
+** extend setup_schroot.sh to also setup virtual harddrives
+** install linux, grub and copy the testscript and ssh keys on the the fs
+** configure apparmor
+** boot qemu
+** ssh into the vm and run the script as usal
* probably not: test with python-pygame installed.
== Further ideas...
diff --git a/bin/test_torbrowser-launcher.sh b/bin/test_torbrowser-launcher.sh
index 495b0fb..4c4584b 100755
--- a/bin/test_torbrowser-launcher.sh
+++ b/bin/test_torbrowser-launcher.sh
@@ -9,8 +9,12 @@ common_init "$@"
set -e
+# dependencies used in the schroot are described in job-cfg/torbrowser-launcher.yaml, see how schroot-create.sh is called there.
+# additionally this script needs the following packages: xvfb, xvkbd, ffmpeg, gocr, imagemagick
+
cleanup_all() {
set +e
+ # $1 is empty when called via trap
if [ "$1" = "quiet" ] ; then
echo "$(date -u) - everything ran nicely, congrats."
fi
@@ -40,9 +44,11 @@ cleanup_all() {
}
cleanup_duplicate_screenshots() {
+ cd $RESULTS
echo "$(date -u) - removing duplicate screenshots."
+ # loop backwards through the screenshots and remove similar ones
+ # this results in keeping the interesting ones :)
MAXDIFF=2500 # pixels
- cd $RESULTS
for i in $(ls -r1 *.png | xargs echo) ; do
for j in $(ls -r1 *.png | xargs echo) ; do
if [ "$j" = "$i" ] ; then
@@ -50,7 +56,9 @@ cleanup_duplicate_screenshots() {
elif [ ! -f $j ] || [ ! -f $i ] ; then
break
fi
+ # here we check the difference in pixels between the two images
PIXELS=$(compare -metric AE $i $j /dev/null 2>&1 || true)
+ # if it's an integer…
if [[ "$PIXELS" =~ ^[0-9]+$ ]] && [ $PIXELS -le $MAXDIFF ] ; then
echo "$(date -u ) - removing $j, just $PIXELS pixels difference."
rm $j
@@ -63,16 +71,18 @@ cleanup_duplicate_screenshots() {
update_screenshot() {
TIMESTAMP=$(date +%Y%m%d%H%M%S)
+ # probably there is something more lightweight to grab a screenshot from xvfb…
ffmpeg -y -f x11grab -s $SIZE -i :$SCREEN.0 -frames 1 screenshot.png > /dev/null 2>&1
convert screenshot.png -adaptive-resize 128x96 screenshot-thumb.png
- # for publishing
+ # for later publishing
cp screenshot.png $RESULTS/screenshot_$TIMESTAMP.png
- echo "screenshot_$TIMESTAMP.png preserved."
# for the live screenshot plugin
mv screenshot.png screenshot-thumb.png $WORKSPACE/
+ echo "screenshot_$TIMESTAMP.png taken."
}
begin_session() {
+ # create schroot session
schroot --begin-session --session-name=$SESSION -c jenkins-torbrowser-launcher-$SUITE
echo "Starting schroot session, schroot --run-session -c $SESSION -- now availble."
schroot --run-session -c $SESSION --directory /tmp -u root -- mkdir $HOME
@@ -80,6 +90,7 @@ begin_session() {
}
end_session() {
+ # destroy schroot session
schroot --end-session -c $SESSION
echo "$(date -u ) - schroot session $SESSION end."
sleep 1
@@ -94,8 +105,9 @@ upgrade_to_newer_packaged_version_in() {
schroot --run-session -c $SESSION --directory /tmp -u root -- apt-get -y install -t $SUITE torbrowser-launcher
}
-build_and_upgrade_to_git_version() {
+upgrade_to_package_build_from_git() {
echo
+ local BRANCH=$1
echo "$(date -u ) - building Debian package based on branch $BRANCH from $GIT_URL."
schroot --run-session -c $SESSION --directory $TMPDIR/git -- debuild -b -uc -us
DEB=$(cd $TMPDIR ; ls torbrowser-launcher_*deb)
@@ -111,12 +123,15 @@ download_and_launch() {
echo
echo "$(date -u) - Test download_and_launch begins."
echo "$(date -u ) - starting dbus service."
+ # yes, torbrowser needs dbus
schroot --run-session -c $SESSION --directory /tmp -u root -- service dbus start
sleep 2
echo "$(date -u) - starting Xfvb on :$SCREEN.0 now."
+ # start X on virtual framebuffer device
Xvfb -ac -br -screen 0 ${SIZE}x24 :$SCREEN &
XPID=$!
sleep 1
+ # configure environment
export DISPLAY=":$SCREEN.0"
echo export DISPLAY=":$SCREEN.0"
unset http_proxy
@@ -127,17 +142,20 @@ download_and_launch() {
echo "$(date -u) - starting awesome."
timeout -k 30m 29m schroot --run-session -c $SESSION --preserve-environment -- awesome &
sleep 2
+ # configure dbus session for this user's session
DBUS_SESSION_FILE=$(mktemp -t torbrowser-launcher-XXXXXX)
DBUS_SESSION_POINTER=$(schroot --run-session -c $SESSION --preserve-environment -- ls $HOME/.dbus/session-bus/ -t1 | head -1)
schroot --run-session -c $SESSION --preserve-environment -- cat $HOME/.dbus/session-bus/$DBUS_SESSION_POINTER > $DBUS_SESSION_FILE
. $DBUS_SESSION_FILE && export DBUS_SESSION_BUS_ADDRESS
echo export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
rm $DBUS_SESSION_FILE
+ # start ffmpeg to capture a video of the interesting bits of the test
ffmpeg -f x11grab -s $SIZE -i :$SCREEN.0 $VIDEO > /dev/null 2>&1 &
FFMPEGPID=$!
echo "'$(date -u) - starting torbrowser tests'" | tee | xargs schroot --run-session -c $SESSION --preserve-environment -- notify-send
update_screenshot
- echo "$(date -u) - starting torbrowser-launcher the first time, opening settings dialog."
+ echo "$(date -u) - starting torbrowser-launcher, opening settings dialog."
+ # set PYTHONUNBUFFERED to get unbuffered output from python, so we can grep in it in real time
export PYTHONUNBUFFERED=true
( timeout -k 30m 29m schroot --run-session -c $SESSION --preserve-environment -- /usr/bin/torbrowser-launcher --settings 2>&1 |& tee $TBL_LOGFILE || true ) &
sleep 10
@@ -197,7 +215,8 @@ download_and_launch() {
for i in $(seq 1 6) ; do
sleep 10
# this directory only exists once torbrower has successfully started
- STATUS="$(schroot --run-session -c $SESSION -- test ! -d $HOME/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default || echo $(date -u ) - torbrowser running. )"
+ # (and pattern matching doesnt work because of schroot…)
+ STATUS="$(schroot --run-session -c $SESSION -- test ! -d $HOME/.local/share/torbrowser/tbb/x86_64/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default -a ! -d $HOME/.local/share/torbrowser/tbb/x86_64/tor-browser_de/Browser/TorBrowser/Data/Browser/profile.default || echo $(date -u ) - torbrowser running. )"
if [ -n "$STATUS" ] ; then
sleep 10
update_screenshot
@@ -232,8 +251,7 @@ download_and_launch() {
exit 0
fi
BONUS_LEVEL_1=""
- URL="http://vwakviie2ienjx6t.onion/debian/"
- # see http://richardhartmann.de/blog/posts/2015/08/24-Tor-enabled_Debian_mirror/
+ URL="http://vwakviie2ienjx6t.onion/debian/" # see http://richardhartmann.de/blog/posts/2015/08/24-Tor-enabled_Debian_mirror/
echo "$(date -u) - pressing <ctrl>-l - about to enter $URL as URL."
xvkbd -text "\Cl" > /dev/null 2>&1
sleep 3
@@ -308,7 +326,7 @@ if [ -z "$1" ] ; then
fi
SUITE=$1
UPGRADE_SUITE=""
-TMPDIR=$(mktemp -d -t torbrowser-launcher-XXXXXX) # where everything actually happens
+TMPDIR=$(mktemp -d -t torbrowser-launcher-XXXXXX)
TBL_LOGFILE=$(mktemp -t torbrowser-launcher-XXXXXX)
SESSION="tbb-launcher-$SUITE-$(basename $TMPDIR)"
STARTTIME=$(date +%Y%m%d%H%M)
@@ -317,6 +335,7 @@ SIZE=1024x768
SCREEN=$EXECUTOR_NUMBER
if [ "$2" = "git" ] ; then
if [ "$3" = "merge" ] ; then
+ # merge debian branch into upstream master branch
BRANCH=upstream-master-plus-debian-packaging
DEBIAN_GIT_URL="git://git.debian.org/git/collab-maint/torbrowser-launcher.git"
DEBIAN_BRANCH="debian/$4"
@@ -335,11 +354,12 @@ if [ "$2" = "git" ] ; then
dch -R $COMMIT_MSG1
dch -v $BUILD_VERSION $COMMIT_MSG2
prepare_git_workspace_copy
- # revert to original branch
+ # revert to original workspace status
git reset --hard
git checkout -f -q $COMMIT_HASH
git branch -D $BRANCH
else
+ # just use this branch
BRANCH=$3
prepare_git_workspace_copy
fi
@@ -357,6 +377,7 @@ rm -f $RESULTS/*.png $RESULTS/*.mpg
[ ! -f screenshot.png ] || mv screenshot.png screenshot_from_git.png
mkdir -p $RESULTS
cd $TMPDIR
+# use trap to always clean up
trap cleanup_all INT TERM EXIT
#
@@ -364,8 +385,10 @@ trap cleanup_all INT TERM EXIT
#
echo "$(date -u) - testing torbrowser-launcher on $SUITE now."
begin_session
+# the default is to test the packaged version from $SUITE
+# and there are two variations:
if [ "$2" = "git" ] ; then
- build_and_upgrade_to_git_version
+ upgrade_to_package_build_from_git $BRANCH
elif [ -n "$UPGRADE_SUITE" ] ; then
upgrade_to_newer_packaged_version_in $UPGRADE_SUITE
fi
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/qa/jenkins.debian.net.git
More information about the Qa-jenkins-scm
mailing list