blob: 81cc6472c56f470a881877c78d835cc713f40c7b [file] [log] [blame]
Neal Norwitz461aa5b2006-01-02 20:07:16 +00001#!/bin/sh
2
3## Script to build and test the latest python from svn. It basically
4## does this:
5## svn up ; ./configure ; make ; make test ; make install ; cd Doc ; make
6##
Georg Brandlbbd82e42010-01-03 14:18:52 +00007## Logs are kept and rsync'ed to the webhost. If there are test failure(s),
Neal Norwitz461aa5b2006-01-02 20:07:16 +00008## information about the failure(s) is mailed.
9##
Georg Brandlbbd82e42010-01-03 14:18:52 +000010## The user must be a member of the webmaster group locally and on webhost.
11##
Neal Norwitz461aa5b2006-01-02 20:07:16 +000012## This script is run on the PSF's machine as user neal via crontab.
13##
14## Yes, this script would probably be easier in python, but then
15## there's a bootstrap problem. What if Python doesn't build?
16##
17## This script should be fairly clean Bourne shell, ie not too many
18## bash-isms. We should try to keep it portable to other Unixes.
19## Even though it will probably only run on Linux. I'm sure there are
20## several GNU-isms currently (date +%s and readlink).
21##
22## Perhaps this script should be broken up into 2 (or more) components.
23## Building doc is orthogonal to the rest of the python build/test.
24##
25
26## FIXME: we should detect test hangs (eg, if they take more than 45 minutes)
27
28## FIXME: we should run valgrind
29## FIXME: we should run code coverage
30
31## Utilities invoked in this script include:
Neal Norwitzd3a58672006-01-02 23:22:41 +000032## basename, date, dirname, expr, grep, readlink, uname
Neal Norwitz461aa5b2006-01-02 20:07:16 +000033## cksum, make, mutt, rsync, svn
34
Neal Norwitz461aa5b2006-01-02 20:07:16 +000035## remember where did we started from
36DIR=`dirname $0`
37if [ "$DIR" = "" ]; then
38 DIR="."
39fi
40
41## make directory absolute
42DIR=`readlink -f $DIR`
Neal Norwitzd3a58672006-01-02 23:22:41 +000043FULLPATHNAME="$DIR/`basename $0`"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000044## we want Misc/..
45DIR=`dirname $DIR`
46
47## Configurable options
48
49FAILURE_SUBJECT="Python Regression Test Failures"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000050#FAILURE_MAILTO="YOUR_ACCOUNT@gmail.com"
Neal Norwitzf415d5f2006-02-19 18:48:19 +000051FAILURE_MAILTO="python-checkins@python.org"
Neal Norwitz5d08bd72007-04-20 05:20:38 +000052#FAILURE_CC="optional--uncomment and set to desired address"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000053
54REMOTE_SYSTEM="neal@dinsdale.python.org"
Georg Brandl4cf8ac42008-10-04 08:13:56 +000055REMOTE_DIR="/data/ftp.python.org/pub/www.python.org/doc/current"
56REMOTE_DIR_DIST="/data/ftp.python.org/pub/python/doc/current"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000057RESULT_FILE="$DIR/build/index.html"
Neal Norwitzdaeaf692008-10-03 04:10:46 +000058INSTALL_DIR="/tmp/python-test-2.6/local"
Georg Brandlbbd82e42010-01-03 14:18:52 +000059RSYNC_OPTS="-C -e ssh -rlogD"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000060
Neal Norwitz524b59b2006-06-27 04:09:13 +000061# Always run the installed version of Python.
62PYTHON=$INSTALL_DIR/bin/python
63
64# Python options and regression test program that should always be run.
Neal Norwitzf2fcfa32006-08-18 06:14:52 +000065REGRTEST_ARGS="-E -tt $INSTALL_DIR/lib/python2.6/test/regrtest.py"
Neal Norwitz524b59b2006-06-27 04:09:13 +000066
Neal Norwitz461aa5b2006-01-02 20:07:16 +000067REFLOG="build/reflog.txt.out"
Neal Norwitzee6d23e2006-04-12 05:56:00 +000068# These tests are not stable and falsely report leaks sometimes.
Neal Norwitzf415d5f2006-02-19 18:48:19 +000069# The entire leak report will be mailed if any test not in this list leaks.
Neal Norwitza1f9b7f2006-04-06 07:58:59 +000070# Note: test_XXX (none currently) really leak, but are disabled
Neal Norwitz770a8002006-03-17 04:52:38 +000071# so we don't send spam. Any test which really leaks should only
72# be listed here if there are also test cases under Lib/test/leakers.
Neal Norwitza403e412008-08-24 17:29:53 +000073LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|urllib2_localnet|xmlrpc)"
Neal Norwitzee6d23e2006-04-12 05:56:00 +000074
75# Skip these tests altogether when looking for leaks. These tests
76# do not need to be stored above in LEAKY_TESTS too.
77# test_compiler almost never finishes with the same number of refs
78# since it depends on other modules, skip it.
79# test_logging causes hangs, skip it.
Georg Brandlbbd82e42010-01-03 14:18:52 +000080# KBK 21Apr09: test_httpservers causes hangs, skip for now.
81LEAKY_SKIPS="-x test_compiler test_logging test_httpservers"
Neal Norwitzf415d5f2006-02-19 18:48:19 +000082
Neal Norwitz770a8002006-03-17 04:52:38 +000083# Change this flag to "yes" for old releases to only update/build the docs.
Neal Norwitzdaeaf692008-10-03 04:10:46 +000084BUILD_DISABLED="yes"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000085
86## utility functions
87current_time() {
88 date +%s
89}
90
91update_status() {
92 now=`current_time`
93 time=`expr $now - $3`
94 echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
95}
96
Skip Montanaro04735172008-02-15 19:03:59 +000097place_summary_first() {
98 testf=$1
99 sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
Neal Norwitz64984a82008-03-05 05:49:03 +0000100 | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
Skip Montanaro04735172008-02-15 19:03:59 +0000101 echo "" >> $testf.tmp
102 cat $testf >> $testf.tmp
103 mv $testf.tmp $testf
104}
105
106count_failures () {
107 testf=$1
108 n=`grep -ic " failed:" $testf`
109 if [ $n -eq 1 ] ; then
Neal Norwitz64984a82008-03-05 05:49:03 +0000110 n=`grep " failed:" $testf | sed -e 's/ .*//'`
Skip Montanaro04735172008-02-15 19:03:59 +0000111 fi
112 echo $n
113}
114
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000115mail_on_failure() {
116 if [ "$NUM_FAILURES" != "0" ]; then
Neal Norwitz5d08bd72007-04-20 05:20:38 +0000117 dest=$FAILURE_MAILTO
118 # FAILURE_CC is optional.
119 if [ "$FAILURE_CC" != "" ]; then
120 dest="$dest -c $FAILURE_CC"
121 fi
Neal Norwitz64984a82008-03-05 05:49:03 +0000122 if [ "x$3" != "x" ] ; then
123 (echo "More important issues:"
124 echo "----------------------"
125 egrep -v "$3" < $2
126 echo ""
127 echo "Less important issues:"
128 echo "----------------------"
129 egrep "$3" < $2)
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000130 else
Neal Norwitz64984a82008-03-05 05:49:03 +0000131 cat $2
132 fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000133 fi
134}
135
136## setup
137cd $DIR
Georg Brandlbbd82e42010-01-03 14:18:52 +0000138make clobber > /dev/null 2>&1
139cp -p Modules/Setup.dist Modules/Setup
140# But maybe there was no Makefile - we are only building docs. Clear build:
141rm -rf build/
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000142mkdir -p build
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000143rm -rf $INSTALL_DIR
Georg Brandlbbd82e42010-01-03 14:18:52 +0000144## get the path we are building
145repo_path=$(grep "url=" .svn/entries | sed -e s/\\W*url=// -e s/\"//g)
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000146
147## create results file
148TITLE="Automated Python Build Results"
Neal Norwitzb8967592006-01-16 04:37:22 +0000149echo "<html>" >> $RESULT_FILE
150echo " <head>" >> $RESULT_FILE
151echo " <title>$TITLE</title>" >> $RESULT_FILE
152echo " <meta http-equiv=\"refresh\" content=\"43200\">" >> $RESULT_FILE
153echo " </head>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000154echo "<body>" >> $RESULT_FILE
155echo "<h2>Automated Python Build Results</h2>" >> $RESULT_FILE
156echo "<table>" >> $RESULT_FILE
157echo " <tr>" >> $RESULT_FILE
158echo " <td>Built on:</td><td>`date`</td>" >> $RESULT_FILE
159echo " </tr><tr>" >> $RESULT_FILE
160echo " <td>Hostname:</td><td>`uname -n`</td>" >> $RESULT_FILE
161echo " </tr><tr>" >> $RESULT_FILE
162echo " <td>Platform:</td><td>`uname -srmpo`</td>" >> $RESULT_FILE
Georg Brandlbbd82e42010-01-03 14:18:52 +0000163echo " </tr><tr>" >> $RESULT_FILE
164echo " <td>URL:</td><td>$repo_path</td>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000165echo " </tr>" >> $RESULT_FILE
166echo "</table>" >> $RESULT_FILE
167echo "<ul>" >> $RESULT_FILE
168
169## update, build, and test
170ORIG_CHECKSUM=`cksum $FULLPATHNAME`
171F=svn-update.out
172start=`current_time`
173svn update >& build/$F
174err=$?
175update_status "Updating" "$F" $start
Neal Norwitz88b78d82006-02-14 08:14:16 +0000176if [ $err = 0 -a "$BUILD_DISABLED" != "yes" ]; then
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000177 ## FIXME: we should check if this file has changed.
178 ## If it has changed, we should re-run the script to pick up changes.
179 if [ "$ORIG_CHECKSUM" != "$ORIG_CHECKSUM" ]; then
180 exec $FULLPATHNAME $@
181 fi
182
183 F=svn-stat.out
184 start=`current_time`
185 svn stat >& build/$F
186 ## ignore some of the diffs
187 NUM_DIFFS=`egrep -vc '^. (@test|db_home|Lib/test/(regrtest\.py|db_home))$' build/$F`
188 update_status "svn stat ($NUM_DIFFS possibly important diffs)" "$F" $start
189
190 F=configure.out
191 start=`current_time`
192 ./configure --prefix=$INSTALL_DIR --with-pydebug >& build/$F
193 err=$?
194 update_status "Configuring" "$F" $start
195 if [ $err = 0 ]; then
196 F=make.out
197 start=`current_time`
198 make >& build/$F
199 err=$?
200 warnings=`grep warning build/$F | egrep -vc "te?mpnam(_r|)' is dangerous,"`
201 update_status "Building ($warnings warnings)" "$F" $start
202 if [ $err = 0 ]; then
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000203 ## make install
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000204 F=make-install.out
205 start=`current_time`
206 make install >& build/$F
207 update_status "Installing" "$F" $start
208
Neal Norwitz9815f8b2006-07-26 04:00:18 +0000209 if [ ! -x $PYTHON ]; then
210 ln -s ${PYTHON}2.* $PYTHON
211 fi
212
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000213 ## make and run basic tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000214 F=make-test.out
215 start=`current_time`
Neal Norwitz38bdfaa2008-03-05 05:50:20 +0000216 $PYTHON $REGRTEST_ARGS -u urlfetch >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000217 NUM_FAILURES=`count_failures build/$F`
218 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000219 update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
Neal Norwitz02c408d2006-01-03 02:18:01 +0000220 mail_on_failure "basics" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000221
Neal Norwitz524b59b2006-06-27 04:09:13 +0000222 F=make-test-opt.out
223 start=`current_time`
Neal Norwitz38bdfaa2008-03-05 05:50:20 +0000224 $PYTHON -O $REGRTEST_ARGS -u urlfetch >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000225 NUM_FAILURES=`count_failures build/$F`
226 place_summary_first build/$F
Neal Norwitz524b59b2006-06-27 04:09:13 +0000227 update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
228 mail_on_failure "opt" build/$F
229
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000230 ## run the tests looking for leaks
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000231 F=make-test-refleak.out
232 start=`current_time`
Neal Norwitz0f77da32006-04-17 01:48:41 +0000233 ## ensure that the reflog exists so the grep doesn't fail
234 touch $REFLOG
Georg Brandlbbd82e42010-01-03 14:18:52 +0000235 $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network $LEAKY_SKIPS >& build/$F
Neal Norwitz64984a82008-03-05 05:49:03 +0000236 LEAK_PAT="($LEAKY_TESTS|sum=0)"
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000237 NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
Skip Montanaro04735172008-02-15 19:03:59 +0000238 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000239 update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000240 mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000241
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000242 ## now try to run all the tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000243 F=make-testall.out
244 start=`current_time`
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000245 ## skip curses when running from cron since there's no terminal
246 ## skip sound since it's not setup on the PSF box (/dev/dsp)
Neal Norwitz524b59b2006-06-27 04:09:13 +0000247 $PYTHON $REGRTEST_ARGS -uall -x test_curses test_linuxaudiodev test_ossaudiodev >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000248 NUM_FAILURES=`count_failures build/$F`
249 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000250 update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
Neal Norwitzd3a58672006-01-02 23:22:41 +0000251 mail_on_failure "all" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000252 fi
253 fi
254fi
255
256
257## make doc
Neal Norwitz524b59b2006-06-27 04:09:13 +0000258cd $DIR/Doc
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000259F="make-doc.out"
260start=`current_time`
Georg Brandlbbd82e42010-01-03 14:18:52 +0000261make clean > ../build/$F 2>&1
262make checkout html >> ../build/$F 2>&1
263err=$?
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000264update_status "Making doc" "$F" $start
265if [ $err != 0 ]; then
266 NUM_FAILURES=1
267 mail_on_failure "doc" ../build/$F
268fi
269
Georg Brandl4cf8ac42008-10-04 08:13:56 +0000270F="make-doc-dist.out"
271start=`current_time`
272if [ $conflict_count == 0 ]; then
273 make dist >& ../build/$F
274 err=$?
275fi
276update_status "Making downloadable doc" "$F" $start
277if [ $err != 0 ]; then
278 NUM_FAILURES=1
279 mail_on_failure "doc dist" ../build/$F
280fi
281
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000282echo "</ul>" >> $RESULT_FILE
283echo "</body>" >> $RESULT_FILE
284echo "</html>" >> $RESULT_FILE
285
286## copy results
Georg Brandlbbd82e42010-01-03 14:18:52 +0000287chgrp -R webmaster build/html
288chmod -R g+w build/html
Neal Norwitz7def3e02007-08-16 05:07:03 +0000289rsync $RSYNC_OPTS build/html/* $REMOTE_SYSTEM:$REMOTE_DIR
Georg Brandl4cf8ac42008-10-04 08:13:56 +0000290rsync $RSYNC_OPTS dist/* $REMOTE_SYSTEM:$REMOTE_DIR_DIST
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000291cd ../build
292rsync $RSYNC_OPTS index.html *.out $REMOTE_SYSTEM:$REMOTE_DIR/results/