blob: 1cc3c00b539a56438eb8fc29e2ae50cc80e5111f [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##
7## Logs are kept and rsync'ed to the host. If there are test failure(s),
8## information about the failure(s) is mailed.
9##
10## This script is run on the PSF's machine as user neal via crontab.
11##
12## Yes, this script would probably be easier in python, but then
13## there's a bootstrap problem. What if Python doesn't build?
14##
15## This script should be fairly clean Bourne shell, ie not too many
16## bash-isms. We should try to keep it portable to other Unixes.
17## Even though it will probably only run on Linux. I'm sure there are
18## several GNU-isms currently (date +%s and readlink).
19##
20## Perhaps this script should be broken up into 2 (or more) components.
21## Building doc is orthogonal to the rest of the python build/test.
22##
23
24## FIXME: we should detect test hangs (eg, if they take more than 45 minutes)
25
26## FIXME: we should run valgrind
27## FIXME: we should run code coverage
28
29## Utilities invoked in this script include:
Neal Norwitzd3a58672006-01-02 23:22:41 +000030## basename, date, dirname, expr, grep, readlink, uname
Neal Norwitz461aa5b2006-01-02 20:07:16 +000031## cksum, make, mutt, rsync, svn
32
Neal Norwitz461aa5b2006-01-02 20:07:16 +000033## remember where did we started from
34DIR=`dirname $0`
35if [ "$DIR" = "" ]; then
36 DIR="."
37fi
38
39## make directory absolute
40DIR=`readlink -f $DIR`
Neal Norwitzd3a58672006-01-02 23:22:41 +000041FULLPATHNAME="$DIR/`basename $0`"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000042## we want Misc/..
43DIR=`dirname $DIR`
44
45## Configurable options
46
47FAILURE_SUBJECT="Python Regression Test Failures"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000048#FAILURE_MAILTO="YOUR_ACCOUNT@gmail.com"
Neal Norwitzf415d5f2006-02-19 18:48:19 +000049FAILURE_MAILTO="python-checkins@python.org"
Neal Norwitz5d08bd72007-04-20 05:20:38 +000050#FAILURE_CC="optional--uncomment and set to desired address"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000051
52REMOTE_SYSTEM="neal@dinsdale.python.org"
53REMOTE_DIR="/data/ftp.python.org/pub/docs.python.org/dev/"
54RESULT_FILE="$DIR/build/index.html"
55INSTALL_DIR="/tmp/python-test/local"
56RSYNC_OPTS="-aC -e ssh"
57
Neal Norwitz524b59b2006-06-27 04:09:13 +000058# Always run the installed version of Python.
59PYTHON=$INSTALL_DIR/bin/python
60
61# Python options and regression test program that should always be run.
Neal Norwitz044e3272008-10-03 04:13:08 +000062REGRTEST_ARGS="-E -tt $INSTALL_DIR/lib/python2.7/test/regrtest.py"
Neal Norwitz524b59b2006-06-27 04:09:13 +000063
Neal Norwitz461aa5b2006-01-02 20:07:16 +000064REFLOG="build/reflog.txt.out"
Neal Norwitzee6d23e2006-04-12 05:56:00 +000065# These tests are not stable and falsely report leaks sometimes.
Neal Norwitzf415d5f2006-02-19 18:48:19 +000066# The entire leak report will be mailed if any test not in this list leaks.
Neal Norwitza1f9b7f2006-04-06 07:58:59 +000067# Note: test_XXX (none currently) really leak, but are disabled
Neal Norwitz770a8002006-03-17 04:52:38 +000068# so we don't send spam. Any test which really leaks should only
69# be listed here if there are also test cases under Lib/test/leakers.
Neal Norwitza403e412008-08-24 17:29:53 +000070LEAKY_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 +000071
72# Skip these tests altogether when looking for leaks. These tests
73# do not need to be stored above in LEAKY_TESTS too.
74# test_compiler almost never finishes with the same number of refs
75# since it depends on other modules, skip it.
76# test_logging causes hangs, skip it.
77LEAKY_SKIPS="-x test_compiler test_logging"
Neal Norwitzf415d5f2006-02-19 18:48:19 +000078
Neal Norwitz770a8002006-03-17 04:52:38 +000079# Change this flag to "yes" for old releases to only update/build the docs.
Neal Norwitz88b78d82006-02-14 08:14:16 +000080BUILD_DISABLED="no"
Neal Norwitz461aa5b2006-01-02 20:07:16 +000081
82## utility functions
83current_time() {
84 date +%s
85}
86
87update_status() {
88 now=`current_time`
89 time=`expr $now - $3`
90 echo "<li><a href=\"$2\">$1</a> <font size=\"-1\">($time seconds)</font></li>" >> $RESULT_FILE
91}
92
Skip Montanaro04735172008-02-15 19:03:59 +000093place_summary_first() {
94 testf=$1
95 sed -n '/^[0-9][0-9]* tests OK\./,$p' < $testf \
Neal Norwitz64984a82008-03-05 05:49:03 +000096 | egrep -v '\[[0-9]+ refs\]' > $testf.tmp
Skip Montanaro04735172008-02-15 19:03:59 +000097 echo "" >> $testf.tmp
98 cat $testf >> $testf.tmp
99 mv $testf.tmp $testf
100}
101
102count_failures () {
103 testf=$1
104 n=`grep -ic " failed:" $testf`
105 if [ $n -eq 1 ] ; then
Neal Norwitz64984a82008-03-05 05:49:03 +0000106 n=`grep " failed:" $testf | sed -e 's/ .*//'`
Skip Montanaro04735172008-02-15 19:03:59 +0000107 fi
108 echo $n
109}
110
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000111mail_on_failure() {
112 if [ "$NUM_FAILURES" != "0" ]; then
Neal Norwitz5d08bd72007-04-20 05:20:38 +0000113 dest=$FAILURE_MAILTO
114 # FAILURE_CC is optional.
115 if [ "$FAILURE_CC" != "" ]; then
116 dest="$dest -c $FAILURE_CC"
117 fi
Neal Norwitz64984a82008-03-05 05:49:03 +0000118 if [ "x$3" != "x" ] ; then
119 (echo "More important issues:"
120 echo "----------------------"
121 egrep -v "$3" < $2
122 echo ""
123 echo "Less important issues:"
124 echo "----------------------"
125 egrep "$3" < $2)
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000126 else
Neal Norwitz64984a82008-03-05 05:49:03 +0000127 cat $2
128 fi | mutt -s "$FAILURE_SUBJECT $1 ($NUM_FAILURES)" $dest
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000129 fi
130}
131
132## setup
133cd $DIR
134mkdir -p build
135rm -f $RESULT_FILE build/*.out
136rm -rf $INSTALL_DIR
137
138## create results file
139TITLE="Automated Python Build Results"
Neal Norwitzb8967592006-01-16 04:37:22 +0000140echo "<html>" >> $RESULT_FILE
141echo " <head>" >> $RESULT_FILE
142echo " <title>$TITLE</title>" >> $RESULT_FILE
143echo " <meta http-equiv=\"refresh\" content=\"43200\">" >> $RESULT_FILE
144echo " </head>" >> $RESULT_FILE
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000145echo "<body>" >> $RESULT_FILE
146echo "<h2>Automated Python Build Results</h2>" >> $RESULT_FILE
147echo "<table>" >> $RESULT_FILE
148echo " <tr>" >> $RESULT_FILE
149echo " <td>Built on:</td><td>`date`</td>" >> $RESULT_FILE
150echo " </tr><tr>" >> $RESULT_FILE
151echo " <td>Hostname:</td><td>`uname -n`</td>" >> $RESULT_FILE
152echo " </tr><tr>" >> $RESULT_FILE
153echo " <td>Platform:</td><td>`uname -srmpo`</td>" >> $RESULT_FILE
154echo " </tr>" >> $RESULT_FILE
155echo "</table>" >> $RESULT_FILE
156echo "<ul>" >> $RESULT_FILE
157
158## update, build, and test
159ORIG_CHECKSUM=`cksum $FULLPATHNAME`
160F=svn-update.out
161start=`current_time`
162svn update >& build/$F
163err=$?
164update_status "Updating" "$F" $start
Neal Norwitz88b78d82006-02-14 08:14:16 +0000165if [ $err = 0 -a "$BUILD_DISABLED" != "yes" ]; then
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000166 ## FIXME: we should check if this file has changed.
167 ## If it has changed, we should re-run the script to pick up changes.
168 if [ "$ORIG_CHECKSUM" != "$ORIG_CHECKSUM" ]; then
169 exec $FULLPATHNAME $@
170 fi
171
172 F=svn-stat.out
173 start=`current_time`
174 svn stat >& build/$F
175 ## ignore some of the diffs
176 NUM_DIFFS=`egrep -vc '^. (@test|db_home|Lib/test/(regrtest\.py|db_home))$' build/$F`
177 update_status "svn stat ($NUM_DIFFS possibly important diffs)" "$F" $start
178
179 F=configure.out
180 start=`current_time`
181 ./configure --prefix=$INSTALL_DIR --with-pydebug >& build/$F
182 err=$?
183 update_status "Configuring" "$F" $start
184 if [ $err = 0 ]; then
185 F=make.out
186 start=`current_time`
187 make >& build/$F
188 err=$?
189 warnings=`grep warning build/$F | egrep -vc "te?mpnam(_r|)' is dangerous,"`
190 update_status "Building ($warnings warnings)" "$F" $start
191 if [ $err = 0 ]; then
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000192 ## make install
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000193 F=make-install.out
194 start=`current_time`
195 make install >& build/$F
196 update_status "Installing" "$F" $start
197
Neal Norwitz9815f8b2006-07-26 04:00:18 +0000198 if [ ! -x $PYTHON ]; then
199 ln -s ${PYTHON}2.* $PYTHON
200 fi
201
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000202 ## make and run basic tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000203 F=make-test.out
204 start=`current_time`
Neal Norwitz38bdfaa2008-03-05 05:50:20 +0000205 $PYTHON $REGRTEST_ARGS -u urlfetch >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000206 NUM_FAILURES=`count_failures build/$F`
207 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000208 update_status "Testing basics ($NUM_FAILURES failures)" "$F" $start
Neal Norwitz02c408d2006-01-03 02:18:01 +0000209 mail_on_failure "basics" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000210
Neal Norwitz524b59b2006-06-27 04:09:13 +0000211 F=make-test-opt.out
212 start=`current_time`
Neal Norwitz38bdfaa2008-03-05 05:50:20 +0000213 $PYTHON -O $REGRTEST_ARGS -u urlfetch >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000214 NUM_FAILURES=`count_failures build/$F`
215 place_summary_first build/$F
Neal Norwitz524b59b2006-06-27 04:09:13 +0000216 update_status "Testing opt ($NUM_FAILURES failures)" "$F" $start
217 mail_on_failure "opt" build/$F
218
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000219 ## run the tests looking for leaks
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000220 F=make-test-refleak.out
221 start=`current_time`
Neal Norwitz0f77da32006-04-17 01:48:41 +0000222 ## ensure that the reflog exists so the grep doesn't fail
223 touch $REFLOG
Neal Norwitz38bdfaa2008-03-05 05:50:20 +0000224 $PYTHON $REGRTEST_ARGS -R 4:3:$REFLOG -u network,urlfetch $LEAKY_SKIPS >& build/$F
Neal Norwitz64984a82008-03-05 05:49:03 +0000225 LEAK_PAT="($LEAKY_TESTS|sum=0)"
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000226 NUM_FAILURES=`egrep -vc "$LEAK_PAT" $REFLOG`
Skip Montanaro04735172008-02-15 19:03:59 +0000227 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000228 update_status "Testing refleaks ($NUM_FAILURES failures)" "$F" $start
Skip Montanaroee29c3f2008-02-02 19:11:57 +0000229 mail_on_failure "refleak" $REFLOG "$LEAK_PAT"
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000230
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000231 ## now try to run all the tests
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000232 F=make-testall.out
233 start=`current_time`
Neal Norwitzd19a4d42006-01-02 22:10:10 +0000234 ## skip curses when running from cron since there's no terminal
235 ## skip sound since it's not setup on the PSF box (/dev/dsp)
Neal Norwitz524b59b2006-06-27 04:09:13 +0000236 $PYTHON $REGRTEST_ARGS -uall -x test_curses test_linuxaudiodev test_ossaudiodev >& build/$F
Skip Montanaro04735172008-02-15 19:03:59 +0000237 NUM_FAILURES=`count_failures build/$F`
238 place_summary_first build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000239 update_status "Testing all except curses and sound ($NUM_FAILURES failures)" "$F" $start
Neal Norwitzd3a58672006-01-02 23:22:41 +0000240 mail_on_failure "all" build/$F
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000241 fi
242 fi
243fi
244
245
246## make doc
Neal Norwitz524b59b2006-06-27 04:09:13 +0000247cd $DIR/Doc
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000248F="make-doc.out"
249start=`current_time`
Neal Norwitz5c404ae2007-08-16 05:16:09 +0000250# XXX(nnorwitz): For now, keep the code that checks for a conflicted file until
251# after the first release of 2.6a1 or 3.0a1. At that point, it will be clear
252# if there will be a similar problem with the new doc system.
253
Neal Norwitz5d08bd72007-04-20 05:20:38 +0000254# Doc/commontex/boilerplate.tex is expected to always have an outstanding
255# modification for the date. When a release is cut, a conflict occurs.
256# This allows us to detect this problem and not try to build the docs
257# which will definitely fail with a conflict.
Neal Norwitz7def3e02007-08-16 05:07:03 +0000258#CONFLICTED_FILE=commontex/boilerplate.tex
259#conflict_count=`grep -c "<<<" $CONFLICTED_FILE`
260conflict_count=0
Neal Norwitz5d08bd72007-04-20 05:20:38 +0000261if [ $conflict_count != 0 ]; then
262 echo "Conflict detected in $CONFLICTED_FILE. Doc build skipped." > ../build/$F
263 err=1
264else
Neal Norwitz82955f62007-08-17 04:10:55 +0000265 make update html >& ../build/$F
Neal Norwitz5d08bd72007-04-20 05:20:38 +0000266 err=$?
267fi
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000268update_status "Making doc" "$F" $start
269if [ $err != 0 ]; then
270 NUM_FAILURES=1
271 mail_on_failure "doc" ../build/$F
272fi
273
274echo "</ul>" >> $RESULT_FILE
275echo "</body>" >> $RESULT_FILE
276echo "</html>" >> $RESULT_FILE
277
278## copy results
Neal Norwitz7def3e02007-08-16 05:07:03 +0000279rsync $RSYNC_OPTS build/html/* $REMOTE_SYSTEM:$REMOTE_DIR
Neal Norwitz461aa5b2006-01-02 20:07:16 +0000280cd ../build
281rsync $RSYNC_OPTS index.html *.out $REMOTE_SYSTEM:$REMOTE_DIR/results/