blob: 03c0d7b43ee1d9186e1e8f47eb514e4ed56caf2b [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 Brandl01a30522009-08-13 08:37:59 +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 Brandl01a30522009-08-13 08:37:59 +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"
Martin v. Löwis924eca72008-12-05 07:20:46 +000051FAILURE_MAILTO="python-checkins@python.org"
Guido van Rossumd8faa362007-04-27 19:54:29 +000052#FAILURE_CC="optional--uncomment and set to desired address"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000053
54REMOTE_SYSTEM="neal@dinsdale.python.org"
Benjamin Peterson0887dbb2009-06-27 22:06:56 +000055REMOTE_DIR="/data/ftp.python.org/pub/www.python.org/doc/3.1"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000056RESULT_FILE="$DIR/build/index.html"
Benjamin Peterson0887dbb2009-06-27 22:06:56 +000057INSTALL_DIR="/tmp/python-test-3.1/local"
Georg Brandl593d0f42010-01-03 14:33:39 +000058RSYNC_OPTS="-C -e ssh -rlogD"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000059
Thomas Wouters0e3f5912006-08-11 14:57:12 +000060# Always run the installed version of Python.
61PYTHON=$INSTALL_DIR/bin/python
62
63# Python options and regression test program that should always be run.
Georg Brandle1b5ac62008-06-04 13:06:58 +000064REGRTEST_ARGS="-E $INSTALL_DIR/lib/python3.0/test/regrtest.py"
Thomas Wouters0e3f5912006-08-11 14:57:12 +000065
Neal Norwitz461aa5b2006-01-02 20:07:16 +000066REFLOG="build/reflog.txt.out"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000067# These tests are not stable and falsely report leaks sometimes.
Neal Norwitzf415d5f2006-02-19 18:48:19 +000068# The entire leak report will be mailed if any test not in this list leaks.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000069# Note: test_XXX (none currently) really leak, but are disabled
70# so we don't send spam. Any test which really leaks should only
71# be listed here if there are also test cases under Lib/test/leakers.
Collin Winter9a4414d2009-05-18 22:32:26 +000072LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|xmlrpc)"
Guido van Rossum52056532007-05-10 14:04:07 +000073
74# These tests always fail, so skip them so we don't get false positives.
Guido van Rossumcd16bf62007-06-13 18:07:49 +000075_ALWAYS_SKIP=""
Guido van Rossum52056532007-05-10 14:04:07 +000076ALWAYS_SKIP="-x $_ALWAYS_SKIP"
Neal Norwitzf415d5f2006-02-19 18:48:19 +000077
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000078# Skip these tests altogether when looking for leaks. These tests
79# do not need to be stored above in LEAKY_TESTS too.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000080# test_logging causes hangs, skip it.
Georg Brandl01a30522009-08-13 08:37:59 +000081# KBK 21Apr09: test_httpservers causes hangs, skip for now.
82LEAKY_SKIPS="-x test_compiler test_logging test_httpservers"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000083
84# Change this flag to "yes" for old releases to only update/build the docs.
Neal Norwitz88b78d82006-02-14 08:14:16 +000085BUILD_DISABLED="no"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000086
87## utility functions
88current_time() {
89 date +%s
90}
91
92update_status() {
93 now=`current_time`
94 time=`expr $now - $3`
95 echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
96}
97
Christian Heimesa156e092008-02-16 07:38:31 +000098place_summary_first() {
99 testf=$1
100 sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000101 | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
Christian Heimesa156e092008-02-16 07:38:31 +0000102 echo "" >> $testf.tmp
103 cat $testf >> $testf.tmp
104 mv $testf.tmp $testf
105}
106
107count_failures () {
108 testf=$1
109 n=`grep -ic " failed:" $testf`
110 if [ $n -eq 1 ] ; then
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000111 n=`grep " failed:" $testf | sed -e 's/ .*//'`
Christian Heimesa156e092008-02-16 07:38:31 +0000112 fi
113 echo $n
114}
115
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000116mail_on_failure() {
117 if [ "$NUM_FAILURES" != "0" ]; then
Guido van Rossumd8faa362007-04-27 19:54:29 +0000118 dest=$FAILURE_MAILTO
119 # FAILURE_CC is optional.
120 if [ "$FAILURE_CC" != "" ]; then
121 dest="$dest -c $FAILURE_CC"
122 fi
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000123 if [ "x$3" != "x" ] ; then
124 (echo "More important issues:"
125 echo "----------------------"
126 egrep -v "$3" < $2
127 echo ""
128 echo "Less important issues:"
129 echo "----------------------"
130 egrep "$3" < $2)
Christian Heimes292d3512008-02-03 16:51:08 +0000131 else
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000132 cat $2
133 fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000134 fi
135}
136
137## setup
138cd $DIR
Georg Brandl593d0f42010-01-03 14:33:39 +0000139make clobber > /dev/null 2>&1
Georg Brandl01a30522009-08-13 08:37:59 +0000140cp -p Modules/Setup.dist Modules/Setup
141# But maybe there was no Makefile - we are only building docs. Clear build:
142rm -rf build/
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000143mkdir -p build
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000144rm -rf $INSTALL_DIR
Georg Brandl01a30522009-08-13 08:37:59 +0000145## get the path we are building
146repo_path=$(grep "url=" .svn/entries | sed -e s/\\W*url=// -e s/\"//g)
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000147
148## create results file
149TITLE="Automated Python Build Results"
Neal Norwitzb8967592006-01-16 04:37:22 +0000150echo "<html>" >> $RESULT_FILE
151echo " <head>" >> $RESULT_FILE
152echo " <title>$TITLE</title>" >> $RESULT_FILE
153echo " <meta http-equiv=\"refresh\" content=\"43200\">" >> $RESULT_FILE
154echo " </head>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000155echo "<body>" >> $RESULT_FILE
156echo "<h2>Automated Python Build Results</h2>" >> $RESULT_FILE
157echo "<table>" >> $RESULT_FILE
158echo " <tr>" >> $RESULT_FILE
159echo " <td>Built on:</td><td>`date`</td>" >> $RESULT_FILE
160echo " </tr><tr>" >> $RESULT_FILE
161echo " <td>Hostname:</td><td>`uname -n`</td>" >> $RESULT_FILE
162echo " </tr><tr>" >> $RESULT_FILE
163echo " <td>Platform:</td><td>`uname -srmpo`</td>" >> $RESULT_FILE
Georg Brandl01a30522009-08-13 08:37:59 +0000164echo " </tr><tr>" >> $RESULT_FILE
165echo " <td>URL:</td><td>$repo_path</td>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000166echo " </tr>" >> $RESULT_FILE
167echo "</table>" >> $RESULT_FILE
168echo "<ul>" >> $RESULT_FILE
169
170## update, build, and test
171ORIG_CHECKSUM=`cksum $FULLPATHNAME`
172F=svn-update.out
173start=`current_time`
174svn update >& build/$F
175err=$?
176update_status "Updating" "$F" $start
Neal Norwitz88b78d82006-02-14 08:14:16 +0000177if [ $err = 0 -a "$BUILD_DISABLED" != "yes" ]; then
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000178 ## FIXME: we should check if this file has changed.
179 ## If it has changed, we should re-run the script to pick up changes.
180 if [ "$ORIG_CHECKSUM" != "$ORIG_CHECKSUM" ]; then
181 exec $FULLPATHNAME $@
182 fi
183
184 F=svn-stat.out
185 start=`current_time`
186 svn stat >& build/$F
187 ## ignore some of the diffs
188 NUM_DIFFS=`egrep -vc '^. (@test|db_home|Lib/test/(regrtest\.py|db_home))$' build/$F`
189 update_status "svn stat ($NUM_DIFFS possibly important diffs)" "$F" $start
190
191 F=configure.out
192 start=`current_time`
193 ./configure --prefix=$INSTALL_DIR --with-pydebug >& build/$F
194 err=$?
195 update_status "Configuring" "$F" $start
196 if [ $err = 0 ]; then
197 F=make.out
198 start=`current_time`
199 make >& build/$F
200 err=$?
201 warnings=`grep warning build/$F | egrep -vc "te?mpnam(_r|)' is dangerous,"`
202 update_status "Building ($warnings warnings)" "$F" $start
203 if [ $err = 0 ]; then
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000204 ## make install
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000205 F=make-install.out
206 start=`current_time`
207 make install >& build/$F
208 update_status "Installing" "$F" $start
209
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000210 if [ ! -x $PYTHON ]; then
Guido van Rossum52056532007-05-10 14:04:07 +0000211 ln -s ${PYTHON}3.* $PYTHON
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000212 fi
213
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000214 ## make and run basic tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000215 F=make-test.out
216 start=`current_time`
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000217 $PYTHON $REGRTEST_ARGS -u urlfetch >& build/$F
Christian Heimesa156e092008-02-16 07:38:31 +0000218 NUM_FAILURES=`count_failures build/$F`
219 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000220 update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
Neal Norwitz02c408d2006-01-03 02:18:01 +0000221 mail_on_failure "basics" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000222
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000223 F=make-test-opt.out
224 start=`current_time`
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000225 $PYTHON -O $REGRTEST_ARGS -u urlfetch >& build/$F
Christian Heimesa156e092008-02-16 07:38:31 +0000226 NUM_FAILURES=`count_failures build/$F`
227 place_summary_first build/$F
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000228 update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
229 mail_on_failure "opt" build/$F
230
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000231 ## run the tests looking for leaks
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000232 F=make-test-refleak.out
233 start=`current_time`
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000234 ## ensure that the reflog exists so the grep doesn't fail
235 touch $REFLOG
Georg Brandl01a30522009-08-13 08:37:59 +0000236 $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network $LEAKY_SKIPS >& build/$F
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000237 LEAK_PAT="($LEAKY_TESTS|sum=0)"
Christian Heimes292d3512008-02-03 16:51:08 +0000238 NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
Christian Heimesa156e092008-02-16 07:38:31 +0000239 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000240 update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
Christian Heimes292d3512008-02-03 16:51:08 +0000241 mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000242
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000243 ## now try to run all the tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000244 F=make-testall.out
245 start=`current_time`
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000246 ## skip curses when running from cron since there's no terminal
247 ## skip sound since it's not setup on the PSF box (/dev/dsp)
Guido van Rossum52056532007-05-10 14:04:07 +0000248 $PYTHON $REGRTEST_ARGS -uall -x test_curses test_linuxaudiodev test_ossaudiodev $_ALWAYS_SKIP >& build/$F
Christian Heimesa156e092008-02-16 07:38:31 +0000249 NUM_FAILURES=`count_failures build/$F`
250 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000251 update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
Neal Norwitzd3a58672006-01-02 23:22:41 +0000252 mail_on_failure "all" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000253 fi
254 fi
255fi
256
257
258## make doc
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000259cd $DIR/Doc
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000260F="make-doc.out"
261start=`current_time`
Georg Brandl593d0f42010-01-03 14:33:39 +0000262make clean > ../build/$F 2>&1
263make checkout html >> ../build/$F 2>&1
264err=$?
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000265update_status "Making doc" "$F" $start
266if [ $err != 0 ]; then
267 NUM_FAILURES=1
268 mail_on_failure "doc" ../build/$F
269fi
270
271echo "</ul>" >> $RESULT_FILE
272echo "</body>" >> $RESULT_FILE
273echo "</html>" >> $RESULT_FILE
274
275## copy results
Georg Brandl416d6622010-03-12 21:30:42 +0000276## (not used anymore, the daily build is now done directly on the server)
277#chgrp -R webmaster build/html
278#chmod -R g+w build/html
279#rsync $RSYNC_OPTS build/html/* $REMOTE_SYSTEM:$REMOTE_DIR
280#cd ../build
281#rsync $RSYNC_OPTS index.html *.out $REMOTE_SYSTEM:$REMOTE_DIR/results/