blob: 2f7bff18b55d606045d0346b9c1f8898d45973db [file] [log] [blame]
R. David Murrayf4d63ab2010-01-07 04:04:28 +00001#!/bin/sh
Neal Norwitz461aa5b2006-01-02 20:07:16 +00002
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##
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +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##
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +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"
55REMOTE_DIR="/data/ftp.python.org/pub/docs.python.org/dev/"
56RESULT_FILE="$DIR/build/index.html"
57INSTALL_DIR="/tmp/python-test/local"
Kurt B. Kaiserae628c92010-01-03 08:36:45 +000058RSYNC_OPTS="-C -e ssh -rlogD"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000059
Neal Norwitz524b59b2006-06-27 04:09:13 +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.
Neal Norwitz044e3272008-10-03 04:13:08 +000064REGRTEST_ARGS="-E -tt $INSTALL_DIR/lib/python2.7/test/regrtest.py"
Neal Norwitz524b59b2006-06-27 04:09:13 +000065
Neal Norwitz461aa5b2006-01-02 20:07:16 +000066REFLOG="build/reflog.txt.out"
Neal Norwitzee6d23e2006-04-12 05:56:00 +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.
Neal Norwitza1f9b7f2006-04-06 07:58:59 +000069# Note: test_XXX (none currently) really leak, but are disabled
Neal Norwitz770a8002006-03-17 04:52:38 +000070# 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 Winterf03c42f2009-05-18 21:35:40 +000072LEAKY_TESTS="test_(asynchat|cmd_line|docxmlrpc|dumbdbm|file|ftplib|httpservers|imaplib|popen2|socket|smtplib|sys|telnetlib|threadedtempfile|threading|threadsignals|xmlrpc)"
Neal Norwitzee6d23e2006-04-12 05:56:00 +000073
74# Skip these tests altogether when looking for leaks. These tests
75# do not need to be stored above in LEAKY_TESTS too.
76# test_compiler almost never finishes with the same number of refs
77# since it depends on other modules, skip it.
78# test_logging causes hangs, skip it.
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +000079# KBK 21Apr09: test_httpservers causes hangs, skip for now.
80LEAKY_SKIPS="-x test_compiler test_logging test_httpservers"
Neal Norwitzf415d5f2006-02-19 18:48:19 +000081
Neal Norwitz770a8002006-03-17 04:52:38 +000082# Change this flag to "yes" for old releases to only update/build the docs.
Neal Norwitz88b78d82006-02-14 08:14:16 +000083BUILD_DISABLED="no"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000084
85## utility functions
86current_time() {
87 date +%s
88}
89
90update_status() {
91 now=`current_time`
92 time=`expr $now - $3`
93 echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
94}
95
Skip Montanaro04735172008-02-15 19:03:59 +000096place_summary_first() {
97 testf=$1
98 sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
Neal Norwitz64984a82008-03-05 05:49:03 +000099 | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
Skip Montanaro04735172008-02-15 19:03:59 +0000100 echo "" >> $testf.tmp
101 cat $testf >> $testf.tmp
102 mv $testf.tmp $testf
103}
104
105count_failures () {
106 testf=$1
107 n=`grep -ic " failed:" $testf`
108 if [ $n -eq 1 ] ; then
Neal Norwitz64984a82008-03-05 05:49:03 +0000109 n=`grep " failed:" $testf | sed -e 's/ .*//'`
Skip Montanaro04735172008-02-15 19:03:59 +0000110 fi
111 echo $n
112}
113
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000114mail_on_failure() {
115 if [ "$NUM_FAILURES" != "0" ]; then
Neal Norwitz5d08bd72007-04-20 05:20:38 +0000116 dest=$FAILURE_MAILTO
117 # FAILURE_CC is optional.
118 if [ "$FAILURE_CC" != "" ]; then
119 dest="$dest -c $FAILURE_CC"
120 fi
Neal Norwitz64984a82008-03-05 05:49:03 +0000121 if [ "x$3" != "x" ] ; then
122 (echo "More important issues:"
123 echo "----------------------"
124 egrep -v "$3" < $2
125 echo ""
126 echo "Less important issues:"
127 echo "----------------------"
128 egrep "$3" < $2)
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000129 else
Neal Norwitz64984a82008-03-05 05:49:03 +0000130 cat $2
131 fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000132 fi
133}
134
135## setup
136cd $DIR
Kurt B. Kaiserae628c92010-01-03 08:36:45 +0000137make clobber > /dev/null 2>&1
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +0000138cp -p Modules/Setup.dist Modules/Setup
139# But maybe there was no Makefile - we are only building docs. Clear build:
140rm -rf build/
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000141mkdir -p build
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000142rm -rf $INSTALL_DIR
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +0000143## get the path we are building
144repo_path=$(grep "url=" .svn/entries | sed -e s/\\W*url=// -e s/\"//g)
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000145
146## create results file
147TITLE="Automated Python Build Results"
Neal Norwitzb8967592006-01-16 04:37:22 +0000148echo "<html>" >> $RESULT_FILE
149echo " <head>" >> $RESULT_FILE
150echo " <title>$TITLE</title>" >> $RESULT_FILE
151echo " <meta http-equiv=\"refresh\" content=\"43200\">" >> $RESULT_FILE
152echo " </head>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000153echo "<body>" >> $RESULT_FILE
154echo "<h2>Automated Python Build Results</h2>" >> $RESULT_FILE
155echo "<table>" >> $RESULT_FILE
156echo " <tr>" >> $RESULT_FILE
157echo " <td>Built on:</td><td>`date`</td>" >> $RESULT_FILE
158echo " </tr><tr>" >> $RESULT_FILE
159echo " <td>Hostname:</td><td>`uname -n`</td>" >> $RESULT_FILE
160echo " </tr><tr>" >> $RESULT_FILE
161echo " <td>Platform:</td><td>`uname -srmpo`</td>" >> $RESULT_FILE
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +0000162echo " </tr><tr>" >> $RESULT_FILE
163echo " <td>URL:</td><td>$repo_path</td>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000164echo " </tr>" >> $RESULT_FILE
165echo "</table>" >> $RESULT_FILE
166echo "<ul>" >> $RESULT_FILE
167
168## update, build, and test
169ORIG_CHECKSUM=`cksum $FULLPATHNAME`
170F=svn-update.out
171start=`current_time`
172svn update >& build/$F
173err=$?
174update_status "Updating" "$F" $start
Neal Norwitz88b78d82006-02-14 08:14:16 +0000175if [ $err = 0 -a "$BUILD_DISABLED" != "yes" ]; then
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000176 ## FIXME: we should check if this file has changed.
177 ## If it has changed, we should re-run the script to pick up changes.
178 if [ "$ORIG_CHECKSUM" != "$ORIG_CHECKSUM" ]; then
179 exec $FULLPATHNAME $@
180 fi
181
182 F=svn-stat.out
183 start=`current_time`
184 svn stat >& build/$F
185 ## ignore some of the diffs
186 NUM_DIFFS=`egrep -vc '^. (@test|db_home|Lib/test/(regrtest\.py|db_home))$' build/$F`
187 update_status "svn stat ($NUM_DIFFS possibly important diffs)" "$F" $start
188
189 F=configure.out
190 start=`current_time`
191 ./configure --prefix=$INSTALL_DIR --with-pydebug >& build/$F
192 err=$?
193 update_status "Configuring" "$F" $start
194 if [ $err = 0 ]; then
195 F=make.out
196 start=`current_time`
197 make >& build/$F
198 err=$?
199 warnings=`grep warning build/$F | egrep -vc "te?mpnam(_r|)' is dangerous,"`
200 update_status "Building ($warnings warnings)" "$F" $start
201 if [ $err = 0 ]; then
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000202 ## make install
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000203 F=make-install.out
204 start=`current_time`
205 make install >& build/$F
206 update_status "Installing" "$F" $start
207
Neal Norwitz9815f8b2006-07-26 04:00:18 +0000208 if [ ! -x $PYTHON ]; then
209 ln -s ${PYTHON}2.* $PYTHON
210 fi
211
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000212 ## make and run basic tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000213 F=make-test.out
214 start=`current_time`
R. David Murrayff2d7a72010-01-07 03:09:08 +0000215 $PYTHON $REGRTEST_ARGS -W -u urlfetch >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000216 NUM_FAILURES=`count_failures build/$F`
217 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000218 update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
Neal Norwitz02c408d2006-01-03 02:18:01 +0000219 mail_on_failure "basics" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000220
Neal Norwitz524b59b2006-06-27 04:09:13 +0000221 F=make-test-opt.out
222 start=`current_time`
R. David Murrayff2d7a72010-01-07 03:09:08 +0000223 $PYTHON -O $REGRTEST_ARGS -W -u urlfetch >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000224 NUM_FAILURES=`count_failures build/$F`
225 place_summary_first build/$F
Neal Norwitz524b59b2006-06-27 04:09:13 +0000226 update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
227 mail_on_failure "opt" build/$F
228
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000229 ## run the tests looking for leaks
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000230 F=make-test-refleak.out
231 start=`current_time`
Neal Norwitz0f77da32006-04-17 01:48:41 +0000232 ## ensure that the reflog exists so the grep doesn't fail
233 touch $REFLOG
Kurt B. Kaiser794b2a72009-07-27 16:09:28 +0000234 $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network $LEAKY_SKIPS >& build/$F
Neal Norwitz64984a82008-03-05 05:49:03 +0000235 LEAK_PAT="($LEAKY_TESTS|sum=0)"
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000236 NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
Skip Montanaro04735172008-02-15 19:03:59 +0000237 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000238 update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000239 mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000240
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000241 ## now try to run all the tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000242 F=make-testall.out
243 start=`current_time`
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000244 ## skip curses when running from cron since there's no terminal
245 ## skip sound since it's not setup on the PSF box (/dev/dsp)
R. David Murrayff2d7a72010-01-07 03:09:08 +0000246 $PYTHON $REGRTEST_ARGS -W -uall -x test_curses test_linuxaudiodev test_ossaudiodev >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000247 NUM_FAILURES=`count_failures build/$F`
248 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000249 update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
Neal Norwitzd3a58672006-01-02 23:22:41 +0000250 mail_on_failure "all" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000251 fi
252 fi
253fi
254
255
256## make doc
Neal Norwitz524b59b2006-06-27 04:09:13 +0000257cd $DIR/Doc
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000258F="make-doc.out"
259start=`current_time`
Georg Brandl7c910eb2010-01-03 13:05:39 +0000260make clean > ../build/$F 2>&1
261make checkout html >> ../build/$F 2>&1
262err=$?
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000263update_status "Making doc" "$F" $start
264if [ $err != 0 ]; then
265 NUM_FAILURES=1
266 mail_on_failure "doc" ../build/$F
267fi
268
269echo "</ul>" >> $RESULT_FILE
270echo "</body>" >> $RESULT_FILE
271echo "</html>" >> $RESULT_FILE
272
273## copy results
Georg Brandlf1539bd2010-03-12 21:27:23 +0000274## (not used anymore, the daily build is now done directly on the server)
275#chgrp -R webmaster build/html
276#chmod -R g+w build/html
277#rsync $RSYNC_OPTS build/html/* $REMOTE_SYSTEM:$REMOTE_DIR
278#cd ../build
279#rsync $RSYNC_OPTS index.html *.out $REMOTE_SYSTEM:$REMOTE_DIR/results/